@@ -94,25 +94,38 @@ func rawReplaceBuildArguments(fc []byte, args Arguments) []byte {
94
94
95
95
// replateBuildArguments marshals the package config to YAML and replaces the given arguments with their corresponding
96
96
// 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 ) {
98
98
type configOnlyHelper struct {
99
99
Config PackageConfig `yaml:"config"`
100
100
}
101
- cfgonly := configOnlyHelper {Config : pkg .Config }
102
- fc , err = yaml .Marshal (cfgonly )
101
+ fc , err := yaml .Marshal (configOnlyHelper {Config : pkg .Config })
103
102
if err != nil {
104
103
return
105
104
}
106
-
107
105
fc = rawReplaceBuildArguments (fc , args )
108
-
109
106
cfg , err := unmarshalTypeDependentConfig (pkg .Type , func (out interface {}) error {
110
107
return yaml .Unmarshal (fc , out )
111
108
})
112
109
if err != nil {
113
110
return
114
111
}
115
112
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
+
116
129
return
117
130
}
118
131
@@ -194,7 +207,7 @@ type packageDependency struct {
194
207
195
208
// Package is a single buildable artifact within a component
196
209
type Package struct {
197
- C * Component
210
+ C * Component `json:"-"`
198
211
199
212
// computing the version is expensive - let's cache that
200
213
versionCache string
@@ -207,7 +220,8 @@ type Package struct {
207
220
// Instanciated packages are packages which have some of their build args resolved during linking,
208
221
// i.e. have their values set through the dependant package. Variant packages are always copies
209
222
// 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
211
225
212
226
dependencies []* Package
213
227
layout map [* Package ]string
@@ -230,21 +244,26 @@ func (p *Package) link(idx map[string]*Package) error {
230
244
return PackageNotFoundErr {dep .Ref }
231
245
}
232
246
247
+ err := deppkg .link (idx )
248
+ if err != nil {
249
+ return err
250
+ }
251
+
233
252
// This dependency has arguments which we need to replace in the dependency package itself.
234
253
// To this end we copy the package, replace the build arg and make the new (virtual) package
235
254
// fit for purpose.
236
255
if len (dep .Args ) > 0 {
237
256
cpy := * deppkg
238
- fc , err := replaceBuildArguments (& cpy , dep .Args )
257
+ err := replaceBuildArguments (& cpy , dep .Args )
239
258
if err != nil {
240
259
return err
241
260
}
242
261
if dep .Alias != "" {
243
262
cpy .Name = dep .Alias
244
263
}
245
- cpy .Definition = fc
246
264
cpy .versionCache = ""
247
265
cpy .InstanceOf = deppkg .FullName ()
266
+ cpy .InstanceArgs = dep .Args
248
267
249
268
deppkg = & cpy
250
269
p .C .Packages = append (p .C .Packages , deppkg )
@@ -888,7 +907,7 @@ func (p *Package) resolveBuiltinVariables() error {
888
907
}
889
908
}
890
909
891
- _ , err = replaceBuildArguments (p , builtinArgs )
910
+ err = replaceBuildArguments (p , builtinArgs )
892
911
if err != nil {
893
912
return err
894
913
}
@@ -969,7 +988,7 @@ func (p *Package) ContentManifest() ([]string, error) {
969
988
// WriteVersionManifest writes the manifest whoose hash is the version of this package (see Version())
970
989
func (p * Package ) WriteVersionManifest (out io.Writer ) error {
971
990
if p .dependencies == nil {
972
- return xerrors .Errorf ("package is not linked" )
991
+ return xerrors .Errorf ("package %s is not linked" , p . FullName () )
973
992
}
974
993
975
994
envhash , err := p .C .W .EnvironmentManifest .Hash ()
@@ -1001,6 +1020,9 @@ func (p *Package) WriteVersionManifest(out io.Writer) error {
1001
1020
1002
1021
bundle = append (bundle , fmt .Sprintf ("environment: %s\n " , envhash ))
1003
1022
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
+ }
1004
1026
for _ , argdep := range p .ArgumentDependencies {
1005
1027
bundle = append (bundle , fmt .Sprintf ("arg %s\n " , argdep ))
1006
1028
}
0 commit comments