From 08253a0901ccd65a2d08dce797e410cd06054e61 Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Mon, 1 Aug 2022 16:11:25 -0700 Subject: [PATCH 1/2] Index Go code in the build/make/tools Test: manual Change-Id: Iae326016074cbed8b83940dd188ca1171cc4d696 --- build_kzip.bash | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build_kzip.bash b/build_kzip.bash index 6219021cf..fa616b94d 100755 --- a/build_kzip.bash +++ b/build_kzip.bash @@ -44,14 +44,18 @@ declare -r go_extractor=$(realpath prebuilts/build-tools/linux-x86/bin/go_extrac declare -r go_root=$(realpath prebuilts/go/linux-x86) declare -r source_root=$PWD -# TODO(asmundak): Until b/182183061 is fixed, default corpus has to be specified -# in the rules file. Generate this file on the fly with corpus value set from the -# environment variable. -for dir in blueprint soong; do - (cd "build/$dir"; +# For the Go code, we invoke the extractor directly. The two caveats are that +# the extractor's rewrite rules are generated on the fly as they depend on the XREF_CORPUS +# value, and that the name of the kzip file is derived from the directory name +# by replacing '/' with '_'. +declare -ar go_modules=(build/blueprint build/soong + build/make/tools/canoninja build/make/tools/compliance build/make/tools/rbcrun) +for dir in "${go_modules[@]}"; do + (cd "$dir"; + outfile=$(echo "$dir" | sed -r 's|/|_|g;s|(.*)|\1.go.kzip|'); KYTHE_ROOT_DIRECTORY="${source_root}" "$go_extractor" --goroot="$go_root" \ --rules=<(printf '[{"pattern": "(.*)","vname": {"path": "@1@", "corpus":"%s"}}]' "${XREF_CORPUS}") \ - --canonicalize_package_corpus --output "${abspath_out}/soong/build_${dir}.go.kzip" ./... + --canonicalize_package_corpus --output "${abspath_out}/soong/$outfile" ./... ) done From a09540641198a4256082d30a98c859fe35d1b8de Mon Sep 17 00:00:00 2001 From: Sasha Smundak Date: Tue, 2 Aug 2022 18:23:58 -0700 Subject: [PATCH 2/2] Consolidate Bazel conversion state into a single field in CommonProperties Bazel conversion state needs to be cloned during module cloning, so it should be registered via module.AddProperties. Until now it was done implicitly as the modules converted so far added the whole base.commonProperties field (and thus transitively all its subfields). However, adding CommonProperties also adds its fields to the list of the module's attributes, which is undesirable. The problem surfaced while implementing Bazel conversion to the `license` rule. Bug: 190817312 Test: treehugger Change-Id: Id3de4ede8df81b21f00065a3a1bdc2d707391c3a --- android/bazel.go | 14 ++++++++++++++ android/module.go | 27 +++++++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/android/bazel.go b/android/bazel.go index 40f2917db..183a2f324 100644 --- a/android/bazel.go +++ b/android/bazel.go @@ -35,6 +35,20 @@ const ( Bp2BuildTopLevel = "." ) +type BazelConversionStatus struct { + // Information about _all_ bp2build targets generated by this module. Multiple targets are + // supported as Soong handles some things within a single target that we may choose to split into + // multiple targets, e.g. renderscript, protos, yacc within a cc module. + Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` + + // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to + // Bazel + UnconvertedDeps []string `blueprint:"mutated"` + + // MissingBp2buildDep stores the module names of direct dependency that were not found + MissingDeps []string `blueprint:"mutated"` +} + type bazelModuleProperties struct { // The label of the Bazel target replacing this Soong module. When run in conversion mode, this // will import the handcrafted build target into the autogenerated file. Note: this may result in diff --git a/android/module.go b/android/module.go index 4dbfdd318..39f5ff9e6 100644 --- a/android/module.go +++ b/android/module.go @@ -909,17 +909,8 @@ type commonProperties struct { // constants in image.go, but can also be set to a custom value by individual module types. ImageVariation string `blueprint:"mutated"` - // Information about _all_ bp2build targets generated by this module. Multiple targets are - // supported as Soong handles some things within a single target that we may choose to split into - // multiple targets, e.g. renderscript, protos, yacc within a cc module. - Bp2buildInfo []bp2buildInfo `blueprint:"mutated"` - - // UnconvertedBp2buildDep stores the module names of direct dependency that were not converted to - // Bazel - UnconvertedBp2buildDeps []string `blueprint:"mutated"` - - // MissingBp2buildDep stores the module names of direct dependency that were not found - MissingBp2buildDeps []string `blueprint:"mutated"` + // Bazel conversion status + BazelConversionStatus BazelConversionStatus `blueprint:"mutated"` } // CommonAttributes represents the common Bazel attributes from which properties @@ -1489,40 +1480,40 @@ func (b bp2buildInfo) BazelAttributes() []interface{} { } func (m *ModuleBase) addBp2buildInfo(info bp2buildInfo) { - m.commonProperties.Bp2buildInfo = append(m.commonProperties.Bp2buildInfo, info) + m.commonProperties.BazelConversionStatus.Bp2buildInfo = append(m.commonProperties.BazelConversionStatus.Bp2buildInfo, info) } // IsConvertedByBp2build returns whether this module was converted via bp2build. func (m *ModuleBase) IsConvertedByBp2build() bool { - return len(m.commonProperties.Bp2buildInfo) > 0 + return len(m.commonProperties.BazelConversionStatus.Bp2buildInfo) > 0 } // Bp2buildTargets returns the Bazel targets bp2build generated for this module. func (m *ModuleBase) Bp2buildTargets() []bp2buildInfo { - return m.commonProperties.Bp2buildInfo + return m.commonProperties.BazelConversionStatus.Bp2buildInfo } // AddUnconvertedBp2buildDep stores module name of a dependency that was not converted to Bazel. func (b *baseModuleContext) AddUnconvertedBp2buildDep(dep string) { - unconvertedDeps := &b.Module().base().commonProperties.UnconvertedBp2buildDeps + unconvertedDeps := &b.Module().base().commonProperties.BazelConversionStatus.UnconvertedDeps *unconvertedDeps = append(*unconvertedDeps, dep) } // AddMissingBp2buildDep stores module name of a dependency that was not found in a Android.bp file. func (b *baseModuleContext) AddMissingBp2buildDep(dep string) { - missingDeps := &b.Module().base().commonProperties.MissingBp2buildDeps + missingDeps := &b.Module().base().commonProperties.BazelConversionStatus.MissingDeps *missingDeps = append(*missingDeps, dep) } // GetUnconvertedBp2buildDeps returns the list of module names of this module's direct dependencies that // were not converted to Bazel. func (m *ModuleBase) GetUnconvertedBp2buildDeps() []string { - return FirstUniqueStrings(m.commonProperties.UnconvertedBp2buildDeps) + return FirstUniqueStrings(m.commonProperties.BazelConversionStatus.UnconvertedDeps) } // GetMissingBp2buildDeps eturns the list of module names that were not found in Android.bp files. func (m *ModuleBase) GetMissingBp2buildDeps() []string { - return FirstUniqueStrings(m.commonProperties.MissingBp2buildDeps) + return FirstUniqueStrings(m.commonProperties.BazelConversionStatus.MissingDeps) } func (m *ModuleBase) AddJSONData(d *map[string]interface{}) {