Skip to content

Commit

Permalink
Merge pull request #721 from jonjohnsonjr/vendored
Browse files Browse the repository at this point in the history
Track vendored deps for .PKGINFO
  • Loading branch information
jonjohnsonjr authored Oct 10, 2023
2 parents 0e6d29c + 35149f8 commit 2c1195f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
28 changes: 20 additions & 8 deletions pkg/build/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import (
// concurrent builds on giant machines, and uses only 1 core on tiny machines.
var pgzipThreads = min(runtime.GOMAXPROCS(0), 8)

var libDirs = []string{"lib", "usr/lib", "lib64", "usr/lib64"}

func min(l, r int) int {
if l < r {
return l
Expand Down Expand Up @@ -203,6 +205,9 @@ provides = {{ $dep }}
{{- range $dep := .Dependencies.Replaces }}
replaces = {{ $dep }}
{{- end }}
{{- range $dep := .Dependencies.Vendored }}
# vendored = {{ $dep }}
{{- end }}
{{- if .Dependencies.ProviderPriority }}
provider_priority = {{ .Dependencies.ProviderPriority }}
{{- end }}
Expand Down Expand Up @@ -397,7 +402,6 @@ func findInterpreter(bin *elf.File) (string, error) {
// dereferenceCrossPackageSymlink attempts to dereference a symlink across multiple package
// directories.
func (pc *PackageBuild) dereferenceCrossPackageSymlink(path string) (string, error) {
libDirs := []string{"lib", "usr/lib", "lib64", "usr/lib64"}
targetPackageNames := []string{pc.PackageName, pc.Build.Configuration.Package.Name}
realPath, err := os.Readlink(filepath.Join(pc.WorkspaceSubdir(), path))
if err != nil {
Expand Down Expand Up @@ -529,11 +533,6 @@ func generateSharedObjectNameDeps(pc *PackageBuild, generated *config.Dependenci
// Ugh: libc.so.6 has an PT_INTERP set on itself to make the `/lib/libc.so.6 --about`
// functionality work. So we always generate provides entries for libc.
if !pc.Options.NoProvides && (interp == "" || strings.HasPrefix(basename, "libc")) {
libDirs := []string{"lib", "usr/lib", "lib64", "usr/lib64"}
if !allowedPrefix(path, libDirs) {
return nil
}

sonames, err := ef.DynString(elf.DT_SONAME)
// most likely SONAME is not set on this object
if err != nil {
Expand All @@ -551,7 +550,11 @@ func generateSharedObjectNameDeps(pc *PackageBuild, generated *config.Dependenci
libver = "0"
}

generated.Provides = append(generated.Provides, fmt.Sprintf("so:%s=%s", soname, libver))
if allowedPrefix(path, libDirs) {
generated.Provides = append(generated.Provides, fmt.Sprintf("so:%s=%s", soname, libver))
} else {
generated.Vendored = append(generated.Vendored, fmt.Sprintf("so:%s=%s", soname, libver))
}
}
}
}
Expand Down Expand Up @@ -686,14 +689,23 @@ func (pc *PackageBuild) GenerateDependencies() error {
}
}

newruntime := append(pc.Dependencies.Runtime, generated.Runtime...)
// Only consider vendored deps for self-provided generated runtime deps.
// If a runtime dep is explicitly configured, assume we actually do need it.
// This gives us an escape hatch in melange config in case there is a runtime
// dep that we don't want to be satisfied by a vendored dep.
unvendored := removeSelfProvidedDeps(generated.Runtime, generated.Vendored)

newruntime := append(pc.Dependencies.Runtime, unvendored...)
pc.Dependencies.Runtime = dedup(newruntime)

newprovides := append(pc.Dependencies.Provides, generated.Provides...)
pc.Dependencies.Provides = dedup(newprovides)

pc.Dependencies.Runtime = removeSelfProvidedDeps(pc.Dependencies.Runtime, pc.Dependencies.Provides)

// Sets .PKGINFO `# vendored = ...` comments; does not affect resolution.
pc.Dependencies.Vendored = generated.Vendored

pc.Dependencies.Summarize(pc.Logger)

return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,10 @@ type Dependencies struct {
// Optional: An integer compared against other equal package provides used to
// determine priority
ProviderPriority int `yaml:"provider-priority,omitempty"`

// List of self-provided dependencies found outside of lib directories
// ("lib", "usr/lib", "lib64", or "usr/lib64").
Vendored []string `yaml:"-"`
}

type ConfigurationParsingOption func(*configOptions)
Expand Down

0 comments on commit 2c1195f

Please sign in to comment.