9
9
"sync"
10
10
11
11
"github.com/coreos/go-semver/semver"
12
+ "github.com/lima-vm/lima/pkg/limayaml"
12
13
"github.com/lima-vm/lima/pkg/store/dirnames"
13
14
"github.com/lima-vm/lima/pkg/store/filenames"
14
15
"github.com/lima-vm/lima/pkg/version/versionutil"
@@ -19,6 +20,7 @@ import (
19
20
var warnBaseIsExperimental = sync .OnceFunc (func () {
20
21
logrus .Warn ("`base` is experimental" )
21
22
})
23
+
22
24
var warnFileIsExperimental = sync .OnceFunc (func () {
23
25
logrus .Warn ("`provision[*].file` and `probes[*].file` are experimental" )
24
26
})
@@ -69,23 +71,23 @@ func (tmpl *Template) embedAllBases(ctx context.Context, embedAll, defaultBase b
69
71
break
70
72
}
71
73
baseLocator := tmpl .Config .Base [0 ]
72
- isTemplate , _ := SeemsTemplateURL (baseLocator )
74
+ isTemplate , _ := SeemsTemplateURL (baseLocator . URL )
73
75
if isTemplate && ! embedAll {
74
76
// Once we skip a template:// URL we can no longer embed any other base template
75
77
for i := 1 ; i < len (tmpl .Config .Base ); i ++ {
76
- isTemplate , _ = SeemsTemplateURL (tmpl .Config .Base [i ])
78
+ isTemplate , _ = SeemsTemplateURL (tmpl .Config .Base [i ]. URL )
77
79
if ! isTemplate {
78
- return fmt .Errorf ("cannot embed template %q after not embedding %q" , tmpl .Config .Base [i ], baseLocator )
80
+ return fmt .Errorf ("cannot embed template %q after not embedding %q" , tmpl .Config .Base [i ]. URL , baseLocator . URL )
79
81
}
80
82
}
81
83
break
82
84
// TODO should we track embedding of template:// URLs so we can warn if we embed a non-template:// URL afterwards?
83
85
}
84
86
85
- if seen [baseLocator ] {
86
- return fmt .Errorf ("base template loop detected: template %q already included" , baseLocator )
87
+ if seen [baseLocator . URL ] {
88
+ return fmt .Errorf ("base template loop detected: template %q already included" , baseLocator . URL )
87
89
}
88
- seen [baseLocator ] = true
90
+ seen [baseLocator . URL ] = true
89
91
90
92
// remove base[0] from template before merging
91
93
if err := tmpl .embedBase (ctx , baseLocator , embedAll , seen ); err != nil {
@@ -101,13 +103,13 @@ func (tmpl *Template) embedAllBases(ctx context.Context, embedAll, defaultBase b
101
103
return nil
102
104
}
103
105
104
- func (tmpl * Template ) embedBase (ctx context.Context , baseLocator string , embedAll bool , seen map [string ]bool ) error {
106
+ func (tmpl * Template ) embedBase (ctx context.Context , baseLocator limayaml. LocatorWithDigest , embedAll bool , seen map [string ]bool ) error {
105
107
warnBaseIsExperimental ()
106
- logrus .Debugf ("Embedding base %q in template %q" , baseLocator , tmpl .Locator )
108
+ logrus .Debugf ("Embedding base %q in template %q" , baseLocator . URL , tmpl .Locator )
107
109
if err := tmpl .Unmarshal (); err != nil {
108
110
return err
109
111
}
110
- base , err := Read (ctx , "" , baseLocator )
112
+ base , err := Read (ctx , "" , baseLocator . URL )
111
113
if err != nil {
112
114
return err
113
115
}
@@ -308,7 +310,7 @@ func (tmpl *Template) deleteListEntry(list string, idx int) {
308
310
tmpl .expr .WriteString (fmt .Sprintf ("| del($a.%s[%d], $b.%s[%d])\n " , list , idx , list , idx ))
309
311
}
310
312
311
- // upgradeListEntryStringToMapField turns list[idx] from a string to a {field: list[idx]} map
313
+ // upgradeListEntryStringToMapField turns list[idx] from a string to a {field: list[idx]} map.
312
314
func (tmpl * Template ) upgradeListEntryStringToMapField (list string , idx int , field string ) {
313
315
// TODO the head_comment on the string becomes duplicated as a foot_comment on the new field; could be a yq bug?
314
316
tmpl .expr .WriteString (fmt .Sprintf ("| ($a.%s[%d] | select(type == \" !!str\" )) |= {\" %s\" : .}\n " , list , idx , field ))
@@ -557,9 +559,9 @@ func (tmpl *Template) embedAllScripts(ctx context.Context, embedAll bool) error
557
559
// Don't overwrite existing script. This should throw an error during validation.
558
560
if p .File != nil && p .Script == "" {
559
561
warnFileIsExperimental ()
560
- isTemplate , _ := SeemsTemplateURL (* p .File )
562
+ isTemplate , _ := SeemsTemplateURL (p .File . URL )
561
563
if embedAll || ! isTemplate {
562
- scriptTmpl , err := Read (ctx , "" , * p .File )
564
+ scriptTmpl , err := Read (ctx , "" , p .File . URL )
563
565
if err != nil {
564
566
return err
565
567
}
@@ -570,9 +572,9 @@ func (tmpl *Template) embedAllScripts(ctx context.Context, embedAll bool) error
570
572
for i , p := range tmpl .Config .Provision {
571
573
if p .File != nil && p .Script == "" {
572
574
warnFileIsExperimental ()
573
- isTemplate , _ := SeemsTemplateURL (* p .File )
575
+ isTemplate , _ := SeemsTemplateURL (p .File . URL )
574
576
if embedAll || ! isTemplate {
575
- scriptTmpl , err := Read (ctx , "" , * p .File )
577
+ scriptTmpl , err := Read (ctx , "" , p .File . URL )
576
578
if err != nil {
577
579
return err
578
580
}
0 commit comments