MCPcopy Create free account
hub / github.com/compose-spec/compose-go / ApplyInclude

Function ApplyInclude

loader/include.go:54–165  ·  view source on GitHub ↗
(ctx context.Context, workingDir string, environment types.Mapping, model map[string]any, options *Options, included []string, processor PostProcessor)

Source from the content-addressed store, hash-verified

52}
53
54func 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 })

Callers 1

loadYamlFileFunction · 0.85

Calls 12

GetEnvFromFileFunction · 0.92
ToConfigFilesFunction · 0.92
loadIncludeConfigFunction · 0.85
loadYamlModelFunction · 0.85
importResourcesFunction · 0.85
cloneMethod · 0.80
RemoteResourceLoadersMethod · 0.80
MergeMethod · 0.80
CloneMethod · 0.80
AcceptMethod · 0.65
LoadMethod · 0.65
DirMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…