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

Method moduleSourceWithClient

core/schema/modulesource.go:3343–3399  ·  view source on GitHub ↗
(
	ctx context.Context,
	src *core.ModuleSource,
	args struct {
		Generator dagql.String
		OutputDir dagql.String
	},
)

Source from the content-addressed store, hash-verified

3341}
3342
3343func (s *moduleSourceSchema) moduleSourceWithClient(
3344 ctx context.Context,
3345 src *core.ModuleSource,
3346 args struct {
3347 Generator dagql.String
3348 OutputDir dagql.String
3349 },
3350) (*core.ModuleSource, error) {
3351 src = src.Clone()
3352
3353 if src.ConfigClients == nil {
3354 src.ConfigClients = []*modules.ModuleConfigClient{}
3355 }
3356
3357 moduleConfigClient := &modules.ModuleConfigClient{
3358 Generator: args.Generator.String(),
3359 Directory: args.OutputDir.String(),
3360 }
3361
3362 for _, client := range src.ConfigClients {
3363 if filepath.Clean(client.Directory) == filepath.Clean(moduleConfigClient.Directory) {
3364 return nil, fmt.Errorf("a client is already generated in the %s directory", client.Directory)
3365 }
3366 }
3367
3368 // Verify that the generator can be loaded as a module and clean
3369 // the generator path if it's a local path.
3370 if !sdk.IsModuleSDKBuiltin(moduleConfigClient.Generator) {
3371 dag, err := core.CurrentDagqlServer(ctx)
3372 if err != nil {
3373 return nil, fmt.Errorf("failed to get dag server: %w", err)
3374 }
3375
3376 query, err := core.CurrentQuery(ctx)
3377 if err != nil {
3378 return nil, fmt.Errorf("failed to get current query: %w", err)
3379 }
3380
3381 bk, err := query.Engine(ctx)
3382 if err != nil {
3383 return nil, fmt.Errorf("failed to get engine client: %w", err)
3384 }
3385
3386 clientModule, err := core.ResolveDepToSource(ctx, bk, dag, src, moduleConfigClient.Generator, "", "")
3387 if err != nil {
3388 return nil, fmt.Errorf("failed to resolve client module source: %w", err)
3389 }
3390
3391 if clientModule.Self().Kind == core.ModuleSourceKindLocal {
3392 moduleConfigClient.Generator = filepath.Clean(moduleConfigClient.Generator)
3393 }
3394 }
3395
3396 src.ConfigClients = append(src.ConfigClients, moduleConfigClient)
3397
3398 return src, nil
3399}
3400

Callers

nothing calls this directly

Calls 8

IsModuleSDKBuiltinFunction · 0.92
CurrentDagqlServerFunction · 0.92
CurrentQueryFunction · 0.92
ResolveDepToSourceFunction · 0.92
SelfMethod · 0.80
CloneMethod · 0.65
StringMethod · 0.65
EngineMethod · 0.65

Tested by

no test coverage detected