// returns buildpack path, ok
333575
func (runner *Runner) runSupplyBuildpacks() (string, string, error) {
	if err := runner.validateSupplyBuildpacks(); err != nil {
		return "", "", err
	}
	for i, buildpack := range runner.config.SupplyBuildpacks() {
		buildpackPath, err := runner.buildpackPath(buildpack)
		if err != nil {
			printError(err.Error())
			return "", "", newDescriptiveError(err, buildpackapplifecycle.SupplyFailMsg)
		}

		err = runner.run(exec.Command(filepath.Join(buildpackPath, "bin", "supply"), runner.config.BuildDir(), runner.supplyCachePath(buildpack), runner.depsDir, runner.config.DepsIndex(i)), os.Stdout)
		if err != nil {
			return "", "", newDescriptiveError(err, buildpackapplifecycle.SupplyFailMsg)
		}
	}

	finalBuildpack := runner.config.BuildpackOrder()[len(runner.config.SupplyBuildpacks())]
	finalPath, err := runner.buildpackPath(finalBuildpack)
	if err != nil {
		return "", "", newDescriptiveError(err, buildpackapplifecycle.SupplyFailMsg)
	}

	return finalBuildpack, finalPath, nil
}
126069
func (ccpack *SignedCDSPackage) InitFromPath(ccname string, ccversion string, path string) ([]byte, *pb.ChaincodeDeploymentSpec, error) {
	//incase ccpack is reused
	ccpack.reset()

	buf, err := GetChaincodePackageFromPath(ccname, ccversion, path)
	if err != nil {
		return nil, nil, err
	}

	if _, err = ccpack.InitFromBuffer(buf); err != nil {
		return nil, nil, err
	}

	return ccpack.buf, ccpack.depSpec, nil
}
1265056
func autobuild(p *build.Package) error {
	if p.Dir == "" {
		return fmt.Errorf("no files to build")
	}
	ps, err := os.Stat(p.PkgObj)
	if err != nil {
		// Assume package file does not exist and build for the first time.
		return build_package(p)
	}
	pt := ps.ModTime()
	fs, err := readdir_lstat(p.Dir)
	if err != nil {
		return err
	}
	for _, f := range fs {
		if f.IsDir() {
			continue
		}
		if f.ModTime().After(pt) {
			// Source file is newer than package file; rebuild.
			return build_package(p)
		}
	}
	return nil
}
1012088
func buildCopyModules(c *model.CommandConfig, revel_paths *model.RevelContainer, packageFolders []string) (err error) {
	destPath := filepath.Join(c.Build.TargetPath, "src")
	// Find all the modules used and copy them over.
	config := revel_paths.Config.Raw()
	modulePaths := make(map[string]string) // import path => filesystem path

	// We should only copy over the section of options what the build is targeted for
	// We will default to prod
	for _, section := range config.Sections() {
		// If the runmode is defined we will only import modules defined for that run mode
		if c.Build.Mode != "" && c.Build.Mode != section {
			continue
		}
		options, _ := config.SectionOptions(section)
		for _, key := range options {
			if !strings.HasPrefix(key, "module.") {
				continue
			}
			moduleImportPath, _ := config.String(section, key)
			if moduleImportPath == "" {
				continue
			}

			modPkg, err := build.Import(moduleImportPath, revel_paths.RevelPath, build.FindOnly)
			if err != nil {
				utils.Logger.Fatalf("Failed to load module %s (%s): %s", key[len("module."):], c.ImportPath, err)
			}
			modulePaths[moduleImportPath] = modPkg.Dir
		}
	}

	// Copy the the paths for each of the modules
	for importPath, fsPath := range modulePaths {
		utils.Logger.Info("Copy files ", "to", filepath.Join(destPath, importPath), "from", fsPath)
		if c.Build.CopySource {
			err = utils.CopyDir(filepath.Join(destPath, importPath), fsPath, nil)
			if err != nil {
				return
			}
		} else {
			for _, folder := range packageFolders {
				err = utils.CopyDir(
					filepath.Join(destPath, importPath, folder),
					filepath.Join(fsPath, folder),
					nil)
				if err != nil {
					return
				}
			}
		}
	}

	return
}
1058158
func (client Client) DeleteBuildpack(buildpackGUID string) (JobURL, Warnings, error) {
	request, err := client.newHTTPRequest(requestOptions{
		RequestName: internal.DeleteBuildpackRequest,
		URIParams: map[string]string{
			"buildpack_guid": buildpackGUID,
		},
	})
	if err != nil {
		return "", nil, err
	}

	response := cloudcontroller.Response{}
	err = client.connection.Make(request, &response)

	return JobURL(response.ResourceLocationURL), response.Warnings, err
}
664341
func LocatePackage(path string) (string, error) {
	p, err := build.Default.Import(path, "", build.FindOnly)
	if err != nil {
		return "", errors.Wrap(err, "LocatePackage: failed to find import")
	}

	cwd, err := os.Getwd()
	if err != nil {
		return "", errors.Wrap(err, "LocatePackage: could not get working directory")
	}

	p.Dir, err = filepath.Rel(cwd, p.Dir)
	if err != nil {
		return "", errors.Wrap(err, "LocatePackage: could not construct relative path")
	}

	return p.Dir, nil
}
498217
func (app Application) CalculatedBuildpacks() []string {
	buildpack := app.CalculatedBuildpack()
	switch {
	case app.Buildpacks != nil:
		return app.Buildpacks
	case len(buildpack) > 0:
		return []string{buildpack}
	default:
		return nil
	}
}
872479
func (javaPlatform *Platform) GetDeploymentPayload(path string) ([]byte, error) {

	logger.Debugf("Packaging java project from path %s", path)
	var err error

	// --------------------------------------------------------------------------------------
	// Write out our tar package
	// --------------------------------------------------------------------------------------
	payload := bytes.NewBuffer(nil)
	gw := gzip.NewWriter(payload)
	tw := tar.NewWriter(gw)

	folder := path
	if folder == "" {
		logger.Error("ChaincodeSpec's path cannot be empty")
		return nil, errors.New("ChaincodeSpec's path cannot be empty")
	}

	// trim trailing slash if it exists
	if folder[len(folder)-1] == '/' {
		folder = folder[:len(folder)-1]
	}

	if err = cutil.WriteJavaProjectToPackage(tw, folder); err != nil {

		logger.Errorf("Error writing java project to tar package %s", err)
		return nil, fmt.Errorf("Error writing Chaincode package contents: %s", err)
	}

	tw.Close()
	gw.Close()

	return payload.Bytes(), nil
}
452906
func OpenPackageFile(path string) (*PackageFile, error) {
	lc := strings.ToLower(path)
	if strings.HasPrefix(lc, "http://") || strings.HasPrefix(lc, "https://") {
		return openPackageURL(path)
	}

	return openPackageFile(path)
}
1112133
func try_autobuild(p *build.Package) {
	if g_config.Autobuild {
		err := autobuild(p)
		if err != nil && *g_debug {
			log.Printf("Autobuild error: %s\n", err)
		}
	}
}
545332
func PackagePath(path string) (string, error) {
	absPath, err := filepath.Abs(path)
	if err != nil {
		absPath = path
	}
	gopaths := filepath.SplitList(envOr("GOPATH", build.Default.GOPATH))
	if os.Getenv("GO111MODULE") != "on" { // GOPATH mode
		for _, gopath := range gopaths {
			if gp, err := filepath.Abs(gopath); err == nil {
				gopath = gp
			}
			if filepath.HasPrefix(absPath, gopath) {
				base := filepath.FromSlash(gopath + "/src")
				rel, err := filepath.Rel(base, absPath)
				return filepath.ToSlash(rel), err
			}
		}
	}
	if os.Getenv("GO111MODULE") != "off" { // Module mode
		root, file := findModuleRoot(absPath, "", false)
		if root != "" {
			content, err := ioutil.ReadFile(filepath.Join(root, file))
			if err == nil {
				p := modulePath(content)
				base := filepath.FromSlash(root)
				rel, err := filepath.Rel(base, absPath)
				return filepath.ToSlash(filepath.Join(p, rel)), err
			}
		}
	}
	return "", fmt.Errorf("%s does not contain a Go package", absPath)
}
516171
func FindSrcPaths(appImportPath, revelImportPath string, packageResolver func(pkgName string) error) (appSourcePath, revelSourcePath string, err error) {
	var (
		gopaths = filepath.SplitList(build.Default.GOPATH)
		goroot  = build.Default.GOROOT
	)

	if len(gopaths) == 0 {
		err = errors.New("GOPATH environment variable is not set. " +
			"Please refer to http://golang.org/doc/code.html to configure your Go environment.")
		return
	}

	if ContainsString(gopaths, goroot) {
		err = fmt.Errorf("GOPATH (%s) must not include your GOROOT (%s). "+
			"Please refer to http://golang.org/doc/code.html to configure your Go environment. ",
			build.Default.GOPATH, goroot)
		return

	}

	appPkgDir := ""
	appPkgSrcDir := ""
	if len(appImportPath)>0 {
		Logger.Info("Seeking app package","app",appImportPath)
		appPkg, err := build.Import(appImportPath, "", build.FindOnly)
		if err != nil {
			err = fmt.Errorf("Failed to import " + appImportPath + " with error %s", err.Error())
			return "","",err
		}
		appPkgDir,appPkgSrcDir =appPkg.Dir, appPkg.SrcRoot
	}
	Logger.Info("Seeking remote package","using",appImportPath, "remote",revelImportPath)
	revelPkg, err := build.Default.Import(revelImportPath, appPkgDir, build.FindOnly)
	if err != nil {
		Logger.Info("Resolved called Seeking remote package","using",appImportPath, "remote",revelImportPath)
		packageResolver(revelImportPath)
		revelPkg, err = build.Import(revelImportPath, appPkgDir, build.FindOnly)
		if err != nil {
			err = fmt.Errorf("Failed to find Revel with error: %s", err.Error())
			return
		}
	}

	revelSourcePath, appSourcePath = revelPkg.Dir[:len(revelPkg.Dir)-len(revelImportPath)], appPkgSrcDir
	return
}
1186823
func (e *Env) getStdlibPath(c context.Context, env []string) (string, error) {
	// This script will return the directory where the `site` Python module is found.
	// This module is always created by the VirtualEnv, and so is a reliable
	// indicator of where 'stdlib' imports exist.
	const script = `import os, site, sys; ` +
		`sys.stdout.write(os.path.dirname(site.__file__))`
	cmd := e.Interpreter().IsolatedCommand(c, python.CommandTarget{Command: script})
	cmd.Env = env

	var stdout bytes.Buffer
	cmd.Stdout = &stdout

	dumpOutput := attachOutputForLogging(c, logging.Debug, cmd)
	if err := cmd.Run(); err != nil {
		dumpOutput(c, logging.Error)
		return "", errors.Annotate(err, "failed to get stdlib module path").Err()
	}

	return stdout.String(), nil
}
490153
func (d *templateData) ParentServerPackagePath() string {
	if len(d.Parents) == 0 {
		return ""
	}
	return d.Parents[0].ServerPackagePath()
}
258563
func (pkg *Package) pkgpath() string {
	importpath := filepath.FromSlash(pkg.ImportPath) + ".a"
	switch {
	case pkg.isCrossCompile():
		return filepath.Join(pkg.Pkgdir(), importpath)
	case pkg.Goroot && pkg.race:
		// race enabled standard lib
		return filepath.Join(runtime.GOROOT(), "pkg", pkg.gotargetos+"_"+pkg.gotargetarch+"_race", importpath)
	case pkg.Goroot:
		// standard lib
		return filepath.Join(runtime.GOROOT(), "pkg", pkg.gotargetos+"_"+pkg.gotargetarch, importpath)
	default:
		return filepath.Join(pkg.Pkgdir(), importpath)
	}
}
1352165
func ParsePackagePaths(srcDir string, paths ...string) (pkglist *PackageList, err error) {
	var pkg *build.Package
	pkglist = &PackageList{}
	if srcDir, err = filepath.Abs(srcDir); err != nil {
		return
	}

	if len(paths) < 1 {
		if pkg, err = GuessPackageFromDir(srcDir); err != nil {
			return
		}
		pkglist.AddPackage(pkg)
		return
	}

	for _, pkgpath := range paths {
		importPath := strings.TrimSuffix(pkgpath, "/...")
		if importPath != pkgpath {
			if err = collectPackage(pkglist, importPath, srcDir); err != nil {
				return
			}
		} else {
			if pkg, err = build.Import(importPath, srcDir, 0); err != nil {
				return
			}
			pkglist.AddPackage(pkg)
		}
	}

	return
}
695556
func (c *Context) ResolvePackage(path string) (*Package, error) {
	if path == "." {
		return nil, errors.Errorf("%q is not a package", filepath.Join(c.Projectdir(), "src"))
	}
	path, err := relImportPath(filepath.Join(c.Projectdir(), "src"), path)
	if err != nil {
		return nil, err
	}
	if path == "." || path == ".." || strings.HasPrefix(path, "./") || strings.HasPrefix(path, "../") {
		return nil, errors.Errorf("import %q: relative import not supported", path)
	}
	return c.loadPackage(nil, path)
}