Esempio n. 1
0
func (i *Importer) GxPublishGoPackage(imppath string) (*gx.Dependency, error) {
	imppath = getBaseDVCS(imppath)
	if d, ok := i.pkgs[imppath]; ok {
		return d, nil
	}

	if hash, ok := i.preMap[imppath]; ok {
		pkg, err := i.pm.GetPackageTo(hash, filepath.Join(vendorDir, hash))
		if err != nil {
			return nil, err
		}

		dep := &gx.Dependency{
			Hash:    hash,
			Name:    pkg.Name,
			Version: pkg.Version,
		}
		i.pkgs[imppath] = dep
		return dep, nil
	}

	// make sure its local
	err := i.GoGet(imppath)
	if err != nil {
		if !strings.Contains(err.Error(), "no buildable Go source files") {
			Error("go get %s failed: %s", imppath, err)
			return nil, err
		}
	}

	pkgpath := path.Join(i.gopath, "src", imppath)
	pkgFilePath := path.Join(pkgpath, gx.PkgFileName)
	pkg, err := LoadPackageFile(pkgFilePath)
	if err != nil {
		if !os.IsNotExist(err) {
			return nil, err
		}

		// init as gx package
		parts := strings.Split(imppath, "/")
		pkgname := parts[len(parts)-1]
		if !i.yesall {
			p := fmt.Sprintf("enter name for import '%s'", imppath)
			nname, err := prompt(p, pkgname)
			if err != nil {
				return nil, err
			}

			pkgname = nname
		}

		err = i.pm.InitPkg(pkgpath, pkgname, "go", nil)
		if err != nil {
			return nil, err
		}

		pkg, err = LoadPackageFile(pkgFilePath)
		if err != nil {
			return nil, err
		}
	}

	// wipe out existing dependencies
	pkg.Dependencies = nil

	// recurse!
	depsToVendor, err := i.DepsToVendorForPackage(imppath)
	if err != nil {
		return nil, fmt.Errorf("error fetching deps for %s: %s", imppath, err)
	}

	for n, child := range depsToVendor {
		Log("- processing dep %s for %s [%d / %d]", child, imppath, n+1, len(depsToVendor))
		if strings.HasPrefix(child, imppath) {
			continue
		}
		childdep, err := i.GxPublishGoPackage(child)
		if err != nil {
			return nil, err
		}

		pkg.Dependencies = append(pkg.Dependencies, childdep)
	}

	err = gx.SavePackageFile(pkg, pkgFilePath)
	if err != nil {
		return nil, err
	}

	fullpkgpath, err := filepath.Abs(pkgpath)
	if err != nil {
		return nil, err
	}

	err = i.rewriteImports(fullpkgpath)
	if err != nil {
		return nil, fmt.Errorf("rewriting imports failed: %s", err)
	}

	err = writeGxIgnore(pkgpath, []string{"Godeps/*"})
	if err != nil {
		return nil, err
	}

	hash, err := i.pm.PublishPackage(pkgpath, &pkg.PackageBase)
	if err != nil {
		return nil, err
	}

	Log("published %s as %s", imppath, hash)

	dep := &gx.Dependency{
		Hash:    hash,
		Name:    pkg.Name,
		Version: pkg.Version,
	}
	i.pkgs[imppath] = dep
	return dep, nil
}
Esempio n. 2
0
			dir = cwd
		}

		pkgpath := filepath.Join(dir, gx.PkgFileName)
		pkg, err := LoadPackageFile(pkgpath)
		if err != nil {
			return err
		}

		imp, _ := packagesGoImport(dir)

		if imp != "" {
			pkg.Gx.DvcsImport = imp
		}

		err = gx.SavePackageFile(pkg, pkgpath)
		if err != nil {
			return err
		}

		return nil
	},
}

var postInstallHookCommand = cli.Command{
	Name:  "post-install",
	Usage: "post install hook for newly installed go packages",
	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "global",
			Usage: "specifies whether or not the install was global",
Esempio n. 3
0
		ndep, err := pm.ImportPackage(ipath, dephash)
		if err != nil {
			Fatal(err)
		}

		if pkg.FindDep(ndep.Name) != nil {
			s := fmt.Sprintf("package with name %s already imported, continue?", ndep.Name)
			if !yesNoPrompt(s, false) {
				return
			}
			Log("continuing, please note some things may not work as expected")
		}

		pkg.Dependencies = append(pkg.Dependencies, ndep)
		err = gx.SavePackageFile(pkg, PkgFileName)
		if err != nil {
			Fatal("writing pkgfile: %s", err)
		}

	},
}

var InstallCommand = cli.Command{
	Name:    "install",
	Usage:   "install this package",
	Aliases: []string{"i"},
	Flags: []cli.Flag{
		cli.BoolFlag{
			Name:  "global",
			Usage: "install package in global namespace",