Skip to content

Commit

Permalink
cueutils: read hidden files from overlay rather than unifying values
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGamba committed Sep 27, 2024
1 parent e82cb5e commit a2d7b98
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions cueutils/cueutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func Unmarshal(configs []CueConfigFile, dir, packageName string, value *cue.Valu
ctxOpts := []cuecontext.Option{embedding}
c := cuecontext.New(ctxOpts...)

packagePaths := []string{"."}
insts := []*build.Instance{}
var err error
dirAbs, err := filepath.Abs(dir)
Expand All @@ -58,9 +59,6 @@ func Unmarshal(configs []CueConfigFile, dir, packageName string, value *cue.Valu

overlay := map[string]load.Source{}
for i, cf := range configs {
if strings.HasPrefix(filepath.Base(cf.Name), ".") {
continue
}
Logger.Printf("config: n: %d, name: %s\n", i, cf.Name)
d, err := io.ReadAll(cf.Data)
if err != nil {
Expand All @@ -77,6 +75,9 @@ func Unmarshal(configs []CueConfigFile, dir, packageName string, value *cue.Valu
overlayPath := filepath.Join(dirAbs, filepath.Base(cf.Name))
overlay[overlayPath] = load.FromBytes(d)
Logger.Printf("overlay: %s\n", overlayPath)
if strings.HasPrefix(filepath.Base(cf.Name), ".") {
packagePaths = append(packagePaths, overlayPath)
}
}

if dir == "" {
Expand All @@ -91,7 +92,6 @@ func Unmarshal(configs []CueConfigFile, dir, packageName string, value *cue.Valu
Dir: dir,
Overlay: overlay,
}
packagePaths := []string{"."}
Logger.Printf("dir: %s\nModuleRoot: %s\npackagePaths: %v\n", dir, lc.ModuleRoot, packagePaths)
ii := load.Instances(packagePaths, lc)
logInstancesFiles(dir, ii)
Expand All @@ -106,20 +106,6 @@ func Unmarshal(configs []CueConfigFile, dir, packageName string, value *cue.Valu
*value = (*value).Unify(v)
}

for i, cf := range configs {
if !strings.HasPrefix(filepath.Base(cf.Name), ".") {
continue
}
Logger.Printf("Loading hidden file %d: %s\n", i, cf.Name)
d, err := io.ReadAll(cf.Data)
if err != nil {
return fmt.Errorf("failed to read: %w", err)
}

v := c.CompileBytes(d, cue.Filename(cf.Name), cue.Scope(*value))
*value = value.Unify(v)
}

if value.Err() != nil {
return fmt.Errorf("failed to compile: %s", cueErrors.Details(value.Err(), nil))
}
Expand Down

0 comments on commit a2d7b98

Please sign in to comment.