Skip to content

Commit e591a13

Browse files
adrientheboaledbf
authored andcommitted
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.
1 parent 8e1719d commit e591a13

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pkg/leeway/build.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,14 @@ func Build(pkg *Package, opts ...BuildOption) (err error) {
456456
pkgsToDownload = append(pkgsToDownload, p)
457457
}
458458

459-
err = options.RemoteCache.Download(ctx.LocalCache, pkgsToDownload)
459+
err = ctx.RemoteCache.Download(ctx.LocalCache, pkgsToDownload)
460460
if err != nil {
461461
return err
462462
}
463463

464-
options.Reporter.BuildStarted(pkg, pkgstatus)
464+
ctx.Reporter.BuildStarted(pkg, pkgstatus)
465465
defer func(err *error) {
466-
options.Reporter.BuildFinished(pkg, *err)
466+
ctx.Reporter.BuildFinished(pkg, *err)
467467
}(&err)
468468

469469
if len(unresolvedArgs) != 0 {
@@ -475,21 +475,21 @@ func Build(pkg *Package, opts ...BuildOption) (err error) {
475475
return xerrors.Errorf(msg)
476476
}
477477

478-
if options.BuildPlan != nil {
478+
if ctx.BuildPlan != nil {
479479
log.Debug("writing build plan")
480-
err = writeBuildPlan(options.BuildPlan, pkg, pkgstatus)
480+
err = writeBuildPlan(ctx.BuildPlan, pkg, pkgstatus)
481481
if err != nil {
482482
return err
483483
}
484484
}
485485

486-
if options.DryRun {
486+
if ctx.DryRun {
487487
// This is a dry-run. We've prepared everything for the build but do not execute the build itself.
488488
return nil
489489
}
490490

491491
buildErr := pkg.build(ctx)
492-
cacheErr := options.RemoteCache.Upload(ctx.LocalCache, ctx.GetNewPackagesForCache())
492+
cacheErr := ctx.RemoteCache.Upload(ctx.LocalCache, ctx.GetNewPackagesForCache())
493493

494494
if buildErr != nil {
495495
// We deliberately swallow the target pacakge build error as that will have already been reported using the reporter.

0 commit comments

Comments
 (0)