From 17b7e8341d6a6a473653268db99d457d596bf895 Mon Sep 17 00:00:00 2001 From: Mads Hartmann Date: Fri, 18 Nov 2022 12:22:57 +0000 Subject: [PATCH] Go: Ignore ephemeral packages when checking transitive deps Consider the case where you have three Leeway Go packages A, B, C where A depends on B. B depends on C and C is ephemeral. The ephemeral package C will always be built whenever B is built as it is never cached. However, if B doesn't need to be rebuilt, then C won't be built either. As it is ephemeral it won't be in the cache either, which means that if you try to build package A when B is cached, then the build will fail as C isn't in the cache. This commit fixes it so that ephemeral packages are ignored when checking the transitive dependencies of Go packages. This was already the case for Yarn packages - the implementation (and comments) have been copied over verbatim --- pkg/leeway/build.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/leeway/build.go b/pkg/leeway/build.go index d94b92d3..053eb4cc 100644 --- a/pkg/leeway/build.go +++ b/pkg/leeway/build.go @@ -1121,11 +1121,25 @@ func (p *Package) buildGo(buildctx *buildContext, wd, result string) (res *packa }...) } + // We don't check if ephemeral packages in the transitive dependency tree have been built, + // as they may be too far down the tree to trigger a build (e.g. their parent may be built already). + // Hence, we need to ensure all direct dependencies on ephemeral packages have been built. + for _, deppkg := range p.GetDependencies() { + _, ok := buildctx.LocalCache.Location(deppkg) + if deppkg.Ephemeral && !ok { + return nil, PkgNotBuiltErr{deppkg} + } + } + transdep := p.GetTransitiveDependencies() if len(transdep) > 0 { commands = append(commands, []string{"mkdir", "_deps"}) for _, dep := range transdep { + if dep.Ephemeral { + continue + } + builtpkg, ok := buildctx.LocalCache.Location(dep) if !ok { return nil, PkgNotBuiltErr{dep}