Commit graph

55 commits

Author SHA1 Message Date
Christopher Parsons
9eb4efa094 Merge "Skip certain problematic deps" into main 2023-10-05 20:27:00 +00:00
Chris Parsons
44215bc31d Skip certain problematic deps
These are hacks to unblock allowlist v2. See attached bugs.

Bug: 303307672
Bug: 303310285
Test: Manually tested to unblock `m nothing` with allowlist v2 on AOSP
Change-Id: I076a96134118106b44e105db98617ffb9f33bca5
2023-10-05 17:54:34 +00:00
Jingwen Chen
3e582b8175 Use parameter name hint for BazelLabelModuleDepsWithFn's markAsDeps.
Test: presubmits
Change-Id: I6015581c27ad8b9b5b81d0ed01ba219699b9630b
2023-10-05 10:03:06 +00:00
Christopher Parsons
29c559b785 Merge "create, but dont register, bp2build_deps mutator" into main 2023-10-04 21:38:49 +00:00
Spandan Das
29af2a470d Merge "Handle symlinks in isPackageBoundary" into main 2023-10-03 17:51:41 +00:00
Chris Parsons
5f1b3c7ad8 create, but dont register, bp2build_deps mutator
This is the bulk of the "allowlist v2" feature. It will disable bp2build
generation for modules which have transitive dependencies without a
bazel build definition.

This CL includes this mutator, but doesn't register it as a bp2build
mutator (outside of a few unit tests). This allows us to easily iterate
on completion of this feature and ensure there are no launch blockers
before we finalize the change in AOSP.

Bug: 285631638
Test: Unit tests
Change-Id: Ifb0a079c409ca19b02cafa3fab2efa0d3deebc50
2023-10-03 00:16:30 +00:00
Yu Liu
f2b94010c8 Convert java_aconfig_library to bazel.
Bug: 297357579
Test: Unit test and AconfigJavaHostTest
Change-Id: Icf944cc0b2a7382107923d49b2d2ff0eb4113638
2023-10-02 15:04:19 -07:00
Spandan Das
dc7d7f7557 Handle symlinks in isPackageBoundary
isPackageBoundary looks at ShouldKeepExistingFile before checking if
that directory contains a BUILD file or not. ShouldKeepExistingFile
should be complemented with a isSymlink check. This is necessary because
we copy all symlinks to the synthetic workspace, and the resolved
symlink might point to a directory containing a BUILD file.

This additional clause is redundant if the directory has been
allowlisted for keepExistingBuildFile (e.g. build/bazel, recursive)

Test: b build //bionic/libc:versioner-dependencies (top of stack)

Change-Id: I5b23262f89ea34a78de4ccade6d27e4c5dd95c2e
2023-09-29 21:04:30 +00:00
Romain Jobredeaux
9c06ef353b bp2build support for framework-res
Change-Id: I5b32a702e02b5f1ec08d5608d766a8a0c08d845c
Bug: 276928228
Bug: 297356405
2023-09-26 15:06:50 -04:00
Liz Kammer
af7c166f10 Merge "Handle prebuilt vs source selection in bp2build" into main 2023-09-21 12:15:54 +00:00
Chris Parsons
637458d326 Have ConvertWBp2build use Bp2buildMutatorContext
This no-op refactoring facilitates some upcoming functional changes for
"bp2build allowlist v2". The work requires that the bp2build conversion
mutator be changed from a TopDown mutator to a BottomUp mutator.
Refactoring all bp2build-related methods so that they use Bp2buildMutatorContext
makes it easier to make this functional change without touching tens of
files and multiple projects.

Bug: 285631638
Test: m bp2build
Change-Id: I3d1ef3064146e959c6f0dc315350fc9764bf2bd2
2023-09-20 14:49:35 +00:00
Liz Kammer
e1b39a5286 Handle prebuilt vs source selection in bp2build
Test: enable mainline modules build from prebuilts and build
Bug: 300640274
Change-Id: Ib1d6bbca7e0ab459515d3cf6378741e8368e7327
2023-09-19 16:04:39 -04:00
Treehugger Robot
4f11fee841 Merge "Add a function to find src labels in a specific directory" into main 2023-08-18 20:52:17 +00:00
Spandan Das
f62e80a127 Fix replacements of namespace module srcs in genrule
expandSrcsForBazel always prefixed : in OriginalModuleName. The
exceptions to this are filegroups that appear in a different soong
namespace. For these cases, we were not correctly substituting the soong
module name with the equivalent bazel label.

Test: go test ./bp2build
Change-Id: If090f3f8819835177c1f4d191b3eef6bb6e30ace
2023-08-17 22:50:07 +00:00
Spandan Das
03010664c8 Add a function to find src labels in a specific directory
The existing api restricts search to the directory of the currently
visited soong module. Create a new function that allows search in any
directory. Internally it calls TransformSubpackagePath so the returned
labels will be resolved to respect package boundaries.

The use case for this is to support proto.include_dirs of cc_*, java_*,
python_*

Test: Added a unit test that uses a mock for GlobWihDeps

Change-Id: I75fe3ca7de88b163f456190049a22c62f91c9a2e
2023-08-16 01:15:48 +00:00
Liz Kammer
c86e094e13 Make ShouldConvertWithBp2build avail in loadhooks
Test: Soong go tests
Change-Id: I65af040152107ce50b1a97efcee9364f28bad08b
2023-08-14 11:03:05 -04:00
Spandan Das
fac9d8e71d Merge "Special-case go modules in convertedToBazel" into main 2023-08-03 16:45:49 +00:00
Spandan Das
6485242321 Special-case go modules in convertedToBazel
This function is called in getOtherModuleLabel, and is used to mark the
otherModule as an unconvertedDep. This meant that if a soong module `A`
depends on soong_zip, it would add soong_zip as unconverted dep of `A`.
All go modules have been converted in bp2build, so this CL special
cases go_package and go_binary in this function.

Bug: 294098662
Test: printf metrics in build_conversion.go# GenerateBazelTargets, and
made sure that the string "has unconverted.*soong_zip" does not appear

Change-Id: I8d1d0876c581f9b2eb72dafcb3a28bd5577bbb4c
2023-08-02 22:11:37 +00:00
Cole Faust
5c84c62733 Unique modules in BazelLabelForModuleDepsWithFn
This fixes the current bp2build failure.

Test: Presubmits
Change-Id: I0b141374ebdbee80aa296d9c9a577b125e5703d7
2023-08-01 11:07:02 -07:00
Spandan Das
950091ce29 Fix typo in mutator name
Change-Id: I1aa249e0c2095afb3bdd6eb9f1da62f75607b261
Test: N/A
2023-07-19 22:26:37 +00:00
Spandan Das
0a8a27500e Respect package boundaries in bp2build conversion of go modules
bp2build's codegen context does not implement
BazelPathConversionContext. To reuse the utility function
transformPackagePaths, update its signature

(Also make deps of go_library unique to make the conversion resilient)

Test: go test ./bp2build
Change-Id: I126b1057d2b26bc6c7d3be2780f1b62d28323cf0
2023-07-13 00:22:26 +00:00
Liz Kammer
1e75324ebd Correct genrule path references
Test: b build `bmod robolectric_tzdata`
Test: go test bp2build tests
Change-Id: I98333f2b9f480019ddca11944b455d484a47cf8e
2023-06-02 19:09:35 -04:00
Liz Kammer
20f0f780df Correct allowlisting for override modules
Prevoiusly, we were partially correcting for override modules in
bp2build/mixed builds in some but not all places. Now we always check
for override modules and ensure that Bazel_module properties are
propagated properly for override modules.

Bug: 279609939
Test: go test soong tests
Change-Id: I5445aa71f4c8013315415a2ca9ab9c6b3be6bce0
2023-05-02 09:27:55 -04:00
Jingwen Chen
29743c8423 Read ApexMkInfo for modules to be installed.
This piggybacks onto the ApexInfo cquery handler, so we're issuing a
single bazel query call that reads two providers in the starlark expr.

Also rename requiredDeps to makeModulesToInstall to differentiate it from
APEX's required/provided libs in the apex manifest.

Test: unit test
Test: mkdiff
Fixes: 263123189
Change-Id: Ib7e43f1586f29864eee8627dba3631bfaff27afa
2023-01-27 04:02:45 +00:00
Cole Faust
0abd4b4f5d Optimize PathForBazelOutRelative
This isn't benchmarked or anything, but should give
minor performance improvements.

Test: Verified ninja files didn't change on aosp_arm64-userdebug
Change-Id: I030991f91c326669b7b7e73b8171da4b2a68cbb4
2023-01-10 11:38:40 -08:00
Jingwen Chen
889f2f2844 mixed builds: Make apex's GetBazelLabel return the label of the override_apex, if applicable.
And add test1_com.android.tzdata to prod allowlist.

Fixes: 261054570
Bug: 261054570
Test: mkcompare
Change-Id: I314a4e44ade958ba9a91f71430d76175d734579e
2022-12-20 07:35:20 +00:00
Vinh Tran
b6803a5f52 Add ApexInfo.RequiresLibs to mixed build handler for apex
Adding ApexInfo.RequiresLibs from Bazel to apexBundle.requiredDeps which is eventuallyread by apex androidmk writer for LOCAL_REQUIRED_MODULES to ensures the libs are installed as part of a bundle build.

In Soong, apexBundle.requiredDeps is set in
https://cs.android.com/android/platform/build/soong/+/master:apex/apex.go;l=2305-2323;drc=cb7e73bc0130a95f5991c925c349387185abc098

The same logic is replicated in Bazel at
https://cs.android.com/android/platform/build/bazel/+/master:rules/apex/cc.bzl;l=141-163;drc=cb7e73bc0130a95f5991c925c349387185abc098.

This CL is porting the required libs set by Bazel in mixed build.

Test: go test
Test: run build/bazel/ci/mixed_libc.sh
Bug: 215500321
Change-Id: Id7256d279ac09a8fd42db391a7e93ce0021d8345
2022-12-14 18:54:47 -05:00
Jingwen Chen
6817bbb3c8 Introduce BazelStringOrLabelFromProp.
Soong supports string properties, but they are overloaded, and can mean
one of three things:

* path reference
* module reference
* string literal

Bazel has different types: label and string attributes. Thus there needs
to be a way to categorize them correctly in bp2build.

This CL introduces a new function to be used on properties like
apex_key.private_key / apex_key.public_key, as well as
android_app.certificate / apex.certificate.

It is important to disambiguate the prop betenn a string literal
attribute or file/rule target label attribute, so this functions does
just that.  The new attributes are then further handled by their
respective macros (apex_key, android_binary, apex).

Bug: 253557437
Fixes: 253557437
Test: presubmits, new tests

Change-Id: Id8111cdd60d3aabcae7d17fe9da84d0ee3966023
2022-10-20 14:57:37 +00:00
Usta Shrestha
d558031e0c File paths to allow "./" prefix
bazel_path conversion would treat "./" as a package boundary
  which would be incorrect

Bug: b/243072036
Test: unit test build_conversion_test.go and `m libc`
Change-Id: I0fc44d2fd7a4270442c8755219a11fd585244c5c
2022-09-26 14:44:15 -04:00
Jingwen Chen
0eeaeb8ef7 Fix package boundary in glob expansion with checked in BUILD files.
For directories without an Android.bp file, if they contain a merged
checked in BUILD file, it becomes a package boundary in the symlink
forest. However, the current glob expansion is only aware of Android.bp
files, but not merged BUILD files, so it generates glob expansions
incorrectly for files that cross the package boundary.

This CL fixes that by making the package boundary function aware of the
keepExistingBuildFile allowlist. See the new test cases for example.

Also stop using the same global bp2buildConfig for every test case to
allow each test to define their own bp2build allowlists.

Bug: 185358476
Test: new unit tests

Change-Id: Ifcd1283480a09a642ef4343e5bbc599583524577
2022-09-22 23:22:49 +00:00
Colin Cross
d079e0b270 Reformat build/soong for go 1.19
Test: none
Change-Id: I132368f0fcbdb5ea088b5b84dbe4ccfdd9e94cad
2022-08-17 10:43:13 -07:00
Usta Shrestha
db46a9bbb8 Cosmetic Changes plus log errors
Test: N/A
Bug: N/A
Change-Id: I39e622a93270c922bdbea27ca79632a606431a2c
2022-08-02 20:24:57 +00:00
Cole Faust
9a06d25be2 Make filegroup paths relative to module dir in mixed builds
filegroup.srcs must have a .rel() version of their paths
that is relative to the module directory. Previously in
mixed builds, the relative path wasn't filled in.

Bug: 229251008
Bug: 204244290
Test: go tests, and USE_BAZEL_ANALYSIS=1 m apexer with the following cl
Change-Id: I11a2a8b96139e0e7b956fa4c256a9a99c02f88f3
2022-06-08 11:47:24 -07:00
Sam Delmerico
24c5603815 refactor bp2build module allowlists into struct
To make testing easier, refactor existing module-global variables into a
struct that can be mocked.

Test: build/bazel/bp2build.go
Change-Id: I9d177677644ea743641a745b1839a3a8b29f902a
2022-04-14 13:31:05 +00:00
Liz Kammer
daa09efb5e Start unblocking com.android.runtime deps
Adds support to warn rather than error about missing deps in order to
suport modules in build/soong with deps outside of build/sooong in
bp2build integration tests.

Test: build/bazel/ci/bp2build.sh
Change-Id: I1282bccd37a3fc9f33555d34e68d7f0873d8272c
2022-01-06 10:40:43 -05:00
Romain Jobredeaux
1282c42484 Initial bp2build converter for android_app.
The only supported attributes at this point are:
- srcs
- manifest
- package_name
- resource_dirs
as they most easily map to bazel's android_binary's srcs, manifest, custom_package, and resource_files respectively.
Allow-listing all apps that use these fields, along with sdk_version and dex_preopt. The latter 2 are ignored by the converter,
- sdk_version because we're currently relying on a single pre-built SDK,
- dex_preopt because,
   1. though it is not supported in Bazel builds yet, it doesn't prevent the apps from building, and
   2. the apps being converted only use the dex_preopt attribute to disable dex_preopt, which is what is happening anyway.

Change-Id: I4a4f771eeb8f60a1cd4844b2ac1ce3df7c070e73
Test: ./build/bazel/scripts/run_presubmits.sh
Bug: 198224074
Bug: 203688791
2021-12-07 09:41:49 -05:00
Jingwen Chen
55bc820d66 bp2build: split Bazel conversion context into smaller ones,
and change TopDownMutatorContext signatures to use Bazel conversion context.

This minimizes the context interfaces/functions actually needed to
convert a module, and makes such interfaces easier to mock/test.

Test: CI
Change-Id: Id573d97023d59e06ef70e1f54437024d3f7aadbd
2021-11-02 06:51:27 +00:00
Jingwen Chen
80b6b64db5 Add an error check in bazelPackage for malformed labels.
Bug: 204281595
Test: CI
Change-Id: Ia94a0b5c8dd3a0294475e9bc816a19ae03f7342d
2021-11-02 06:24:31 +00:00
Liz Kammer
0f3b7d2fc4 Add deps of protos to bp2build.
Update BazelOutPath to implement genPathProvider. This allows Bazel
outputs (incl filegroup) to be used as an input to generating a file
(e.g. proto).

Test: bp2build.sh
Test: mixed_build.sh
Bug: 200601772
Change-Id: I5ad67ade193025652100b214996b26ce9ca9bf83
2021-09-29 10:31:27 -04:00
Chris Parsons
953b35623a bp2build: reference static variants directly
Previously, when referencing a cc_library as a static_lib from a
converted module, the corresponding target would depend on the "root
target" of that cc_library. This resulted in a superfluous dependency on
the shared target of the cc_library dependency. This superfluous
dependency could sometimes result in cycles.

This change ensures the static target name is directly specified in such
cases.

Test: mixed_libc.sh CI
Test: USE_BAZEL_ANALYSIS=1 m fmtlib
Change-Id: I36ee9f0a9017b1e9d73df9e3174669107f0afd4f
2021-09-20 15:15:29 -04:00
Liz Kammer
6eff323206 Expand handling of unconverted deps in bp2build
Support three options for converting modules with unconverted
dependencies
1. (default) Warn when converting a module if it has unconverted deps.
2. Error when encountering a module with unconverted deps. (not hooked
up yet)

Test: build/bazel/ci/bp2build.sh
Test: build/bazel/ci/mixed_libc.sh
Test: BP2BUILD_ERROR_UNCONVERTED=1 build/bazel/ci/bp2build.sh with
      unconverted deps -- get appropriate error
Bug: 181155349
Change-Id: Ifaabf0cd2e43e963366dc137159c705294165c3d
2021-09-14 19:55:55 +00:00
Lukacs T. Berki
9f6c24a887 Rename BuildDir and NinjaBuildDir.
These are just out/ and out/soong/ and the old names were quite
confusing.

Test: Presubmits.
Merged-In: I999ca62162062f27e449f83ffb00fa580d4065b8
Merged-In: I2fcd80a9e376a6842a06aa104a9f6f5c5e16f8c7
Change-Id: Ib481d2aac40df8da1b74174dc8ec576c1cb48be0
2021-08-27 10:08:49 +02:00
Christopher Parsons
67d6ccecfc Merge "bp2build: handle system_shared_libs" 2021-08-09 19:11:00 +00:00
Chris Parsons
51f8c39261 bp2build: handle system_shared_libs
- If no system_shared_libs is specified, bp2build writes no attribute
value. In this case, the bazel library macros determine the correct
default behavior.
- If any system_shared_libs is specified for any variant, then bp2build
writes the value verbatim. This includes if an empty list is specified,
as this should override defaulting behavior.

Note this defaulting behavior is incomplete and will be incorrect in
corner cases. For example, if, in an Android.bp, system_shared_libs is
specified for os.linux_bionic but not for os.android, then the bazel
default for os.android will be incorrect. However, there are no current
modules in AOSP which fit this case.

As a related fix, supports static struct for cc_library_static.

Also, removes some elements from the bp2build denylist.

Test: mixed_droid CI
Change-Id: Iee5feeaaf05e8e7209c7a90c913173832ad7bf91
2021-08-09 11:41:09 -04:00
Rupert Shuttleworth
6e4950a061 Add some more properties to the bp2build APEX converter (second try)
In particular:

- AndroidManifest
- file_contexts
- key
- certificate
- min_sdk_version
- updatable
- installable
- native_shared_libs
- binaries

Test: Updated unit test

Change-Id: I1c6e8c4b6b24ce487f64e5d37bd594dbb000fe6f
2021-07-27 05:02:50 -04:00
Rupert Shuttleworth
0358478150 Revert "Add some more properties to the bp2build APEX converter."
This reverts commit 69bf4c0d60.

Reason for revert: Possibly broke CI (https://android-build.googleplex.com/builds/quarterdeck?branch=aosp-master-bazel&target=bp2build-incremental&lkgb=7266256&fkbb=7237028), rolling back just in case...

Change-Id: I14ebac4f47576a73285d1f724ae4499036e8e678
2021-07-27 02:37:32 +00:00
Rupert Shuttleworth
69bf4c0d60 Add some more properties to the bp2build APEX converter.
In particular:

- AndroidManifest
- file_contexts
- key
- certificate
- min_sdk_version
- updatable
- installable
- native_shared_libs
- binaries

Test: Updated unit test

Change-Id: I9ea13f021d63ec0f75006b3b0b23ec8178c7e9da
2021-07-26 07:32:36 -04:00
Chris Parsons
5a34ffb350 Remove bp2build deps mutator
Refactor bp2build to retrieve modules directly by name, instead of via
DirectDeps. This functions properly as bp2build has no need for variant
information of the blueprint graph.

Test: USE_BAZEL_ANALYSIS=1 m fmtlib
Change-Id: Ief4b67bc56f24929871af772f3a742f07085bf8c
2021-07-22 18:09:34 -04:00
Liz Kammer
2d7bbe3883 Append _alwayslink to prebuilt whole static deps
This allows us to support prebuilt archives that are part of whole
static deps.

Test: build/bazel/ci/bp2build.sh
Bug: 190716727

Change-Id: I913dbd8f85a1974fbd53c0cbaa49211db18ea45f
2021-06-11 08:10:50 -04:00
Liz Kammer
47535c51fa Handle excludes_{shared,static}_libs
Bug: 188497994
Test: bp2build.sh
Change-Id: I4a5ea40cbd804e8542fe33143e4926abc0c6164f
2021-06-04 10:15:36 -04:00