Skip to content

Commit 4a942c2

Browse files
authored
Merge pull request #3753 from ActiveState/mitchell/cp-1137
Attach builders to artifacts.
2 parents f741ad6 + bbaff61 commit 4a942c2

File tree

5 files changed

+41
-0
lines changed

5 files changed

+41
-0
lines changed

pkg/buildplan/artifact.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ type Artifact struct {
2929
IsRuntimeDependency bool
3030
IsBuildtimeDependency bool
3131

32+
Builder *Artifact
33+
3234
platforms []strfmt.UUID
3335
children []ArtifactRelation
3436
}

pkg/buildplan/hydrate.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ func (b *BuildPlan) hydrate() error {
3737
}
3838

3939
// We have all the artifacts we're interested in now, but we still want to relate them to a source; ie. an ingredient.
40+
// We also want to relate artifacts to their builders, because dynamically imported ingredients have a special installation process.
4041
// This will also hydrate our requirements, because they are based on the source ID.
4142
for _, artifact := range b.artifacts {
4243
if err := b.hydrateWithIngredients(artifact, platformID, ingredientLookup); err != nil {
4344
return errs.Wrap(err, "hydrating with ingredients failed")
4445
}
46+
if err := b.hydrateWithBuilders(artifact, artifactLookup); err != nil {
47+
return errs.Wrap(err, "hydrating with builders failed")
48+
}
4549
}
4650
}
4751

@@ -202,6 +206,30 @@ func (b *BuildPlan) hydrateWithIngredients(artifact *Artifact, platformID *strfm
202206
return nil
203207
}
204208

209+
func (b *BuildPlan) hydrateWithBuilders(artifact *Artifact, artifactLookup map[strfmt.UUID]*Artifact) error {
210+
err := b.raw.WalkViaSteps([]strfmt.UUID{artifact.ArtifactID}, raw.WalkViaBuilder, func(node interface{}, parent *raw.Artifact) error {
211+
v, ok := node.(*raw.Artifact)
212+
if !ok {
213+
return nil // continue
214+
}
215+
216+
builder, ok := artifactLookup[v.NodeID]
217+
if !ok {
218+
builder = createArtifact(v)
219+
b.artifacts = append(b.artifacts, builder)
220+
artifactLookup[v.NodeID] = builder
221+
}
222+
223+
artifact.Builder = builder
224+
return nil
225+
})
226+
if err != nil {
227+
return errs.Wrap(err, "error hydrating builders")
228+
}
229+
230+
return nil
231+
}
232+
205233
// sanityCheck will for convenience sake validate that we have no duplicates here while on a dev machine.
206234
// If there are duplicates we're likely to see failures down the chain if live, though that's by no means guaranteed.
207235
// Surfacing it here will make it easier to reason about the failure.

pkg/buildplan/raw/raw.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type StepInputTag string
1818
const (
1919
// Tag types
2020
TagSource StepInputTag = "src"
21+
TagBuilder StepInputTag = "builder"
2122
TagDependency StepInputTag = "deps"
2223
)
2324

pkg/buildplan/raw/walk.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ var (
2727
TagDependency,
2828
false,
2929
}
30+
WalkViaBuilder = WalkStrategy{
31+
TagBuilder,
32+
true,
33+
}
3034
)
3135

3236
// WalkViaSteps walks the graph and reports on nodes it encounters

pkg/runtime/ecosystem.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
ecosys "github.com/ActiveState/cli/pkg/runtime/ecosystem"
66
)
77

8+
const starBuilder = "star-builder"
9+
810
type ecosystem interface {
911
Init(runtimePath string, buildplan *buildplan.BuildPlan) error
1012
Namespaces() []string
@@ -27,6 +29,10 @@ func init() {
2729
}
2830

2931
func artifactMatchesEcosystem(a *buildplan.Artifact, e ecosystem) bool {
32+
if a.Builder != nil && a.Builder.DisplayName != starBuilder {
33+
return false
34+
}
35+
3036
for _, namespace := range e.Namespaces() {
3137
for _, i := range a.Ingredients {
3238
if i.Namespace == namespace {

0 commit comments

Comments
 (0)