buildTargetImageWithConfigs builds an image for each module in the workspace. This is used to associate LintConfig and BreakingConfig on a per-module basis.
( ctx context.Context, workspace bufworkspace.Workspace, functionOptions *functionOptions, )
| 1210 | // buildTargetImageWithConfigs builds an image for each module in the workspace. |
| 1211 | // This is used to associate LintConfig and BreakingConfig on a per-module basis. |
| 1212 | func (c *controller) buildTargetImageWithConfigs( |
| 1213 | ctx context.Context, |
| 1214 | workspace bufworkspace.Workspace, |
| 1215 | functionOptions *functionOptions, |
| 1216 | ) ([]ImageWithConfig, error) { |
| 1217 | modules := bufmodule.ModuleSetTargetModules(workspace) |
| 1218 | imageWithConfigs := make([]ImageWithConfig, 0, len(modules)) |
| 1219 | for _, module := range modules { |
| 1220 | c.logger.DebugContext( |
| 1221 | ctx, |
| 1222 | "building image for target module", |
| 1223 | slog.String("moduleOpaqueID", module.OpaqueID()), |
| 1224 | slog.String("moduleDescription", module.Description()), |
| 1225 | ) |
| 1226 | opaqueID := module.OpaqueID() |
| 1227 | // We need to make sure that all dependencies are non-targets, so that they |
| 1228 | // end up as imports in the resulting image. |
| 1229 | moduleSet, err := workspace.WithTargetOpaqueIDs(opaqueID) |
| 1230 | if err != nil { |
| 1231 | return nil, err |
| 1232 | } |
| 1233 | // The moduleReadBucket may include more modules than the target module |
| 1234 | // and its dependencies. This is because the moduleSet is constructed from |
| 1235 | // the workspace. Targeting the module does not remove non-related modules. |
| 1236 | // Build image will use the target info to build the image for the specific |
| 1237 | // module. Non-targeted modules will not be included in the image. |
| 1238 | moduleReadBucket := bufmodule.ModuleSetToModuleReadBucketWithOnlyProtoFiles(moduleSet) |
| 1239 | targetFileInfos, err := bufmodule.GetTargetFileInfos(ctx, moduleReadBucket) |
| 1240 | if err != nil { |
| 1241 | return nil, err |
| 1242 | } |
| 1243 | // This may happen after path targeting. We may have a Module that itself was targeted, |
| 1244 | // but no target files remain. In this case, this isn't a target image. |
| 1245 | // |
| 1246 | // TODO FUTURE: without allowNotExist, this results in silent behavior when --path is incorrect. |
| 1247 | if len(targetFileInfos) == 0 { |
| 1248 | continue |
| 1249 | } |
| 1250 | image, err := c.buildImage( |
| 1251 | ctx, |
| 1252 | moduleReadBucket, |
| 1253 | functionOptions, |
| 1254 | ) |
| 1255 | if err != nil { |
| 1256 | return nil, err |
| 1257 | } |
| 1258 | if err := c.warnUnconfiguredTransitiveImports(ctx, workspace, image); err != nil { |
| 1259 | return nil, err |
| 1260 | } |
| 1261 | imageWithConfigs = append( |
| 1262 | imageWithConfigs, |
| 1263 | newImageWithConfig( |
| 1264 | image, |
| 1265 | module.FullName(), |
| 1266 | module.OpaqueID(), |
| 1267 | workspace.GetLintConfigForOpaqueID(module.OpaqueID()), |
| 1268 | workspace.GetBreakingConfigForOpaqueID(module.OpaqueID()), |
| 1269 | workspace.PluginConfigs(), |
no test coverage detected