Skip to content

Commit

Permalink
scripts/ramfs: readability + formatting cleanups.
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Koch <chrisko@google.com>
  • Loading branch information
hugelgupf committed Nov 5, 2017
1 parent 29dd52e commit 6de9f26
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions scripts/ramfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@ import (
)

var (
// be VERY CAREFUL with these. If you have an empty line here it will
// result in cpio copying the whole tree.
goList = []string{"pkg/include"}
urootList []string
config struct {
config struct {
Goroot string
Godot string
Arch string
Goos string
Gopath string
Expand All @@ -35,13 +30,24 @@ var (
InitialCpio string
UseExistingInit bool
}

// be VERY CAREFUL with these. If you have an empty line here it will
// result in cpio copying the whole tree.
goList = []string{"pkg/include"}
urootList []string
pkgList []string
deps map[string]bool
gorootFiles map[string]bool
urootFiles map[string]bool
standardgotool = true
)

func init() {
flag.BoolVar(&config.UseExistingInit, "useinit", false, "If there is an existing init, don't replace it")
flag.StringVar(&config.InitialCpio, "cpio", "", "An initial cpio image to build on")
flag.StringVar(&config.TempDir, "tmpdir", "", "tmpdir to use instead of ioutil.TempDir")
}

func buildPkg(pkg string, wd string, output string, opts []string) error {
args := []string{
"build", "-x", "-a",
Expand Down Expand Up @@ -115,7 +121,7 @@ func guessgopath() {
log.Fatalf("You have to set GOPATH, which is typically ~/go")
}

type goDirs struct {
type goPackage struct {
Dir string
Deps []string
GoFiles []string
Expand All @@ -125,18 +131,18 @@ type goDirs struct {
ImportPath string
}

// goListPkg takes one package name, and computes all the files it needs to build,
// separating them into Go tree files and uroot files. For now we just 'go list'
// but hopefully later we can do this programmatically.
func goListPkg(name string) (*goDirs, error) {
// goListPkg takes one package name, and computes all the files it needs to
// build, separating them into Go tree files and uroot files. For now we just
// 'go list' but hopefully later we can do this programmatically.
func goListPkg(name string) (*goPackage, error) {
cmd := exec.Command("go", "list", "-json", name)
cmd.Env = append(os.Environ(), "CGO_ENABLED=0")
j, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}

var p goDirs
var p goPackage
if err := json.Unmarshal([]byte(j), &p); err != nil {
return nil, err
}
Expand All @@ -148,7 +154,6 @@ func goListPkg(name string) (*goDirs, error) {
urootFiles[filepath.Join(p.ImportPath, v)] = true
}
}

return &p, nil
}

Expand Down Expand Up @@ -197,14 +202,7 @@ func globlist(s ...string) []string {
return pat
}

// sad news. If I concat the Go cpio with the other cpios, for reasons I don't understand,
// the kernel can't unpack it. Don't know why, don't care. Need to create one giant cpio and unpack that.
// It's not size related: if the go archive is first or in the middle it still fails.
func main() {
flag.BoolVar(&config.UseExistingInit, "useinit", false, "If there is an existing init, don't replace it")
flag.StringVar(&config.InitialCpio, "cpio", "", "An initial cpio image to build on")
flag.StringVar(&config.TempDir, "tmpdir", "", "tmpdir to use instead of ioutil.TempDir")

flag.Parse()

deps = make(map[string]bool)
Expand Down

0 comments on commit 6de9f26

Please sign in to comment.