(ctx context.Context, workingDir string, environment types.Mapping, model map[string]any, options *Options, included []string, processor PostProcessor)
| 52 | } |
| 53 | |
| 54 | func ApplyInclude(ctx context.Context, workingDir string, environment types.Mapping, model map[string]any, options *Options, included []string, processor PostProcessor) error { |
| 55 | includeConfig, err := loadIncludeConfig(model["include"]) |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | for _, r := range includeConfig { |
| 61 | for _, listener := range options.Listeners { |
| 62 | listener("include", map[string]any{ |
| 63 | "path": r.Path, |
| 64 | "workingdir": workingDir, |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | var relworkingdir string |
| 69 | for i, p := range r.Path { |
| 70 | for _, loader := range options.ResourceLoaders { |
| 71 | if !loader.Accept(p) { |
| 72 | continue |
| 73 | } |
| 74 | path, err := loader.Load(ctx, p) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | p = path |
| 79 | |
| 80 | if i == 0 { // This is the "main" file, used to define project-directory. Others are overrides |
| 81 | |
| 82 | switch { |
| 83 | case r.ProjectDirectory == "": |
| 84 | relworkingdir = loader.Dir(path) |
| 85 | r.ProjectDirectory = filepath.Dir(path) |
| 86 | case !filepath.IsAbs(r.ProjectDirectory): |
| 87 | relworkingdir = loader.Dir(r.ProjectDirectory) |
| 88 | r.ProjectDirectory = filepath.Join(workingDir, r.ProjectDirectory) |
| 89 | |
| 90 | default: |
| 91 | relworkingdir = r.ProjectDirectory |
| 92 | |
| 93 | } |
| 94 | for _, f := range included { |
| 95 | if f == path { |
| 96 | included = append(included, path) |
| 97 | return fmt.Errorf("include cycle detected:\n%s\n include %s", included[0], strings.Join(included[1:], "\n include ")) |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | r.Path[i] = p |
| 103 | } |
| 104 | |
| 105 | loadOptions := options.clone() |
| 106 | loadOptions.ResolvePaths = true |
| 107 | loadOptions.SkipNormalization = true |
| 108 | loadOptions.SkipConsistencyCheck = true |
| 109 | loadOptions.ResourceLoaders = append(loadOptions.RemoteResourceLoaders(), localResourceLoader{ |
| 110 | WorkingDir: r.ProjectDirectory, |
| 111 | }) |
no test coverage detected
searching dependent graphs…