diff options
author | 2023-09-27 22:34:57 +0000 | |
---|---|---|
committer | 2023-10-03 19:44:34 +0000 | |
commit | 3b7e34ba717cba75077c8d7f12ae7f1a8ca907f1 (patch) | |
tree | 95898c0d93a8521b841bddf8526a0e7751025c23 /api/api.go | |
parent | 53565bfdb0193e38f96811b58f433d961711681f (diff) |
assign labels to merged_txt modules with defs
This is groundwork for allowlist v2, and ensures that rdeps of
merged_txt targets appropriately reflect that these targets exist.
Fixes: 302061007
Test: Unit test update
Change-Id: I1d64635bb3db50ee525f1a557fd4b73d50dba879
Diffstat (limited to 'api/api.go')
-rw-r--r-- | api/api.go | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/api/api.go b/api/api.go index 431d6d8d06ff..692d38fe21a2 100644 --- a/api/api.go +++ b/api/api.go @@ -114,6 +114,7 @@ type defaultsProps struct { } type Bazel_module struct { + Label *string Bp2build_available *bool } type bazelProperties struct { @@ -140,6 +141,8 @@ type MergedTxtDefinition struct { ModuleTag string // public, system, module-lib or system-server Scope string + // True if there is a bp2build definition for this module + Bp2buildDefined bool } func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { @@ -152,8 +155,10 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { if txt.Scope != "public" { filename = txt.Scope + "-" + filename } + moduleName := ctx.ModuleName() + "-" + filename + props := genruleProps{} - props.Name = proptools.StringPtr(ctx.ModuleName() + "-" + filename) + props.Name = proptools.StringPtr(moduleName) props.Tools = []string{"metalava"} props.Out = []string{filename} props.Cmd = proptools.StringPtr(metalavaCmd + "$(in) --out $(out)") @@ -171,7 +176,20 @@ func createMergedTxt(ctx android.LoadHookContext, txt MergedTxtDefinition) { }, } props.Visibility = []string{"//visibility:public"} - ctx.CreateModule(genrule.GenRuleFactory, &props, &bp2buildNotAvailable) + bazelProps := bazelProperties{ + &Bazel_module{ + Bp2build_available: proptools.BoolPtr(false), + }, + } + if txt.Bp2buildDefined { + moduleDir := ctx.ModuleDir() + if moduleDir == android.Bp2BuildTopLevel { + moduleDir = "" + } + label := fmt.Sprintf("//%s:%s", moduleDir, moduleName) + bazelProps.Label = &label + } + ctx.CreateModule(genrule.GenRuleFactory, &props, &bazelProps) } func createMergedAnnotationsFilegroups(ctx android.LoadHookContext, modules, system_server_modules []string) { @@ -301,38 +319,43 @@ func createMergedTxts(ctx android.LoadHookContext, bootclasspath, system_server_ tagSuffix := []string{".api.txt}", ".removed-api.txt}"} distFilename := []string{"android.txt", "android-removed.txt"} + bp2BuildDefined := []bool{true, false} for i, f := range []string{"current.txt", "removed.txt"} { textFiles = append(textFiles, MergedTxtDefinition{ - TxtFilename: f, - DistFilename: distFilename[i], - BaseTxt: ":non-updatable-" + f, - Modules: bootclasspath, - ModuleTag: "{.public" + tagSuffix[i], - Scope: "public", + TxtFilename: f, + DistFilename: distFilename[i], + BaseTxt: ":non-updatable-" + f, + Modules: bootclasspath, + ModuleTag: "{.public" + tagSuffix[i], + Scope: "public", + Bp2buildDefined: bp2BuildDefined[i], }) textFiles = append(textFiles, MergedTxtDefinition{ - TxtFilename: f, - DistFilename: distFilename[i], - BaseTxt: ":non-updatable-system-" + f, - Modules: bootclasspath, - ModuleTag: "{.system" + tagSuffix[i], - Scope: "system", + TxtFilename: f, + DistFilename: distFilename[i], + BaseTxt: ":non-updatable-system-" + f, + Modules: bootclasspath, + ModuleTag: "{.system" + tagSuffix[i], + Scope: "system", + Bp2buildDefined: bp2BuildDefined[i], }) textFiles = append(textFiles, MergedTxtDefinition{ - TxtFilename: f, - DistFilename: distFilename[i], - BaseTxt: ":non-updatable-module-lib-" + f, - Modules: bootclasspath, - ModuleTag: "{.module-lib" + tagSuffix[i], - Scope: "module-lib", + TxtFilename: f, + DistFilename: distFilename[i], + BaseTxt: ":non-updatable-module-lib-" + f, + Modules: bootclasspath, + ModuleTag: "{.module-lib" + tagSuffix[i], + Scope: "module-lib", + Bp2buildDefined: bp2BuildDefined[i], }) textFiles = append(textFiles, MergedTxtDefinition{ - TxtFilename: f, - DistFilename: distFilename[i], - BaseTxt: ":non-updatable-system-server-" + f, - Modules: system_server_classpath, - ModuleTag: "{.system-server" + tagSuffix[i], - Scope: "system-server", + TxtFilename: f, + DistFilename: distFilename[i], + BaseTxt: ":non-updatable-system-server-" + f, + Modules: system_server_classpath, + ModuleTag: "{.system-server" + tagSuffix[i], + Scope: "system-server", + Bp2buildDefined: bp2BuildDefined[i], }) } for _, txt := range textFiles { |