Stitch in the given module to the list being served to the current client. When includeDependencies is true, dependency modules and toolchains are also served with their constructors on the Query root. When entrypoint is true, the module's main-object methods are promoted onto the Query root.
(ctx context.Context, mod dagql.ObjectResult[*core.Module], includeDependencies bool, entrypoint bool)
| 1514 | // When entrypoint is true, the module's main-object methods are promoted |
| 1515 | // onto the Query root. |
| 1516 | func (srv *Server) ServeModule(ctx context.Context, mod dagql.ObjectResult[*core.Module], includeDependencies bool, entrypoint bool) error { |
| 1517 | client, err := srv.clientFromContext(ctx) |
| 1518 | if err != nil { |
| 1519 | return err |
| 1520 | } |
| 1521 | |
| 1522 | client.stateMu.Lock() |
| 1523 | defer client.stateMu.Unlock() |
| 1524 | |
| 1525 | if err := srv.serveModule(client, core.NewUserMod(mod), core.InstallOpts{Entrypoint: entrypoint}); err != nil { |
| 1526 | return err |
| 1527 | } |
| 1528 | if includeDependencies { |
| 1529 | for _, dep := range mod.Self().Deps.Mods() { |
| 1530 | if err := srv.serveModule(client, dep, core.InstallOpts{}); err != nil { |
| 1531 | return fmt.Errorf("error serving dependency %s: %w", dep.Name(), err) |
| 1532 | } |
| 1533 | } |
| 1534 | |
| 1535 | // Also serve toolchains so their functions are available in the |
| 1536 | // client schema (e.g. when `dagger shell` `.cd`s into a module). |
| 1537 | if mod.Self().Source.Valid && mod.Self().Source.Value.Self() != nil { |
| 1538 | src := mod.Self().Source.Value |
| 1539 | defaultPathContextSrc := src |
| 1540 | if mod.Self().ContextSource.Valid && mod.Self().ContextSource.Value.Self() != nil { |
| 1541 | defaultPathContextSrc = mod.Self().ContextSource.Value |
| 1542 | } |
| 1543 | for i, tcSrc := range src.Self().Toolchains { |
| 1544 | if tcSrc.Self() == nil { |
| 1545 | continue |
| 1546 | } |
| 1547 | var cfg *modules.ModuleConfigDependency |
| 1548 | if i < len(src.Self().ConfigToolchains) { |
| 1549 | cfg = src.Self().ConfigToolchains[i] |
| 1550 | } |
| 1551 | pending := pendingRelatedModule(defaultPathContextSrc, tcSrc.Self(), cfg, false) |
| 1552 | tcMod, err := srv.resolveModuleSourceAsModule(ctx, client.dag, tcSrc, pending) |
| 1553 | if err != nil { |
| 1554 | return fmt.Errorf("error resolving toolchain module: %w", err) |
| 1555 | } |
| 1556 | if err := srv.serveModule(client, core.NewUserMod(tcMod), core.InstallOpts{}); err != nil { |
| 1557 | return fmt.Errorf("error serving toolchain %s: %w", tcMod.Self().Name(), err) |
| 1558 | } |
| 1559 | } |
| 1560 | } |
| 1561 | } |
| 1562 | return nil |
| 1563 | } |
| 1564 | |
| 1565 | // serveModule adds a module to the client's served set with the given install |
| 1566 | // policy. |
nothing calls this directly
no test coverage detected