Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
build: remove empty directories from environment
This makes the paths a little easier to deal with.

Notably, we must still include directories of the package being built.
Otherwise, this manifests itself in gtk+-2 failing because gdk-pixbuf
does not find libgdk_pixbuf-2.0.so.0.
  • Loading branch information
stapelberg committed May 6, 2020
1 parent 283e3fd commit 6ac53ca
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions internal/build/build.go
Expand Up @@ -832,6 +832,14 @@ func newerRevisionGoesFirst(deps []string) []string {
return result
}

func appendUnlessEmpty(dirs []string, dir string) []string {
if fis, _ := ioutil.ReadDir(dir); len(fis) == 0 {
// Empty
return dirs
}
return append(dirs, dir)
}

func (b *Ctx) env(deps []string, hermetic bool) []string {
// TODO: this should go into the C builder once the C builder is used by all packages
var (
Expand All @@ -848,23 +856,29 @@ func (b *Ctx) env(deps []string, hermetic bool) []string {
deps = newerRevisionGoesFirst(deps)

for _, dep := range deps {
libDirs = append(libDirs, "/ro/"+dep+"/out/lib")
appendFunc := appendUnlessEmpty
if dep == b.FullName() {
appendFunc = func(dirs []string, dir string) []string {
return append(dirs, dir) // always append, even if empty
}
}
libDirs = appendFunc(libDirs, "/ro/"+dep+"/out/lib")
// TODO: should we try to make programs install to /lib instead? examples: libffi
libDirs = append(libDirs, "/ro/"+dep+"/out/lib64")
pkgconfigDirs = append(pkgconfigDirs, "/ro/"+dep+"/out/lib/pkgconfig")
pkgconfigDirs = append(pkgconfigDirs, "/ro/"+dep+"/out/share/pkgconfig")
libDirs = appendFunc(libDirs, "/ro/"+dep+"/out/lib64")
pkgconfigDirs = appendFunc(pkgconfigDirs, "/ro/"+dep+"/out/lib/pkgconfig")
pkgconfigDirs = appendFunc(pkgconfigDirs, "/ro/"+dep+"/out/share/pkgconfig")
// Exclude glibc from CPATH: it needs to come last (as /usr/include),
// and gcc doesn’t recognize that the non-system directory glibc-2.27
// duplicates the system directory /usr/include because we only symlink
// the contents, not the whole directory.
if pv := distri.ParseVersion(dep); pv.Pkg != "glibc" && pv.Pkg != "glibc-i686" {
includeDirs = append(includeDirs, "/ro/"+dep+"/out/include")
includeDirs = append(includeDirs, "/ro/"+dep+"/out/include/x86_64-linux-gnu")
includeDirs = appendFunc(includeDirs, "/ro/"+dep+"/out/include")
includeDirs = appendFunc(includeDirs, "/ro/"+dep+"/out/include/x86_64-linux-gnu")
}
perl5Dirs = append(perl5Dirs, "/ro/"+dep+"/out/lib/perl5")
perl5Dirs = appendFunc(perl5Dirs, "/ro/"+dep+"/out/lib/perl5")
// TODO: is site-packages the best choice here?
pythonDirs = append(pythonDirs, "/ro/"+dep+"/out/lib/python3.7/site-packages")
pythonDirs = append(pythonDirs, "/ro/"+dep+"/out/lib/python2.7/site-packages")
pythonDirs = appendFunc(pythonDirs, "/ro/"+dep+"/out/lib/python3.7/site-packages")
pythonDirs = appendFunc(pythonDirs, "/ro/"+dep+"/out/lib/python2.7/site-packages")
}

ifNotHermetic := func(val string) string {
Expand Down Expand Up @@ -915,15 +929,21 @@ func (b *Ctx) runtimeEnv(deps []string) []string {
deps = newerRevisionGoesFirst(deps)

for _, dep := range deps {
appendFunc := appendUnlessEmpty
if dep == b.FullName() {
appendFunc = func(dirs []string, dir string) []string {
return append(dirs, dir) // always append, even if empty
}
}
// TODO: these need to be the bindirs of the runtime deps. move wrapper
// script creation and runtimeEnv call down to when we know runtimeDeps
binDirs = append(binDirs, "/ro/"+dep+"/bin")
libDirs = append(libDirs, "/ro/"+dep+"/out/lib")
binDirs = appendFunc(binDirs, "/ro/"+dep+"/bin")
libDirs = appendFunc(libDirs, "/ro/"+dep+"/out/lib")
// TODO: should we try to make programs install to /lib instead? examples: libffi
libDirs = append(libDirs, "/ro/"+dep+"/out/lib64")
perl5Dirs = append(perl5Dirs, "/ro/"+dep+"/out/lib/perl5")
libDirs = appendFunc(libDirs, "/ro/"+dep+"/out/lib64")
perl5Dirs = appendFunc(perl5Dirs, "/ro/"+dep+"/out/lib/perl5")
// TODO: is site-packages the best choice here?
pythonDirs = append(pythonDirs, "/ro/"+dep+"/out/lib/python3.7/site-packages")
pythonDirs = appendFunc(pythonDirs, "/ro/"+dep+"/out/lib/python3.7/site-packages")
}

env := []string{
Expand Down

0 comments on commit 6ac53ca

Please sign in to comment.