MCPcopy Index your code
hub / github.com/dagger/dagger / initFromModConfig

Method initFromModConfig

core/schema/modulesource.go:963–1065  ·  view source on GitHub ↗

set values in the given src using values read from the module config file provided as bytes

(configBytes []byte, src *core.ModuleSource)

Source from the content-addressed store, hash-verified

961
962// set values in the given src using values read from the module config file provided as bytes
963func (s *moduleSourceSchema) initFromModConfig(configBytes []byte, src *core.ModuleSource) error {
964 // sanity checks
965 if src.SourceRootSubpath == "" {
966 return fmt.Errorf("source root path must be set")
967 }
968
969 modCfg, err := modules.ParseModuleConfig(configBytes)
970 if err != nil {
971 return err
972 }
973
974 if modCfg.Blueprint != nil {
975 if modCfg.SDK != nil {
976 return fmt.Errorf("blueprint and sdk can't both be set")
977 }
978 if len(modCfg.Dependencies) != 0 {
979 return fmt.Errorf("blueprint and dependencies can't both be set")
980 }
981 if modCfg.Source != "" {
982 return fmt.Errorf("blueprint and source can't both be set")
983 }
984 }
985
986 src.ModuleName = modCfg.Name
987 src.ModuleOriginalName = modCfg.Name
988 src.IncludePaths = modCfg.Include
989 src.CodegenConfig = modCfg.Codegen
990 src.ModuleConfigUserFields = modCfg.ModuleConfigUserFields
991 src.ConfigDependencies = modCfg.Dependencies
992 src.ConfigBlueprint = modCfg.Blueprint
993 src.ConfigToolchains = modCfg.Toolchains
994 src.ConfigClients = modCfg.Clients
995
996 engineVersion := modCfg.EngineVersion
997 switch engineVersion {
998 case "":
999 // older versions of dagger might not produce an engine version -
1000 // so return the version that engineVersion was introduced in
1001 engineVersion = engine.MinimumModuleVersion
1002 case modules.EngineVersionLatest:
1003 engineVersion = engine.Version
1004 }
1005 engineVersion = engine.NormalizeVersion(engineVersion)
1006 src.EngineVersion = engineVersion
1007
1008 canDefaultFuncCaching := engine.CheckVersionCompatibility(
1009 engine.BaseVersion(src.EngineVersion),
1010 engine.MinimumDefaultFunctionCachingModuleVersion,
1011 )
1012 switch {
1013 case modCfg.DisableDefaultFunctionCaching != nil:
1014 // explicit setting in dagger.json, use it
1015 src.DisableDefaultFunctionCaching = *modCfg.DisableDefaultFunctionCaching
1016 case canDefaultFuncCaching:
1017 // no explicit setting in dagger.json but module engine version supports it, enable function caching
1018 src.DisableDefaultFunctionCaching = false
1019 default:
1020 // no explicit setting in dagger.json and module engine version doesn't support it, disable function caching

Callers 3

localModuleSourceMethod · 0.95
gitModuleSourceMethod · 0.95

Calls 5

ParseModuleConfigFunction · 0.92
NormalizeVersionFunction · 0.92
BaseVersionFunction · 0.92
rebasePatternsFunction · 0.85

Tested by

no test coverage detected