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

Function ResolveDepToSource

core/modulesource.go:1737–1899  ·  view source on GitHub ↗

ResolveDepToSource given a parent module source, load a dependency of it from the given depSrcRef, depPin and depName.

(
	ctx context.Context,
	bk *engineutil.Client,
	dag *dagql.Server,
	parentSrc *ModuleSource,
	depSrcRef string,
	depPin string,
	depName string,
)

Source from the content-addressed store, hash-verified

1735// ResolveDepToSource given a parent module source, load a dependency of it
1736// from the given depSrcRef, depPin and depName.
1737func ResolveDepToSource(
1738 ctx context.Context,
1739 bk *engineutil.Client,
1740 dag *dagql.Server,
1741 parentSrc *ModuleSource,
1742 depSrcRef string,
1743 depPin string,
1744 depName string,
1745) (inst dagql.ObjectResult[*ModuleSource], err error) {
1746 // sanity checks
1747 if parentSrc != nil {
1748 if parentSrc.SourceRootSubpath == "" {
1749 return inst, fmt.Errorf("source root path must be set")
1750 }
1751 if parentSrc.ModuleName == "" {
1752 return inst, fmt.Errorf("module name must be set")
1753 }
1754 }
1755
1756 parsedDepRef, err := ParseRefString(
1757 ctx,
1758 ModuleSourceStatFS{bk, parentSrc},
1759 depSrcRef,
1760 depPin,
1761 )
1762 if err != nil {
1763 return inst, fmt.Errorf("failed to parse dep ref string: %w", err)
1764 }
1765
1766 switch parsedDepRef.Kind {
1767 case ModuleSourceKindLocal:
1768 if parentSrc == nil {
1769 // it's okay if there's no parent when the dep is git, but we can't find a local dep relative to nothing
1770 return inst, fmt.Errorf("local module dep source path %q must be relative to a parent module", depSrcRef)
1771 }
1772
1773 if filepath.IsAbs(depSrcRef) {
1774 // they need to be relative to the parent module's source root
1775 return inst, fmt.Errorf("local module dep source path %q is absolute", depSrcRef)
1776 }
1777
1778 switch parentSrc.Kind {
1779 case ModuleSourceKindLocal:
1780 // parent=local, dep=local
1781 // load the dep relative to the parent's source root, from the caller's filesystem
1782 depPath := filepath.Join(parentSrc.Local.ContextDirectoryPath, parentSrc.SourceRootSubpath, depSrcRef)
1783 depRelPath, err := pathutil.LexicalRelativePath(parentSrc.Local.ContextDirectoryPath, depPath)
1784 if err != nil {
1785 return inst, fmt.Errorf("failed to get relative path from context to dep: %w", err)
1786 }
1787 if !filepath.IsLocal(depRelPath) {
1788 return inst, fmt.Errorf("local module dep source path %q escapes context %q", depRelPath, parentSrc.Local.ContextDirectoryPath)
1789 }
1790
1791 selectors := []dagql.Selector{{
1792 Field: "moduleSource",
1793 Args: []dagql.NamedInput{
1794 {Name: "refString", Value: dagql.String(depPath)},

Callers 7

externalSDKForModuleMethod · 0.92
localModuleSourceMethod · 0.92
gitModuleSourceMethod · 0.92
loadBlueprintModuleMethod · 0.92

Calls 8

LexicalRelativePathFunction · 0.92
StringTypeAlias · 0.92
BooleanTypeAlias · 0.92
ParseRefStringFunction · 0.85
GitRefStringFunction · 0.85
IsMethod · 0.80
SelectMethod · 0.65
RootMethod · 0.45

Tested by

no test coverage detected