func TestTool(t *testing.T) { if e := Remotize(Value2Spec("github.com/josvazg/remotize/tool", new(ToolTester))); e != nil { t.Fatal(e) } dir, e := build.ScanDir(".", false) if e != nil { t.Fatal(e) } dir.GoFiles = append(dir.GoFiles, "tool_test.go") //fmt.Println("dir", dir) tree, pkg, e := build.FindTree(".") if e != nil { t.Fatal(e) } //fmt.Println("tree", tree, "pkg", pkg) script, e := build.Build(tree, pkg, dir) if e != nil { t.Fatal(e) } //fmt.Println("script", script) e = script.Run() if e != nil { t.Fatal(e) } }
// install installs the package named by path, which is needed by parent. func install(pkg, parent string) { // Make sure we're not already trying to install pkg. switch visit[pkg] { case done: return case visiting: fmt.Fprintf(os.Stderr, "%s: package dependency cycle\n", argv0) printDeps(parent) fmt.Fprintf(os.Stderr, "\t%s\n", pkg) os.Exit(2) } parents[pkg] = parent visit[pkg] = visiting defer func() { visit[pkg] = done }() // Don't allow trailing '/' if _, f := filepath.Split(pkg); f == "" { errorf("%s should not have trailing '/'\n", pkg) return } // Check whether package is local or remote. // If remote, download or update it. tree, pkg, err := build.FindTree(pkg) // Don't build the standard library. if err == nil && tree.Goroot && isStandardPath(pkg) { if parent == "" { errorf("%s: can not goinstall the standard library\n", pkg) } else { printf("%s: skipping standard library\n", pkg) } return } // Download remote packages if not found or forced with -u flag. remote, public := isRemote(pkg), false if remote { if err == build.ErrNotFound || (err == nil && *update) { // Download remote package. printf("%s: download\n", pkg) public, err = download(pkg, tree.SrcDir()) } else { // Test if this is a public repository // (for reporting to dashboard). m, _ := findPublicRepo(pkg) public = m != nil } } if err != nil { terrorf(tree, "%s: %v\n", pkg, err) return } dir := filepath.Join(tree.SrcDir(), pkg) // Install prerequisites. dirInfo, err := build.ScanDir(dir, parent == "") if err != nil { terrorf(tree, "%s: %v\n", pkg, err) return } if len(dirInfo.GoFiles)+len(dirInfo.CgoFiles) == 0 { terrorf(tree, "%s: package has no files\n", pkg) return } for _, p := range dirInfo.Imports { if p != "C" { install(p, pkg) } } if errors { return } // Install this package. if *useMake { err := domake(dir, pkg, tree, dirInfo.IsCommand()) if err != nil { terrorf(tree, "%s: install: %v\n", pkg, err) return } } else { script, err := build.Build(tree, pkg, dirInfo) if err != nil { terrorf(tree, "%s: install: %v\n", pkg, err) return } if *nuke { printf("%s: nuke\n", pkg) script.Nuke() } else if *clean { printf("%s: clean\n", pkg) script.Clean() } if *doInstall { if script.Stale() { printf("%s: install\n", pkg) if err := script.Run(); err != nil { terrorf(tree, "%s: install: %v\n", pkg, err) return } } else { printf("%s: up-to-date\n", pkg) } } } if remote { // mark package as installed in goinstall.log logged := logPackage(pkg, tree) // report installation to the dashboard if this is the first // install from a public repository. if logged && public { maybeReportToDashboard(pkg) } } }