Skip to content

Commit

Permalink
Rename and add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
MDrakos committed Oct 23, 2023
1 parent d3a2d7b commit edc0b6a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
39 changes: 19 additions & 20 deletions pkg/platform/runtime/buildplan/buildplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,33 @@ func (al *ArtifactListing) BuildtimeClosure() (artifact.Map, error) {
return buildtimeClosure, nil
}

func (al *ArtifactListing) ArtifactIDs() ([]artifact.ArtifactID, error) {
func (al *ArtifactListing) ArtifactIDs(buildtimeClosure bool) ([]artifact.ArtifactID, error) {
if al.artifactIDs != nil {
return al.artifactIDs, nil
}

if al.buildtimeClosure != nil {
for _, artifact := range al.buildtimeClosure {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
if buildtimeClosure {
if al.buildtimeClosure != nil {
for _, artifact := range al.buildtimeClosure {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
}
return al.artifactIDs, nil
}
return al.artifactIDs, nil
}

if al.runtimeClosure != nil {
for _, artifact := range al.runtimeClosure {
al.artifactIDs = append(al.artifactIDs, artifact.ArtifactID)
buildTimeClosure, err := al.BuildtimeClosure()
if err != nil {
return nil, errs.Wrap(err, "Could not create buildtime closure")
}
return al.artifactIDs, nil
}

// Favor the buildtime closure over the runtime closure as it will
// include more artifact IDs
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)
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)
}
}
}

return al.artifactIDs, nil
Expand Down
21 changes: 13 additions & 8 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,18 +403,20 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
}

// Compute and handle the change summary
var runtimeArtifacts artifact.Map // Artifacts required for the runtime to function
var requestedArtifacts artifact.Map // Artifacts required for the runtime to function
artifactListing := buildplan.NewArtifactListing(buildResult.Build)

// If we are installing build dependencies, then buildtime dependencies are also runtime dependencies
// If we are installing build dependencies, then the requested artifacts
// will include the buildtime closure. Otherwise, we only need the runtime
// closure.
if strings.EqualFold(os.Getenv(constants.InstallBuildDependencies), "true") {
logging.Debug("Installing build dependencies")
runtimeArtifacts, err = artifactListing.BuildtimeClosure()
requestedArtifacts, err = artifactListing.BuildtimeClosure()
if err != nil {
return nil, nil, errs.Wrap(err, "Failed to compute buildtime closure")
}
} else {
runtimeArtifacts, err = artifactListing.RuntimeClosure()
requestedArtifacts, err = artifactListing.RuntimeClosure()
if err != nil {
return nil, nil, errs.Wrap(err, "Failed to create artifact map from build plan")
}
Expand All @@ -430,7 +432,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
return nil, nil, errs.Wrap(err, "Failed to select setup implementation")
}

downloadablePrebuiltResults, err := setup.DownloadsFromBuild(*buildResult.Build, runtimeArtifacts)
downloadablePrebuiltResults, err := setup.DownloadsFromBuild(*buildResult.Build, requestedArtifacts)
if err != nil {
if errors.Is(err, artifact.CamelRuntimeBuilding) {
localeID := "build_status_in_progress"
Expand All @@ -446,7 +448,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal

// buildResult doesn't have namespace info and will happily report internal only artifacts
downloadablePrebuiltResults = funk.Filter(downloadablePrebuiltResults, func(ad artifact.ArtifactDownload) bool {
ar, ok := runtimeArtifacts[ad.ArtifactID]
ar, ok := requestedArtifacts[ad.ArtifactID]
if !ok {
return true
}
Expand All @@ -463,6 +465,9 @@ 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 {
Expand All @@ -489,7 +494,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
alreadyInstalled := reusableArtifacts(buildResult.Build.Artifacts, storedArtifacts)

// Report resolved artifacts
artifactIDs, err := artifactListing.ArtifactIDs()
artifactIDs, err := artifactListing.ArtifactIDs(includeBuildtimeClosure)
if err != nil {
return nil, nil, errs.Wrap(err, "Could not get artifact IDs from build plan")
}
Expand Down Expand Up @@ -562,7 +567,7 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal
s.analytics.Event(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeDownload, dimensions)
}

err = s.installArtifactsFromBuild(buildResult, runtimeArtifacts, artifact.ArtifactIDsToMap(artifactsToInstall), downloadablePrebuiltResults, setup, resolver, installFunc, logFilePath)
err = s.installArtifactsFromBuild(buildResult, requestedArtifacts, artifact.ArtifactIDsToMap(artifactsToInstall), downloadablePrebuiltResults, setup, resolver, installFunc, logFilePath)
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit edc0b6a

Please sign in to comment.