// Package returns the name of the package if present, or
// fallbacks to BinaryName
768116
func (d debExecutable) Package() string {
	if d.PackageName != "" {
		return d.PackageName
	}
	return d.BinaryName
}
116433
func (t *PackageList) AddPackage(pkg *build.Package) {
	t.ensureInit()
	t.pkgpool[pkg] = true
	t.dirpool[pkg.Dir] = pkg
	t.namepool[getPackageName(pkg)] = pkg
}
615738
func (c *CloudAPI) GetPackage(packageName string) (*cloudapi.Package, error) {
	if err := c.ProcessFunctionHook(c, packageName); err != nil {
		return nil, err
	}

	for _, pkg := range c.packages {
		if pkg.Name == packageName {
			return &pkg, nil
		}
		if pkg.Id == packageName {
			return &pkg, nil
		}
	}

	return nil, fmt.Errorf("Package %s not found", packageName)
}
783199
func build_package(p *build.Package) error {
	if *g_debug {
		log.Printf("-------------------")
		log.Printf("rebuilding package %s", p.Name)
		log.Printf("package import: %s", p.ImportPath)
		log.Printf("package object: %s", p.PkgObj)
		log.Printf("package source dir: %s", p.Dir)
		log.Printf("package source files: %v", p.GoFiles)
		log.Printf("GOPATH: %v", g_daemon.context.GOPATH)
		log.Printf("GOROOT: %v", g_daemon.context.GOROOT)
	}
	env := os.Environ()
	for i, v := range env {
		if strings.HasPrefix(v, "GOPATH=") {
			env[i] = "GOPATH=" + g_daemon.context.GOPATH
		} else if strings.HasPrefix(v, "GOROOT=") {
			env[i] = "GOROOT=" + g_daemon.context.GOROOT
		}
	}

	cmd := exec.Command("go", "install", p.ImportPath)
	cmd.Env = env

	// TODO: Should read STDERR rather than STDOUT.
	out, err := cmd.CombinedOutput()
	if err != nil {
		return err
	}
	if *g_debug {
		log.Printf("build out: %s\n", string(out))
	}
	return nil
}
720114
func (s *LaunchConfig) SetPackageName(v string) *LaunchConfig {
	s.PackageName = &v
	return s
}
318135
func Packages(pkgs ...Pkg) FuncMap {
	l := 0
	for _, p := range pkgs {
		l += len(p.Funcs)
	}
	m := make(FuncMap, l)
	for _, p := range pkgs {
		for nm, f := range p.Funcs {
			if p.MapName != nil {
				nm = p.MapName(nm)
			}
			name := p.Prefix + nm
			if f2, ok := m[name]; ok {
				log.Printf("use: name clash for '%s', %T, %T", name, f, f2)
			}
			m[name] = f
		}
	}
	return m
}
380721
func PackageFor(source string) (*Package, error) {
	w, err := WorkspaceFor(source)
	if err != nil {
		return nil, err
	}
	basepath := filepath.Join(w.Path, "src") // GOPATH mode.
	if w.isModuleMode {
		basepath = w.Path // Module mode.
	}
	path, err := filepath.Rel(basepath, filepath.Dir(source))
	if err != nil {
		return nil, err
	}
	return &Package{Workspace: w, Path: filepath.ToSlash(path)}, nil
}
699065
func resolvePackageName(packageName string, kernelRelease string) string {
	packageName = strings.Replace(packageName, "${KERNEL_RELEASE}", kernelRelease, -1)
	return packageName
}
551695
func (c *Client) Packages() ([]Package, error) {
	stdout, stderr, err := c.execNpm("list", "--json", "--depth=0")
	if err != nil {
		return nil, errors.New(stderr)
	}
	var response map[string]map[string]Package
	if err := json.Unmarshal([]byte(stdout), &response); err != nil {
		return nil, errors.New(stderr)
	}
	packages := make([]Package, 0, len(response["dependencies"]))
	for name, p := range response["dependencies"] {
		p.Name = name
		packages = append(packages, p)
	}
	return packages, nil
}
274799
func (s *Spec) rewritePackageName(pkg *Package) error {
	pkgName := filepath.Base(s.Name)
	if s.Local {
		pkgName = os.Getenv("GOPACKAGE")
		if pkgName == "" {
			return errors.New("GOPACKAGE cannot be empty")
		}
	}
	for _, node := range pkg.Files {
		node.Name.Name = pkgName
	}
	return nil
}
690836
func findPackage(pkgName string) (*build.Package, error) {
	debug("find", pkgName)
	pkg, err := build.Import(pkgName, getwd(), build.FindOnly)
	if err != nil {
		return nil, err
	}
	return pkg, nil
}
197009
func defaultGoPackageName(f *descriptor.FileDescriptorProto) string {
	name := packageIdentityName(f)
	return strings.Replace(name, ".", "_", -1)
}
971822
func (l *LanguageOpts) ManglePackageName(name, suffix string) string {
	if name == "" {
		return suffix
	}
	pth := filepath.ToSlash(filepath.Clean(name)) // preserve path
	_, pkg := path.Split(pth)                     // drop path
	return l.MangleName(swag.ToFileName(pkg), suffix)
}
372105
func Packages(c *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
	pkgs := generator.Packages{}
	c.FileTypes = map[string]generator.FileType{
		importBossFileType: importRuleFile{},
	}

	for _, p := range c.Universe {
		if !arguments.InputIncludes(p) {
			// Don't run on e.g. third party dependencies.
			continue
		}
		savedPackage := p
		pkgs = append(pkgs, &generator.DefaultPackage{
			PackageName: p.Name,
			PackagePath: p.Path,
			// GeneratorFunc returns a list of generators. Each generator makes a
			// single file.
			GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
				return []generator.Generator{&importRules{
					myPackage: savedPackage,
				}}
			},
			FilterFunc: func(c *generator.Context, t *types.Type) bool {
				return false
			},
		})
	}

	return pkgs
}
855678
func resolvePackageName(p string) (string, error) {
	p, err := filepath.Abs(p)
	if err == nil {
		p = filepath.Base(p)
		_, err = format.Source([]byte("package " + p))
	}
	if err != nil {
		return "", errors.New("invalid package name " + p)
	}
	return p, nil
}
853962
func allPackages(pattern string) []string {
	pkgs := matchPackages(pattern)
	if len(pkgs) == 0 {
		fmt.Fprintf(os.Stderr, "warning: %q matched no packages\n", pattern)
	}
	return pkgs
}
124309
func (g *Generator) PackagePathAndName(pkg interface{}) (path string, name string) {
	switch p := pkg.(type) {
	case string:
		path = p
		pkgInfo, err := g.loadPackage(path)
		if err != nil { //extract name from the package path itself
			log.Fatalf("failed to import package %q: %v", path, err)
		}

		name = pkgInfo.Pkg.Name()
	case *types.Package:
		path = p.Path()
		name = p.Name()
	case *ast.ImportSpec:
		return g.PackagePathAndName(p.Path.Value[1 : len(p.Path.Value)-1])
	default:
		log.Fatalf("unsupported pkg type: %T", pkg)
	}

	return NormalizeImportPath(path), name
}