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

Method moduleSourceWithSDK

core/schema/modulesource.go:1293–1347  ·  view source on GitHub ↗
(
	ctx context.Context,
	src *core.ModuleSource,
	args struct {
		Source string
	},
)

Source from the content-addressed store, hash-verified

1291}
1292
1293func (s *moduleSourceSchema) moduleSourceWithSDK(
1294 ctx context.Context,
1295 src *core.ModuleSource,
1296 args struct {
1297 Source string
1298 },
1299) (*core.ModuleSource, error) {
1300 src = src.Clone()
1301 if args.Source == "" {
1302 src.SDK = nil
1303 src.SDKImpl = nil
1304
1305 return src, nil
1306 }
1307
1308 if src.SDK == nil {
1309 src.SDK = &core.SDKConfig{}
1310 }
1311 src.SDK.Source = args.Source
1312
1313 // Default source subpath to source root when an SDK is set but no explicit
1314 // source path was configured (e.g. during module init before dagger.json exists).
1315 // This mirrors the logic in initFromModConfig for the sdkSource != "" && modCfg.Source == "" case.
1316 if src.SourceSubpath == "" {
1317 src.SourceSubpath = src.SourceRootSubpath
1318
1319 // Reload the context directory now that SourceSubpath is set, so that
1320 // the source files are included (e.g. an existing main.go). The initial
1321 // load may have used empty SourceSubpath which matches no files.
1322 err := s.loadModuleSourceContext(ctx, src)
1323 switch {
1324 case err == nil:
1325 case codes.NotFound == status.Code(err) && src.Kind == core.ModuleSourceKindLocal:
1326 // tolerate not found during init when context dir doesn't exist yet
1327 default:
1328 return nil, fmt.Errorf("failed to reload context after setting source subpath: %w", err)
1329 }
1330 }
1331
1332 // reload the sdk implementation too
1333 query, err := core.CurrentQuery(ctx)
1334 if err != nil {
1335 return nil, err
1336 }
1337 src.SDKImpl, err = sdk.NewLoader().SDKForModule(ctx, query, src.SDK, src)
1338 if err != nil {
1339 return nil, fmt.Errorf("failed to load sdk for module source: %w", err)
1340 }
1341
1342 // New SDK means new exposed functions and types. Different .env entries might match.
1343 if err := src.LoadUserDefaults(ctx); err != nil {
1344 return nil, fmt.Errorf("load user defaults: %w", err)
1345 }
1346 return src, nil
1347}
1348
1349func (s *moduleSourceSchema) moduleSourceDirectory(
1350 ctx context.Context,

Callers

nothing calls this directly

Calls 7

CurrentQueryFunction · 0.92
NewLoaderFunction · 0.92
SDKForModuleMethod · 0.80
LoadUserDefaultsMethod · 0.80
CloneMethod · 0.65
CodeMethod · 0.45

Tested by

no test coverage detected