From e4d8ef94dc56d119b91965e777877d9cbfe95771 Mon Sep 17 00:00:00 2001 From: Adrien Thebo Date: Tue, 17 Jan 2023 18:24:53 +0000 Subject: [PATCH] Only use buildContext when building packages pkg/build.Build may be called with a BuildOptions that contains a pre-generated BuildContext; in this case the BuildOptions value is largely ignored during context setup and may not be complete. The buildContext struct will be authoritative in this context and must be be used instead of buildOptions. One way that this issue manifests is when running a leeway script with dependencies as `leeway run` generates a buildContext and passes that into leeway.Build; the rest of the buildOptions is empty. When using buildOptions the RemoteCache field will always be empty, even if the buildContext value has a RemoteCache defined. By only using buildContext instead of buildOptions we resolve this confusion on what data is authoritative. --- pkg/leeway/build.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/leeway/build.go b/pkg/leeway/build.go index fd4f4f59..bf57e303 100644 --- a/pkg/leeway/build.go +++ b/pkg/leeway/build.go @@ -456,14 +456,14 @@ func Build(pkg *Package, opts ...BuildOption) (err error) { pkgsToDownload = append(pkgsToDownload, p) } - err = options.RemoteCache.Download(ctx.LocalCache, pkgsToDownload) + err = ctx.RemoteCache.Download(ctx.LocalCache, pkgsToDownload) if err != nil { return err } - options.Reporter.BuildStarted(pkg, pkgstatus) + ctx.Reporter.BuildStarted(pkg, pkgstatus) defer func(err *error) { - options.Reporter.BuildFinished(pkg, *err) + ctx.Reporter.BuildFinished(pkg, *err) }(&err) if len(unresolvedArgs) != 0 { @@ -475,21 +475,21 @@ func Build(pkg *Package, opts ...BuildOption) (err error) { return xerrors.Errorf(msg) } - if options.BuildPlan != nil { + if ctx.BuildPlan != nil { log.Debug("writing build plan") - err = writeBuildPlan(options.BuildPlan, pkg, pkgstatus) + err = writeBuildPlan(ctx.BuildPlan, pkg, pkgstatus) if err != nil { return err } } - if options.DryRun { + if ctx.DryRun { // This is a dry-run. We've prepared everything for the build but do not execute the build itself. return nil } buildErr := pkg.build(ctx) - cacheErr := options.RemoteCache.Upload(ctx.LocalCache, ctx.GetNewPackagesForCache()) + cacheErr := ctx.RemoteCache.Upload(ctx.LocalCache, ctx.GetNewPackagesForCache()) if buildErr != nil { // We deliberately swallow the target pacakge build error as that will have already been reported using the reporter.