Skip to content

Commit

Permalink
Reorganize artifact listing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Oct 23, 2023
1 parent edc0b6a commit 9c4ec88
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
49 changes: 31 additions & 18 deletions pkg/platform/runtime/buildplan/buildplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,23 @@ type ArtifactListing struct {
artifactIDs []artifact.ArtifactID
}

func NewArtifactListing(build *model.Build) *ArtifactListing {
return &ArtifactListing{build: build}
func NewArtifactListing(build *model.Build, buildtimeClosure bool) (*ArtifactListing, error) {
al := &ArtifactListing{build: build}
if buildtimeClosure {
buildtimeClosure, err := newMapFromBuildPlan(al.build, true)
if err != nil {
return nil, errs.Wrap(err, "Could not create buildtime closure")
}
al.buildtimeClosure = buildtimeClosure
} else {
runtimeClosure, err := newMapFromBuildPlan(al.build, false)
if err != nil {
return nil, errs.Wrap(err, "Could not create runtime closure")
}
al.runtimeClosure = runtimeClosure
}

return al, nil
}

func (al *ArtifactListing) RuntimeClosure() (artifact.Map, error) {
Expand Down Expand Up @@ -56,30 +71,28 @@ func (al *ArtifactListing) ArtifactIDs(buildtimeClosure bool) ([]artifact.Artifa
return al.artifactIDs, nil
}

var artifactMap artifact.Map
var err error
if buildtimeClosure {
if al.buildtimeClosure != nil {
for _, artifact := range al.buildtimeClosure {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
if al.buildtimeClosure == nil {
artifactMap, err = al.BuildtimeClosure()
if err != nil {
return nil, errs.Wrap(err, "Could not calculate buildtime closure")
}
return al.artifactIDs, nil
}

buildTimeClosure, err := al.BuildtimeClosure()
if err != nil {
return nil, errs.Wrap(err, "Could not create buildtime closure")
}

for _, artifact := range buildTimeClosure {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
}
} else {
if al.runtimeClosure != nil {
for _, artifact := range al.runtimeClosure {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
if al.runtimeClosure == nil {
artifactMap, err = al.RuntimeClosure()
if err != nil {
return nil, errs.Wrap(err, "Could not calculate runtime closure")
}
}
}

for _, artifact := range artifactMap {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
}

return al.artifactIDs, nil
}

Expand Down
14 changes: 9 additions & 5 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,17 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
return nil, nil, errs.Wrap(err, "Could not handle SolveSuccess event")
}

// If the build is not ready or if we are installing the buildtime closure
// then we need to include the buildtime closure in the changed artifacts
// and the progress reporting.
includeBuildtimeClosure := strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") || !buildResult.BuildReady

// Compute and handle the change summary
var requestedArtifacts artifact.Map // Artifacts required for the runtime to function
artifactListing := buildplan.NewArtifactListing(buildResult.Build)
artifactListing, err := buildplan.NewArtifactListing(buildResult.Build, includeBuildtimeClosure)
if err != nil {
return nil, nil, errs.Wrap(err, "Failed to create artifact listing")
}

// If we are installing build dependencies, then the requested artifacts
// will include the buildtime closure. Otherwise, we only need the runtime
Expand Down Expand Up @@ -465,10 +473,6 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeBuild, dimensions)
}

// If the build is not ready or if we are installing the buildtime closure
// then we need to include the buildtime closure in the changed artifacts
// and the progress reporting.
includeBuildtimeClosure := strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") || !buildResult.BuildReady
changedArtifacts, err := buildplan.NewBaseArtifactChangesetByBuildPlan(buildResult.Build, false, includeBuildtimeClosure)
if err != nil {
return nil, nil, errs.Wrap(err, "Could not compute base artifact changeset")
Expand Down

0 comments on commit 9c4ec88

Please sign in to comment.