func compileMultipe(pkgs []*dag.Package, oldPkgFound bool) bool { var ok bool var max int = len(pkgs) var trouble bool = false if max == 0 { log.Fatal("[ERROR] trying to compile 0 packages in parallel\n") } if max == 1 { if oldPkgFound || !pkgs[0].UpToDate() { say.Println("compiling:", pkgs[0].Name) handy.StdExecve(pkgs[0].Argv, true) oldPkgFound = true } else { say.Println("up 2 date:", pkgs[0].Name) } } else { ch := make(chan bool, max) for y := 0; y < max; y++ { if oldPkgFound || !pkgs[y].UpToDate() { say.Println("compiling:", pkgs[y].Name) oldPkgFound = true go gCompile(pkgs[y].Argv, ch) } else { say.Println("up 2 date:", pkgs[y].Name) ch <- true } } // drain channel (make sure all jobs are finished) for z := 0; z < max; z++ { ok = <-ch if !ok { trouble = true } } } if trouble { log.Fatal("[ERROR] failed batch compile job\n") } return oldPkgFound }
func SerialCompile(pkgs []*dag.Package) { var oldPkgFound bool = false for y := 0; y < len(pkgs); y++ { if global.GetBool("-dryrun") { fmt.Printf("%s || exit 1\n", strings.Join(pkgs[y].Argv, " ")) } else { if oldPkgFound || !pkgs[y].UpToDate() { say.Println("compiling:", pkgs[y].Name) handy.StdExecve(pkgs[y].Argv, true) oldPkgFound = true } else { say.Println("up 2 date:", pkgs[y].Name) } } } }
func ForkLink(output string, pkgs []*dag.Package, extra []*dag.Package, up2date bool) { var mainPKG *dag.Package gotMain := make([]*dag.Package, 0) for i := 0; i < len(pkgs); i++ { if pkgs[i].ShortName == "main" { gotMain = append(gotMain, pkgs[i]) } } if len(gotMain) == 0 { log.Fatal("[ERROR] (linking) no main package found\n") } if len(gotMain) > 1 { choice := mainChoice(gotMain) mainPKG = gotMain[choice] } else { mainPKG = gotMain[0] } compiled := filepath.Join(libroot, mainPKG.Name) + suffix if up2date && !global.GetBool("-dryrun") && handy.IsFile(output) { if handy.ModifyTimestamp(compiled) < handy.ModifyTimestamp(output) { say.Printf("up 2 date: %s\n", output) return } } argv := make([]string, 0) argv = append(argv, pathLinker) switch global.GetString("-backend") { case "gc", "express": argv = append(argv, "-L") argv = append(argv, libroot) } argv = append(argv, "-o") argv = append(argv, output) // gcc get's this no matter what... if global.GetString("-backend") == "gcc" || global.GetString("-backend") == "gccgo" { argv = append(argv, "-static") } else if global.GetBool("-static") { argv = append(argv, "-d") } switch global.GetString("-backend") { case "gccgo", "gcc": walker.IncludeFile = func(s string) bool { return strings.HasSuffix(s, ".o") } walker.IncludeDir = func(s string) bool { return true } for y := 0; y < len(includes); y++ { argv = append(argv, walker.PathWalk(includes[y])...) } case "gc", "express": for y := 0; y < len(includes); y++ { argv = append(argv, "-L") argv = append(argv, includes[y]) } } argv = append(argv, compiled) if global.GetString("-backend") == "gcc" || global.GetString("-backend") == "gccgo" { ss := stringset.New() if len(extra) > 0 { for j := 0; j < len(extra); j++ { // main package untestable using GCC if extra[j].ShortName != "main" { ss.Add(filepath.Join(libroot, extra[j].Name) + suffix) } } } else { for k := 0; k < len(pkgs); k++ { ss.Add(filepath.Join(libroot, pkgs[k].Name) + suffix) } ss.Remove(compiled) } if ss.Len() > 0 { argv = append(argv, ss.Slice()...) } } if global.GetBool("-dryrun") { linker := filepath.Base(pathLinker) fmt.Printf("%s %s || exit 1\n", linker, strings.Join(argv[1:], " ")) } else { say.Println("linking :", output) handy.StdExecve(argv, true) } }