NewModuleSetForProtoc returns a new ModuleSet for protoc -I dirPaths and filePaths. The returned ModuleSet will have a single targeted Module, with target files matching the filePaths. Technically this will work with len(filePaths) == 0 but we should probably make sure that is banned in protoc.
( ctx context.Context, logger *slog.Logger, storageosProvider storageos.Provider, includeDirPaths []string, filePaths []string, )
| 37 | // Technically this will work with len(filePaths) == 0 but we should probably make sure |
| 38 | // that is banned in protoc. |
| 39 | func NewModuleSetForProtoc( |
| 40 | ctx context.Context, |
| 41 | logger *slog.Logger, |
| 42 | storageosProvider storageos.Provider, |
| 43 | includeDirPaths []string, |
| 44 | filePaths []string, |
| 45 | ) (bufmodule.ModuleSet, error) { |
| 46 | absIncludeDirPaths, err := normalizeAndAbsolutePaths(includeDirPaths, "include directory") |
| 47 | if err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | absFilePaths, err := normalizeAndAbsolutePaths(filePaths, "input file") |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | var rootBuckets []storage.ReadBucket |
| 55 | for _, includeDirPath := range includeDirPaths { |
| 56 | rootBucket, err := storageosProvider.NewReadWriteBucket( |
| 57 | includeDirPath, |
| 58 | storageos.ReadWriteBucketWithSymlinksIfSupported(), |
| 59 | ) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | // need to do match extension here |
| 64 | // https://github.com/bufbuild/buf/issues/113 |
| 65 | rootBuckets = append(rootBuckets, storage.FilterReadBucket(rootBucket, storage.MatchPathExt(".proto"))) |
| 66 | } |
| 67 | targetPaths, err := xslices.MapError( |
| 68 | absFilePaths, |
| 69 | func(absFilePath string) (string, error) { |
| 70 | return applyRootsToTargetPath(absIncludeDirPaths, absFilePath, normalpath.Absolute) |
| 71 | }, |
| 72 | ) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | |
| 77 | moduleSetBuilder := bufmodule.NewModuleSetBuilder(ctx, logger, bufmodule.NopModuleDataProvider, bufmodule.NopCommitProvider) |
| 78 | moduleSetBuilder.AddLocalModule( |
| 79 | storage.MultiReadBucket(rootBuckets...), |
| 80 | ".", |
| 81 | true, |
| 82 | bufmodule.LocalModuleWithTargetPaths( |
| 83 | targetPaths, |
| 84 | nil, |
| 85 | ), |
| 86 | ) |
| 87 | return moduleSetBuilder.Build() |
| 88 | } |
| 89 | |
| 90 | // *** PRIVATE *** |
| 91 |
searching dependent graphs…