Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pkg/ from .gitignore #159

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

# golang
pkg/
/bin/
*.prof
*.mprof
Expand Down
119 changes: 119 additions & 0 deletions src/vendor/git.sr.ht/~nelsam/hel/v3/pkg/packages.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// This is free and unencumbered software released into the public
// domain. For more information, see <http://unlicense.org> or the
// accompanying UNLICENSE file.

package pkg

import (
"fmt"
"go/build"
"os"
"path/filepath"
"strings"

"golang.org/x/tools/go/packages"
)

var (
cwd string
gopathEnv = os.Getenv("GOPATH")
gopath = strings.Split(gopathEnv, string(os.PathListSeparator))
)

func init() {
var err error
cwd, err = os.Getwd()
if err != nil {
panic(err)
}
}

// Dir represents a directory containing go files.
type Dir struct {
pkg *packages.Package
fsPath string
}

// Load looks for directories matching the passed in package patterns
// and returns Dir values for each directory that can be successfully
// imported and is found to match one of the patterns.
func Load(pkgPatterns ...string) []Dir {
return load(cwd, pkgPatterns...)
}

func load(fromDir string, pkgPatterns ...string) (dirs []Dir) {
pkgs, err := packages.Load(&packages.Config{
Mode: packages.NeedName | packages.NeedFiles | packages.NeedImports | packages.NeedDeps | packages.NeedSyntax,
}, pkgPatterns...)
if err != nil {
panic(err)
}
for _, pkg := range pkgs {
fsPath := ""
if len(pkg.GoFiles) > 0 {
fsPath = filepath.Dir(pkg.GoFiles[0])
}
dirs = append(dirs, Dir{pkg: pkg, fsPath: fsPath})
}
return dirs
}

// Path returns the file path to d.
func (d Dir) Path() string {
return d.fsPath
}

// Package returns the *packages.Package for d
func (d Dir) Package() *packages.Package {
return d.pkg
}

// Import imports path from srcDir, then loads the ast for that package.
// It ensures that the returned ast is for the package that would be
// imported by an import clause.
func (d Dir) Import(path string) (*packages.Package, error) {
p, ok := nestedImport(d.pkg, path)
if !ok {
return nil, fmt.Errorf("Could not find import %s in package %s", path, d.Path())
}
return p, nil
}

func nestedImport(pkg *packages.Package, path string) (*packages.Package, bool) {
if p, ok := pkg.Imports[path]; ok {
return p, true
}
for _, p := range pkg.Imports {
if subp, ok := nestedImport(p, path); ok {
return subp, true
}
}
return nil, false
}

func parsePatterns(fromDir string, pkgPatterns ...string) (packages []string) {
for _, pkgPattern := range pkgPatterns {
if !strings.HasSuffix(pkgPattern, "...") {
packages = append(packages, pkgPattern)
continue
}
parent := strings.TrimSuffix(pkgPattern, "...")
parentPkg, err := build.Import(parent, fromDir, build.AllowBinary)
if err != nil {
panic(err)
}
filepath.Walk(parentPkg.Dir, func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
return nil
}
path = strings.Replace(path, parentPkg.Dir, parent, 1)
if _, err := build.Import(path, fromDir, build.AllowBinary); err != nil {
// This directory doesn't appear to be a go package
return nil
}
packages = append(packages, path)
return nil
})
}
return
}
24 changes: 24 additions & 0 deletions src/vendor/github.com/pkg/errors/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/vendor/github.com/pkg/errors/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions src/vendor/github.com/pkg/errors/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/vendor/github.com/pkg/errors/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 59 additions & 0 deletions src/vendor/github.com/pkg/errors/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions src/vendor/github.com/pkg/errors/appveyor.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading