Skip to content

Commit 5c250ad

Browse files
committed
Not yet working: attempt at transitive instantiation
1 parent 25bff6a commit 5c250ad

File tree

2 files changed

+43
-12
lines changed

2 files changed

+43
-12
lines changed

fixtures/pkgs/instanciated/BUILD.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ packages:
44
config:
55
commands:
66
- ["echo", "${message}"]
7+
- name: rabbit-hole
8+
type: generic
9+
deps:
10+
- ref: :variant
11+
args:
12+
message: "${passingThrough}"
713
- name: all
814
type: generic
915
deps:
@@ -14,4 +20,7 @@ packages:
1420
- ref: :variant
1521
alias: world
1622
args:
17-
message: world
23+
message: world
24+
- ref: :rabbit-hole
25+
args:
26+
passingThrough: awesome

pkg/leeway/package.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,25 +94,38 @@ func rawReplaceBuildArguments(fc []byte, args Arguments) []byte {
9494

9595
// replateBuildArguments marshals the package config to YAML and replaces the given arguments with their corresponding
9696
// value. If the arg has no corresponding value, the argument is not changed.
97-
func replaceBuildArguments(pkg *Package, args Arguments) (fc []byte, err error) {
97+
func replaceBuildArguments(pkg *Package, args Arguments) (err error) {
9898
type configOnlyHelper struct {
9999
Config PackageConfig `yaml:"config"`
100100
}
101-
cfgonly := configOnlyHelper{Config: pkg.Config}
102-
fc, err = yaml.Marshal(cfgonly)
101+
fc, err := yaml.Marshal(configOnlyHelper{Config: pkg.Config})
103102
if err != nil {
104103
return
105104
}
106-
107105
fc = rawReplaceBuildArguments(fc, args)
108-
109106
cfg, err := unmarshalTypeDependentConfig(pkg.Type, func(out interface{}) error {
110107
return yaml.Unmarshal(fc, out)
111108
})
112109
if err != nil {
113110
return
114111
}
115112
pkg.Config = cfg
113+
114+
var deps struct {
115+
Deps []packageDependencyOrString `yaml:"deps"`
116+
}
117+
deps.Deps = pkg.Dependencies
118+
fc, err = yaml.Marshal(deps)
119+
if err != nil {
120+
return
121+
}
122+
fc = rawReplaceBuildArguments(fc, args)
123+
err = yaml.Unmarshal(fc, &deps)
124+
if err != nil {
125+
return
126+
}
127+
pkg.Dependencies = deps.Deps
128+
116129
return
117130
}
118131

@@ -194,7 +207,7 @@ type packageDependency struct {
194207

195208
// Package is a single buildable artifact within a component
196209
type Package struct {
197-
C *Component
210+
C *Component `json:"-"`
198211

199212
// computing the version is expensive - let's cache that
200213
versionCache string
@@ -207,7 +220,8 @@ type Package struct {
207220
// Instanciated packages are packages which have some of their build args resolved during linking,
208221
// i.e. have their values set through the dependant package. Variant packages are always copies
209222
// of their original definitions. This field carries the full name of the original package.
210-
InstanceOf string `yaml:"-"`
223+
InstanceOf string `yaml:"-"`
224+
InstanceArgs map[string]string
211225

212226
dependencies []*Package
213227
layout map[*Package]string
@@ -230,21 +244,26 @@ func (p *Package) link(idx map[string]*Package) error {
230244
return PackageNotFoundErr{dep.Ref}
231245
}
232246

247+
err := deppkg.link(idx)
248+
if err != nil {
249+
return err
250+
}
251+
233252
// This dependency has arguments which we need to replace in the dependency package itself.
234253
// To this end we copy the package, replace the build arg and make the new (virtual) package
235254
// fit for purpose.
236255
if len(dep.Args) > 0 {
237256
cpy := *deppkg
238-
fc, err := replaceBuildArguments(&cpy, dep.Args)
257+
err := replaceBuildArguments(&cpy, dep.Args)
239258
if err != nil {
240259
return err
241260
}
242261
if dep.Alias != "" {
243262
cpy.Name = dep.Alias
244263
}
245-
cpy.Definition = fc
246264
cpy.versionCache = ""
247265
cpy.InstanceOf = deppkg.FullName()
266+
cpy.InstanceArgs = dep.Args
248267

249268
deppkg = &cpy
250269
p.C.Packages = append(p.C.Packages, deppkg)
@@ -888,7 +907,7 @@ func (p *Package) resolveBuiltinVariables() error {
888907
}
889908
}
890909

891-
_, err = replaceBuildArguments(p, builtinArgs)
910+
err = replaceBuildArguments(p, builtinArgs)
892911
if err != nil {
893912
return err
894913
}
@@ -969,7 +988,7 @@ func (p *Package) ContentManifest() ([]string, error) {
969988
// WriteVersionManifest writes the manifest whoose hash is the version of this package (see Version())
970989
func (p *Package) WriteVersionManifest(out io.Writer) error {
971990
if p.dependencies == nil {
972-
return xerrors.Errorf("package is not linked")
991+
return xerrors.Errorf("package %s is not linked", p.FullName())
973992
}
974993

975994
envhash, err := p.C.W.EnvironmentManifest.Hash()
@@ -1001,6 +1020,9 @@ func (p *Package) WriteVersionManifest(out io.Writer) error {
10011020

10021021
bundle = append(bundle, fmt.Sprintf("environment: %s\n", envhash))
10031022
bundle = append(bundle, fmt.Sprintf("definition: %s\n", defhash))
1023+
for k, v := range p.InstanceArgs {
1024+
bundle = append(bundle, fmt.Sprintf("instance-arg %s=%s\n", k, v))
1025+
}
10041026
for _, argdep := range p.ArgumentDependencies {
10051027
bundle = append(bundle, fmt.Sprintf("arg %s\n", argdep))
10061028
}

0 commit comments

Comments
 (0)