Merge changes I0b78ceeb,Ic57e1efd
* changes:
Add environment variable to force keeping ANSI codes
Disable table mode in smart status if window size is not available
diff --git a/android/bazel.go b/android/bazel.go
index 9cebc80..bfd0f90 100644
--- a/android/bazel.go
+++ b/android/bazel.go
@@ -150,17 +150,23 @@
"build/bazel/platforms":/* recursive = */ true,
"build/bazel/product_variables":/* recursive = */ true,
"build/bazel_common_rules":/* recursive = */ true,
+ "build/make/tools":/* recursive = */ true,
"build/pesto":/* recursive = */ true,
// external/bazelbuild-rules_android/... is needed by mixed builds, otherwise mixed builds analysis fails
// e.g. ERROR: Analysis of target '@soong_injection//mixed_builds:buildroot' failed
"external/bazelbuild-rules_android":/* recursive = */ true,
"external/bazel-skylib":/* recursive = */ true,
+ "external/guava":/* recursive = */ true,
+ "external/error_prone":/* recursive = */ true,
+ "external/jsr305":/* recursive = */ true,
+ "frameworks/ex/common":/* recursive = */ true,
"prebuilts/sdk":/* recursive = */ false,
"prebuilts/sdk/tools":/* recursive = */ false,
"prebuilts/r8":/* recursive = */ false,
"packages/apps/Music":/* recursive = */ true,
+ "packages/apps/QuickSearchBox":/* recursive = */ true,
}
// Configure modules in these directories to enable bp2build_available: true or false by default.
diff --git a/bp2build/build_conversion.go b/bp2build/build_conversion.go
index 07f492e..b1a6e2c 100644
--- a/bp2build/build_conversion.go
+++ b/bp2build/build_conversion.go
@@ -261,7 +261,7 @@
// Simple metrics tracking for bp2build
metrics := CodegenMetrics{
- RuleClassCount: make(map[string]int),
+ ruleClassCount: make(map[string]int),
}
dirs := make(map[string]bool)
@@ -277,14 +277,28 @@
switch ctx.Mode() {
case Bp2Build:
+ // There are two main ways of converting a Soong module to Bazel:
+ // 1) Manually handcrafting a Bazel target and associating the module with its label
+ // 2) Automatically generating with bp2build converters
+ //
+ // bp2build converters are used for the majority of modules.
if b, ok := m.(android.Bazelable); ok && b.HasHandcraftedLabel() {
- metrics.handCraftedTargetCount += 1
- metrics.TotalModuleCount += 1
- metrics.AddConvertedModule(m.Name())
+ // Handle modules converted to handcrafted targets.
+ //
+ // Since these modules are associated with some handcrafted
+ // target in a BUILD file, we simply append the entire contents
+ // of that BUILD file to the generated BUILD file.
+ //
+ // The append operation is only done once, even if there are
+ // multiple modules from the same directory associated to
+ // targets in the same BUILD file (or package).
+
+ // Log the module.
+ metrics.AddConvertedModule(m.Name(), Handcrafted)
+
pathToBuildFile := getBazelPackagePath(b)
- // We are using the entire contents of handcrafted build file, so if multiple targets within
- // a package have handcrafted targets, we only want to include the contents one time.
if _, exists := buildFileToAppend[pathToBuildFile]; exists {
+ // Append the BUILD file content once per package, at most.
return
}
t, err := getHandcraftedBuildContent(ctx, b, pathToBuildFile)
@@ -297,23 +311,29 @@
// something more targeted based on the rule type and target
buildFileToAppend[pathToBuildFile] = true
} else if aModule, ok := m.(android.Module); ok && aModule.IsConvertedByBp2build() {
+ // Handle modules converted to generated targets.
+
+ // Log the module.
+ metrics.AddConvertedModule(m.Name(), Generated)
+
+ // Handle modules with unconverted deps. By default, emit a warning.
if unconvertedDeps := aModule.GetUnconvertedBp2buildDeps(); len(unconvertedDeps) > 0 {
msg := fmt.Sprintf("%q depends on unconverted modules: %s", m.Name(), strings.Join(unconvertedDeps, ", "))
if ctx.unconvertedDepMode == warnUnconvertedDeps {
metrics.moduleWithUnconvertedDepsMsgs = append(metrics.moduleWithUnconvertedDepsMsgs, msg)
} else if ctx.unconvertedDepMode == errorModulesUnconvertedDeps {
- metrics.TotalModuleCount += 1
errs = append(errs, fmt.Errorf(msg))
return
}
}
targets = generateBazelTargets(bpCtx, aModule)
- metrics.AddConvertedModule(m.Name())
for _, t := range targets {
- metrics.RuleClassCount[t.ruleClass] += 1
+ // A module can potentially generate more than 1 Bazel
+ // target, each of a different rule class.
+ metrics.IncrementRuleClassCount(t.ruleClass)
}
} else {
- metrics.TotalModuleCount += 1
+ metrics.IncrementUnconvertedCount()
return
}
case QueryView:
diff --git a/bp2build/metrics.go b/bp2build/metrics.go
index 9e7b3b6..1cc4143 100644
--- a/bp2build/metrics.go
+++ b/bp2build/metrics.go
@@ -9,14 +9,17 @@
// Simple metrics struct to collect information about a Blueprint to BUILD
// conversion process.
type CodegenMetrics struct {
- // Total number of Soong/Blueprint modules
- TotalModuleCount int
+ // Total number of Soong modules converted to generated targets
+ generatedModuleCount int
+
+ // Total number of Soong modules converted to handcrafted targets
+ handCraftedModuleCount int
+
+ // Total number of unconverted Soong modules
+ unconvertedModuleCount int
// Counts of generated Bazel targets per Bazel rule class
- RuleClassCount map[string]int
-
- // Total number of handcrafted targets
- handCraftedTargetCount int
+ ruleClassCount map[string]int
moduleWithUnconvertedDepsMsgs []string
@@ -26,22 +29,49 @@
// Print the codegen metrics to stdout.
func (metrics *CodegenMetrics) Print() {
generatedTargetCount := 0
- for _, ruleClass := range android.SortedStringKeys(metrics.RuleClassCount) {
- count := metrics.RuleClassCount[ruleClass]
+ for _, ruleClass := range android.SortedStringKeys(metrics.ruleClassCount) {
+ count := metrics.ruleClassCount[ruleClass]
fmt.Printf("[bp2build] %s: %d targets\n", ruleClass, count)
generatedTargetCount += count
}
fmt.Printf(
"[bp2build] Generated %d total BUILD targets and included %d handcrafted BUILD targets from %d Android.bp modules.\n With %d modules with unconverted deps \n\t%s",
generatedTargetCount,
- metrics.handCraftedTargetCount,
- metrics.TotalModuleCount,
+ metrics.handCraftedModuleCount,
+ metrics.TotalModuleCount(),
len(metrics.moduleWithUnconvertedDepsMsgs),
strings.Join(metrics.moduleWithUnconvertedDepsMsgs, "\n\t"))
}
-func (metrics *CodegenMetrics) AddConvertedModule(moduleName string) {
+func (metrics *CodegenMetrics) IncrementRuleClassCount(ruleClass string) {
+ metrics.ruleClassCount[ruleClass] += 1
+}
+
+func (metrics *CodegenMetrics) IncrementUnconvertedCount() {
+ metrics.unconvertedModuleCount += 1
+}
+
+func (metrics *CodegenMetrics) TotalModuleCount() int {
+ return metrics.handCraftedModuleCount +
+ metrics.generatedModuleCount +
+ metrics.unconvertedModuleCount
+}
+
+type ConversionType int
+
+const (
+ Generated ConversionType = iota
+ Handcrafted
+)
+
+func (metrics *CodegenMetrics) AddConvertedModule(moduleName string, conversionType ConversionType) {
// Undo prebuilt_ module name prefix modifications
moduleName = android.RemoveOptionalPrebuiltPrefix(moduleName)
metrics.convertedModules = append(metrics.convertedModules, moduleName)
+
+ if conversionType == Handcrafted {
+ metrics.handCraftedModuleCount += 1
+ } else if conversionType == Generated {
+ metrics.generatedModuleCount += 1
+ }
}
diff --git a/cc/config/vndk.go b/cc/config/vndk.go
index 8c678a1..d4fcf7c 100644
--- a/cc/config/vndk.go
+++ b/cc/config/vndk.go
@@ -55,6 +55,8 @@
"android.hardware.power.stats-unstable-ndk_platform",
"android.hardware.radio-V1-ndk",
"android.hardware.radio-V1-ndk_platform",
+ "android.hardware.radio.config-V1-ndk",
+ "android.hardware.radio.config-V1-ndk_platform",
"android.hardware.rebootescrow-ndk_platform",
"android.hardware.security.keymint-V1-ndk",
"android.hardware.security.keymint-V1-ndk_platform",
diff --git a/cc/test.go b/cc/test.go
index 3934784..047a69e 100644
--- a/cc/test.go
+++ b/cc/test.go
@@ -357,7 +357,8 @@
}
func (test *testBinary) install(ctx ModuleContext, file android.Path) {
- testInstallBase := "/data/local/tests/unrestricted"
+ // TODO: (b/167308193) Switch to /data/local/tests/unrestricted as the default install base.
+ testInstallBase := "/data/local/tmp"
if ctx.inVendor() || ctx.useVndk() {
testInstallBase = "/data/local/tests/vendor"
}
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index fe567a9..be81487 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -24,6 +24,7 @@
"io/ioutil"
"os"
"os/exec"
+ "path"
"path/filepath"
"regexp"
"sort"
@@ -164,7 +165,8 @@
type Dependency struct {
XMLName xml.Name `xml:"dependency"`
- BpTarget string `xml:"-"`
+ BpTarget string `xml:"-"`
+ BazelTarget string `xml:"-"`
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
@@ -230,6 +232,14 @@
}
}
+func (p Pom) BazelTargetType() string {
+ if p.IsAar() {
+ return "android_library"
+ } else {
+ return "java_library"
+ }
+}
+
func (p Pom) ImportModuleType() string {
if p.IsAar() {
return "android_library_import"
@@ -240,6 +250,14 @@
}
}
+func (p Pom) BazelImportTargetType() string {
+ if p.IsAar() {
+ return "aar_import"
+ } else {
+ return "java_import"
+ }
+}
+
func (p Pom) ImportProperty() string {
if p.IsAar() {
return "aars"
@@ -248,6 +266,14 @@
}
}
+func (p Pom) BazelImportProperty() string {
+ if p.IsAar() {
+ return "aar"
+ } else {
+ return "jars"
+ }
+}
+
func (p Pom) BpName() string {
if p.BpTarget == "" {
p.BpTarget = rewriteNames.MavenToBp(p.GroupId, p.ArtifactId)
@@ -263,6 +289,14 @@
return p.BpDeps("aar", []string{"compile", "runtime"})
}
+func (p Pom) BazelJarDeps() []string {
+ return p.BazelDeps("jar", []string{"compile", "runtime"})
+}
+
+func (p Pom) BazelAarDeps() []string {
+ return p.BazelDeps("aar", []string{"compile", "runtime"})
+}
+
func (p Pom) BpExtraStaticLibs() []string {
return extraStaticLibs[p.BpName()]
}
@@ -289,6 +323,91 @@
return ret
}
+// BazelDeps obtains dependencies filtered by type and scope. The results of this
+// method are formatted as Bazel BUILD targets.
+func (p Pom) BazelDeps(typeExt string, scopes []string) []string {
+ var ret []string
+ for _, d := range p.Dependencies {
+ if d.Type != typeExt || !InList(d.Scope, scopes) {
+ continue
+ }
+ ret = append(ret, d.BazelTarget)
+ }
+ return ret
+}
+
+func PathModVars() (string, string, string) {
+ cmd := "/bin/bash"
+ androidTop := os.Getenv("ANDROID_BUILD_TOP")
+ envSetupSh := path.Join(androidTop, "build/envsetup.sh")
+ return cmd, androidTop, envSetupSh
+}
+
+func InitRefreshMod(poms []*Pom) error {
+ cmd, _, envSetupSh := PathModVars()
+ // refreshmod is expensive, so if pathmod is already working we can skip it.
+ _, err := exec.Command(cmd, "-c", ". "+envSetupSh+" && pathmod "+poms[0].BpName()).Output()
+ if exitErr, _ := err.(*exec.ExitError); exitErr != nil || err != nil {
+ _, err := exec.Command(cmd, "-c", ". "+envSetupSh+" && refreshmod").Output()
+ if exitErr, _ := err.(*exec.ExitError); exitErr != nil {
+ return fmt.Errorf("failed to run %s\n%s\ntry running lunch.", cmd, string(exitErr.Stderr))
+ } else if err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+func BazelifyExtraDeps(extraDeps ExtraDeps, modules map[string]*Pom) error {
+ for _, deps := range extraDeps {
+ for _, dep := range deps {
+ bazelName, err := BpNameToBazelTarget(dep, modules)
+ if err != nil {
+ return err
+ }
+ dep = bazelName
+ }
+
+ }
+ return nil
+}
+
+func (p *Pom) GetBazelDepNames(modules map[string]*Pom) error {
+ for _, d := range p.Dependencies {
+ bazelName, err := BpNameToBazelTarget(d.BpName(), modules)
+ if err != nil {
+ return err
+ }
+ d.BazelTarget = bazelName
+ }
+ return nil
+}
+
+func BpNameToBazelTarget(bpName string, modules map[string]*Pom) (string, error) {
+ cmd, androidTop, envSetupSh := PathModVars()
+
+ if _, ok := modules[bpName]; ok {
+ // We've seen the POM for this dependency, it will be local to the output BUILD file
+ return ":" + bpName, nil
+ } else {
+ // we don't have the POM for this artifact, find and use the fully qualified target name.
+ output, err := exec.Command(cmd, "-c", ". "+envSetupSh+" && pathmod "+bpName).Output()
+ if exitErr, _ := err.(*exec.ExitError); exitErr != nil {
+ return "", fmt.Errorf("failed to run %s %s\n%s", cmd, bpName, string(exitErr.Stderr))
+ } else if err != nil {
+ return "", err
+ }
+ relPath := ""
+ for _, line := range strings.Fields(string(output)) {
+ if strings.Contains(line, androidTop) {
+ relPath = strings.TrimPrefix(line, androidTop)
+ relPath = strings.TrimLeft(relPath, "/")
+ }
+ }
+ return "//" + relPath + ":" + bpName, nil
+ }
+}
+
func (p Pom) SdkVersion() string {
return sdkVersion
}
@@ -512,6 +631,75 @@
}
`))
+var bazelTemplate = template.Must(template.New("bp").Parse(`
+{{.BazelImportTargetType}} (
+ name = "{{.BpName}}",
+ {{.BazelImportProperty}}: {{- if not .IsAar}}[{{- end}}"{{.ArtifactFile}}"{{- if not .IsAar}}]{{- end}},
+ visibility = ["//visibility:public"],
+ {{- if .IsAar}}
+ deps = [
+ {{- range .BazelJarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BazelAarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraStaticLibs}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraLibs}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpOptionalUsesLibs}}
+ "{{.}}",
+ {{- end}}
+ ],
+ {{- end}}
+)
+`))
+
+var bazelDepsTemplate = template.Must(template.New("bp").Parse(`
+{{.BazelImportTargetType}} (
+ name = "{{.BpName}}",
+ {{.BazelImportProperty}} = {{- if not .IsAar}}[{{- end}}"{{.ArtifactFile}}"{{- if not .IsAar}}]{{- end}},
+ visibility = ["//visibility:public"],
+ deps = [
+ {{- range .BazelJarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BazelAarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraStaticLibs}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraLibs}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpOptionalUsesLibs}}
+ "{{.}}",
+ {{- end}}
+ ],
+ exports = [
+ {{- range .BazelJarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BazelAarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraStaticLibs}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraLibs}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpOptionalUsesLibs}}
+ "{{.}}",
+ {{- end}}
+ ],
+)
+`))
+
func parse(filename string) (*Pom, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
@@ -559,12 +747,14 @@
// Extract the old args from the file
line := scanner.Text()
- if strings.HasPrefix(line, "// pom2bp ") {
+ if strings.HasPrefix(line, "// pom2bp ") { // .bp file
line = strings.TrimPrefix(line, "// pom2bp ")
- } else if strings.HasPrefix(line, "// pom2mk ") {
+ } else if strings.HasPrefix(line, "// pom2mk ") { // .bp file converted from .mk file
line = strings.TrimPrefix(line, "// pom2mk ")
- } else if strings.HasPrefix(line, "# pom2mk ") {
+ } else if strings.HasPrefix(line, "# pom2mk ") { // .mk file
line = strings.TrimPrefix(line, "# pom2mk ")
+ } else if strings.HasPrefix(line, "# pom2bp ") { // Bazel BUILD file
+ line = strings.TrimPrefix(line, "# pom2bp ")
} else {
return fmt.Errorf("unexpected second line: %q", line)
}
@@ -650,6 +840,7 @@
}
var regen string
+ var pom2build bool
flag.Var(&excludes, "exclude", "Exclude module")
flag.Var(&extraStaticLibs, "extra-static-libs", "Extra static dependencies needed when depending on a module")
@@ -664,6 +855,7 @@
flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies")
flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules")
flag.StringVar(®en, "regen", "", "Rewrite specified file")
+ flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file")
flag.Parse()
if regen != "" {
@@ -758,6 +950,16 @@
os.Exit(1)
}
+ if pom2build {
+ if err := InitRefreshMod(poms); err != nil {
+ fmt.Fprintf(os.Stderr, "Error in refreshmod: %s", err)
+ os.Exit(1)
+ }
+ BazelifyExtraDeps(extraStaticLibs, modules)
+ BazelifyExtraDeps(extraLibs, modules)
+ BazelifyExtraDeps(optionalUsesLibs, modules)
+ }
+
for _, pom := range poms {
if pom.IsAar() {
err := pom.ExtractMinSdkVersion()
@@ -767,19 +969,32 @@
}
}
pom.FixDeps(modules)
+ if pom2build {
+ pom.GetBazelDepNames(modules)
+ }
}
buf := &bytes.Buffer{}
+ commentString := "//"
+ if pom2build {
+ commentString = "#"
+ }
+ fmt.Fprintln(buf, commentString, "Automatically generated with:")
+ fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " "))
- fmt.Fprintln(buf, "// Automatically generated with:")
- fmt.Fprintln(buf, "// pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " "))
+ depsTemplate := bpDepsTemplate
+ template := bpTemplate
+ if pom2build {
+ depsTemplate = bazelDepsTemplate
+ template = bazelTemplate
+ }
for _, pom := range poms {
var err error
if staticDeps {
- err = bpDepsTemplate.Execute(buf, pom)
+ err = depsTemplate.Execute(buf, pom)
} else {
- err = bpTemplate.Execute(buf, pom)
+ err = template.Execute(buf, pom)
}
if err != nil {
fmt.Fprintln(os.Stderr, "Error writing", pom.PomFile, pom.BpName(), err)
@@ -787,11 +1002,15 @@
}
}
- out, err := bpfix.Reformat(buf.String())
- if err != nil {
- fmt.Fprintln(os.Stderr, "Error formatting output", err)
- os.Exit(1)
+ if pom2build {
+ os.Stdout.WriteString(buf.String())
+ } else {
+ out, err := bpfix.Reformat(buf.String())
+ if err != nil {
+ fmt.Fprintln(os.Stderr, "Error formatting output", err)
+ os.Exit(1)
+ }
+ os.Stdout.WriteString(out)
}
- os.Stdout.WriteString(out)
}
diff --git a/cmd/soong_build/writedocs.go b/cmd/soong_build/writedocs.go
index 8d8f37f..d2fbed4 100644
--- a/cmd/soong_build/writedocs.go
+++ b/cmd/soong_build/writedocs.go
@@ -372,6 +372,7 @@
{{if .Properties -}}
<div class="accordion" id="{{getModule}}.{{.Name}}">
<span class="fixed">⊕</span><b>{{.Name}}</b>
+ <i>{{.Type}}</i>
{{- range .OtherNames -}}, {{.}}{{- end -}}
</div>
<div class="collapsible">
diff --git a/cuj/cuj.go b/cuj/cuj.go
index 7b04b7a..869e0f7 100644
--- a/cuj/cuj.go
+++ b/cuj/cuj.go
@@ -138,6 +138,8 @@
cujDir := filepath.Join(outDir, "cuj_tests")
+ wd, _ := os.Getwd()
+ os.Setenv("TOP", wd)
// Use a subdirectory for the out directory for the tests to keep them isolated.
os.Setenv("OUT_DIR", filepath.Join(cujDir, "out"))
diff --git a/java/hiddenapi_modular.go b/java/hiddenapi_modular.go
index 51cd501..1c6fbac 100644
--- a/java/hiddenapi_modular.go
+++ b/java/hiddenapi_modular.go
@@ -1194,13 +1194,6 @@
// deferReportingMissingBootDexJar returns true if a missing boot dex jar should not be reported by
// Soong but should instead only be reported in ninja if the file is actually built.
func deferReportingMissingBootDexJar(ctx android.ModuleContext, module android.Module) bool {
- // TODO(b/179354495): Remove this workaround when it is unnecessary.
- // Prebuilt modules like framework-wifi do not yet provide dex implementation jars. So,
- // create a fake one that will cause a build error only if it is used.
- if ctx.Config().AlwaysUsePrebuiltSdks() {
- return true
- }
-
// Any missing dependency should be allowed.
if ctx.Config().AllowMissingDependencies() {
return true
diff --git a/python/python.go b/python/python.go
index a35a1ac..f900172 100644
--- a/python/python.go
+++ b/python/python.go
@@ -45,7 +45,7 @@
type VersionProperties struct {
// whether the module is required to be built with this version.
// Defaults to true for Python 3, and false otherwise.
- Enabled *bool `android:"arch_variant"`
+ Enabled *bool
// list of source files specific to this Python version.
// Using the syntax ":module", srcs may reference the outputs of other modules that produce source files,
@@ -60,7 +60,7 @@
Libs []string `android:"arch_variant"`
// whether the binary is required to be built with embedded launcher for this version, defaults to false.
- Embedded_launcher *bool `android:"arch_variant"` // TODO(b/174041232): Remove this property
+ Embedded_launcher *bool // TODO(b/174041232): Remove this property
}
// properties that apply to all python modules
@@ -70,10 +70,10 @@
// eg. Pkg_path = "a/b/c"; Other packages can reference this module by using
// (from a.b.c import ...) statement.
// if left unspecified, all the source/data files path is unchanged within zip file.
- Pkg_path *string `android:"arch_variant"`
+ Pkg_path *string
// true, if the Python module is used internally, eg, Python std libs.
- Is_internal *bool `android:"arch_variant"`
+ Is_internal *bool
// list of source (.py) files compatible both with Python2 and Python3 used to compile the
// Python module.