Allowlist apexer for bp2build
This also introduces a workaround for the fact that apexer depends on aapt2, but aapt2 doesn't build with bp2build yet. Aapt2 is removed from apexer's requirements during bp2build. Bug: 204244290 Test: ./build/bazel/ci/bp2build.sh Change-Id: I837597ce035c7d5c06e1a3957166583a7a94b5c7
This commit is contained in:
@@ -38,6 +38,7 @@ type bazelPythonBinaryAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Deps bazel.LabelListAttribute
|
||||
Python_version *string
|
||||
Imports bazel.StringListAttribute
|
||||
}
|
||||
|
||||
func pythonBinaryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
@@ -75,6 +76,7 @@ func pythonBinaryBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
Srcs: baseAttrs.Srcs,
|
||||
Deps: baseAttrs.Deps,
|
||||
Python_version: python_version,
|
||||
Imports: baseAttrs.Imports,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
|
@@ -17,9 +17,6 @@ package python
|
||||
// This file contains the module types for building Python library.
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"android/soong/android"
|
||||
"android/soong/bazel"
|
||||
|
||||
@@ -72,40 +69,13 @@ func pythonLibBp2Build(ctx android.TopDownMutatorContext, m *Module) {
|
||||
// do nothing, since python_version defaults to PY2ANDPY3
|
||||
}
|
||||
|
||||
// Bazel normally requires `import path.from.top.of.tree` statements in
|
||||
// python code, but with soong you can directly import modules from libraries.
|
||||
// Add "imports" attributes to the bazel library so it matches soong's behavior.
|
||||
imports := "."
|
||||
if m.properties.Pkg_path != nil {
|
||||
// TODO(b/215119317) This is a hack to handle the fact that we don't convert
|
||||
// pkg_path properly right now. If the folder structure that contains this
|
||||
// Android.bp file matches pkg_path, we can set imports to an appropriate
|
||||
// number of ../..s to emulate moving the files under a pkg_path folder.
|
||||
pkg_path := filepath.Clean(*m.properties.Pkg_path)
|
||||
if strings.HasPrefix(pkg_path, "/") {
|
||||
ctx.ModuleErrorf("pkg_path cannot start with a /: %s", pkg_path)
|
||||
return
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(ctx.ModuleDir(), "/"+pkg_path) && ctx.ModuleDir() != pkg_path {
|
||||
ctx.ModuleErrorf("Currently, bp2build only supports pkg_paths that are the same as the folders the Android.bp file is in. pkg_path: %s, module directory: %s", pkg_path, ctx.ModuleDir())
|
||||
return
|
||||
}
|
||||
numFolders := strings.Count(pkg_path, "/") + 1
|
||||
dots := make([]string, numFolders)
|
||||
for i := 0; i < numFolders; i++ {
|
||||
dots[i] = ".."
|
||||
}
|
||||
imports = strings.Join(dots, "/")
|
||||
}
|
||||
|
||||
baseAttrs := m.makeArchVariantBaseAttributes(ctx)
|
||||
|
||||
attrs := &bazelPythonLibraryAttributes{
|
||||
Srcs: baseAttrs.Srcs,
|
||||
Deps: baseAttrs.Deps,
|
||||
Srcs_version: python_version,
|
||||
Imports: bazel.MakeStringListAttribute([]string{imports}),
|
||||
Imports: baseAttrs.Imports,
|
||||
}
|
||||
|
||||
props := bazel.BazelTargetModuleProperties{
|
||||
|
@@ -131,7 +131,8 @@ type baseAttributes struct {
|
||||
Srcs bazel.LabelListAttribute
|
||||
Deps bazel.LabelListAttribute
|
||||
// Combines Data and Java_data (invariant)
|
||||
Data bazel.LabelListAttribute
|
||||
Data bazel.LabelListAttribute
|
||||
Imports bazel.StringListAttribute
|
||||
}
|
||||
|
||||
// Used to store files of current module after expanding dependencies
|
||||
@@ -230,6 +231,33 @@ func (m *Module) makeArchVariantBaseAttributes(ctx android.TopDownMutatorContext
|
||||
|
||||
attrs.Deps.Add(bazel.MakeLabelAttribute(":" + pyProtoLibraryName))
|
||||
}
|
||||
|
||||
// Bazel normally requires `import path.from.top.of.tree` statements in
|
||||
// python code, but with soong you can directly import modules from libraries.
|
||||
// Add "imports" attributes to the bazel library so it matches soong's behavior.
|
||||
imports := "."
|
||||
if m.properties.Pkg_path != nil {
|
||||
// TODO(b/215119317) This is a hack to handle the fact that we don't convert
|
||||
// pkg_path properly right now. If the folder structure that contains this
|
||||
// Android.bp file matches pkg_path, we can set imports to an appropriate
|
||||
// number of ../..s to emulate moving the files under a pkg_path folder.
|
||||
pkg_path := filepath.Clean(*m.properties.Pkg_path)
|
||||
if strings.HasPrefix(pkg_path, "/") {
|
||||
ctx.ModuleErrorf("pkg_path cannot start with a /: %s", pkg_path)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(ctx.ModuleDir(), "/"+pkg_path) && ctx.ModuleDir() != pkg_path {
|
||||
ctx.ModuleErrorf("Currently, bp2build only supports pkg_paths that are the same as the folders the Android.bp file is in. pkg_path: %s, module directory: %s", pkg_path, ctx.ModuleDir())
|
||||
}
|
||||
numFolders := strings.Count(pkg_path, "/") + 1
|
||||
dots := make([]string, numFolders)
|
||||
for i := 0; i < numFolders; i++ {
|
||||
dots[i] = ".."
|
||||
}
|
||||
imports = strings.Join(dots, "/")
|
||||
}
|
||||
attrs.Imports = bazel.MakeStringListAttribute([]string{imports})
|
||||
|
||||
return attrs
|
||||
}
|
||||
|
||||
@@ -654,7 +682,8 @@ func (p *Module) createSrcsZip(ctx android.ModuleContext, pkgPath string) androi
|
||||
// in order to keep stable order of soong_zip params, we sort the keys here.
|
||||
roots := android.SortedStringKeys(relativeRootMap)
|
||||
|
||||
parArgs := []string{}
|
||||
// Use -symlinks=false so that the symlinks in the bazel output directory are followed
|
||||
parArgs := []string{"-symlinks=false"}
|
||||
if pkgPath != "" {
|
||||
// use package path as path prefix
|
||||
parArgs = append(parArgs, `-P `+pkgPath)
|
||||
|
Reference in New Issue
Block a user