Commit graph

85 commits

Author SHA1 Message Date
Chris Parsons
73f411b72c Delete ApiBp2build soong_build mode
This feature is obsolete.

This makes a large number of codepaths "dead code" (such as
module-specific implementations of ApiBp2build functionality). These
will be deleted in a followup CL.

Bug: 284029211
Test: Presubmits
Change-Id: Ib53b99f1fe8c24380d219caf44e9bb3b96724fa0
2023-09-05 17:09:51 -07:00
Liz Kammer
c86e094e13 Make ShouldConvertWithBp2build avail in loadhooks
Test: Soong go tests
Change-Id: I65af040152107ce50b1a97efcee9364f28bad08b
2023-08-14 11:03:05 -04:00
usta
da2a211bbd Use string.Builder
with 4000X clones of adbd, bp2build.Codegen time goes from 36s to 7s

Test: m bp2build and verify same BUILD.bazel files
Bug: 292281398
Change-Id: Ibd3b328a917fe5d1bdad67c67116da336f9033cb
2023-08-08 13:29:07 +00:00
usta
aaf2fd13e1 add bp2build subevents
Test: verified new events in bp2build_metrics.pb
Bug: 286412441
Change-Id: Ib803c3a3d1a8e7eaae5fb4c01c7769a72f4664ff
2023-08-04 16:47:41 -04:00
Treehugger Robot
687041c9e0 Merge "Add go modules to bp2build progress dashboard" into main 2023-08-02 12:02:19 +00:00
Spandan Das
41f1eeef91 Add go modules to bp2build progress dashboard
Since these modules have been converted, we should tag them as converted
in the dashboard.

Test: Put a print statement for `metrics` and made sure that the go
modules appear there
Bug: 294098662

Change-Id: I6282100111030a94f15f330916eaf41fcfc16e1a
2023-08-01 22:28:16 +00:00
Spandan Das
89aa0f71c9 Do not convert soong's tests in bp2build
These tests cannot be run with b since it uses functions that should not be
used outside tests, and it enforces this by looking at os.Args. Since
the pattern (`-test`) is missing in os.Args, these tests panic in b.

A module can be a dep of soong_build via two mechanisms
1. Listed in deps explicitly
2. Via plugin_for to create a reverse dep

This CL denylists (1) explicitly. e.g. soong-android. Another option
would have been to denylist by using Deps() of soong-build, but that
would denylist `golang-protobuf-proto` as well

This CL denylists (2) programmatically.

Note that this CL only denylists creation of the `go_test` target. We
will still create `go_binary` and `go_library` for soong since there
might be tools that depend on soong.
e.g.
```
--> depends on
dexpreot_gen --> soong-dexpreopt --> soong-android (test failure)
```

(The above example means that we might need to convert _some_ of soong
after all, but we can refactor the common bits to common utils. Keeping
this out of scope for now).

Test: b test //build/soong/... //system/tools/...
too)
Bug: 284483729

Change-Id: I809012bdd383febca30da95e991edfde5fd4d9b9
2023-07-27 17:11:51 +00:00
Spandan Das
682e78686b Create additional test target for go modules in bp2build
For go modules with non-empty testSrcs, we will create an additional
go_test target. To build a standalone test executable, we need to
include the source files in the compilation unit. This will be done
using the `embed` attribute
1. For tests of go_library, this is straightforward. It will embed the
   go_library and "inherit" its .go files and deps
2. For tetss of go_binary, we need to create an additional go_source
   target since go_binary cannot be embedded inside a go_test

Using `b test` for these tests revealed that certain tests are not
hermitic and rely on `testdata` files checked into the tree. This CL
introduces an allowlist to skip generating go_test targets for them.

Test: bp2build unit test
Test: TH
Bug: 284483729
Bug: 288491147
Change-Id: Ic736d655babc2f6067e4da75384900b7b8bdc2ed
2023-07-27 17:11:42 +00:00
Spandan Das
2a55cea4a0 Delete aliases to prebuilts
These tools will now be built from source using rules_go

Test: TH
Bug: 284483729
Change-Id: I6dde9f1418aaa516c4c6f8c8897dd20f4becfb51
2023-07-14 00:43:57 +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
Spandan Das
69afa98fbd Create a temporary denylist for go binaries used in mixed builds
This allows us to rollout building _some_ go targets using rules_go
without affecting mixed builds.

Test: Presubmit
Bug: 284483729
Change-Id: I0ccb4c9b90614369147a380f44f7ae372ef9396e
2023-07-13 00:22:26 +00:00
Spandan Das
de623294fe Partial bp2build conversion of blueprint_go_binary
This module type does not implement android.Module, and therefore we
cannot write a conventional bp2build converter for this module type.
Instead this has been special-cased inside bp2build/build_conversion.go.

There is one major deviation between Soong and Bazel's
go_binary/go_library. Soong
collects the deps in the transitve closure and puts them on compile/link
paths. Bazel OTOH, requires the direct imports to be listed in deps of the binary
explicitly (AFAIK). Since bp2build cannot determine the list of direct
imports from the list of transitive deps, put all the transitive deps in
`deps`

Test: unit tests
Test: TH
Bug: 284483729
Change-Id: I004aaf8607fef1697a0d9e7d018ad657b67778ac
2023-07-11 22:03:48 +00:00
Spandan Das
ea2abba3a9 Partial bp2build conversion of bootstratp_go_package
This module type does not implement android.Module, and therefore we
cannot write a conventional bp2build converter for this module type.
Instead this has been special-cased inside bp2build/build_conversion.go.

Because of the above, we also do not have access to useful functions
available in the ctx object of ConvertWithBp2build. This includes
1. Finding the package (directory) of a dep. This requires getting a
   handle of the underlying module from its name (string). To solve, we
   do a pre-visit to collect this information. This did not increase the
   wall time. On my machine, `m bp2build --skip-soong-tests` takes ~14s
   before and after this CL
2. Converting srcs to labels. This requires glob and package boundary
   resolution. This CL introduces a partial implementation for this
   function. (glob patterns are not used in go tools)

For (1), I considered creating a `ModuleFromName` on
`blueprint.Context` instead of a pre-run, but this increased the time to ~27s.

Test: unit tests
Test: TH
Bug: 284483729

Change-Id: Ifeb029103d14947352556dba295591dd7038b090
2023-07-11 22:03:26 +00:00
Chris Parsons
39a169721c Provide reason for unconverted bp2build modules
This also changes the expectation of ConvertWithBp2build. Each
implementation must either create one or more Bazel target modules, or
mark the module as unconvertible (with a specific reason).

Manually verified no runtime hit in AOSP
In AOSP, the metrics file size increases from 252K to 1.6M

This changes some effective module counts in bp2build metrics:
 - Removes "package" modules from the module count list in
metrics, as these will not be converted like regular modules.
 - Counts Handcrafted modules as being "unconverted", as bp2build is not
   responsible for them.

Bug: 285631638
Test: Verified generated BUILD.bazel files are bit-for-bit identical
with this change
Test: Manually verified one case of each implemented reasonType

Change-Id: I308dd451d8f28379b15671dae9f931bd0446f5c1
2023-06-16 13:45:17 +00:00
Spandan Das
6a448ec1a3 Add a function to create config_setting(s)
The use case for this is creating config_setting(s) specific to an apex
variant and selecting stub/impl in that config_setting. We likely need
only a handful of such config_setting(s), but determining that list
requires iterating the build graph.

Test: go test ./bp2build
Change-Id: I9aa552e3d0bcf67513023c3a7d4bbf8fae464ee4
2023-04-28 19:43:43 +00:00
MarkDacek
9c094ca153 Fix issue where bazel-force-enabled-modules aren't actually analyzed.
Bug: 273910287
Test: run mixed_mode_test.sh

Change-Id: I309c423b6e7f505ad1db0d9327e7de6b8298dfe9
2023-04-14 02:17:54 +00:00
Spandan Das
abedff0ca7 Add a method in bp2build to create aliases in another directory
The expected use case for this is to create aliases for stub libraries
in the @api_surfaces repository in build/bazel/api_surfaces.

This restricts the scope to just aliases. If we have a use case for
generating actual Bazel targets in another directory, a workaround could
be to generate the targets in the current directory (via
CreateBazelTargetModule) and aliases to it in the other directory

Test: go test ./bp2build
Change-Id: I6b63d9d018618d447fc7c260a2a94aaa00e57a4d
2023-03-08 21:40:26 +00:00
Cole Faust
18994c73f1 Replace SortedStringKeys with SortedKeys
Now that we have generics.

Bug: 193460475
Test: presubmits
Change-Id: I1594fd8feb505175d5c09c03ef397e5ffd5b09cb
2023-02-28 16:51:32 -08:00
Cole Faust
b85d1a15cc Bp2build support for multiple product configs
Create a
build/bazel/product_config/generated/products/<product_name>/BUILD
file that contains the platform definitions needed for
a particular product. Currently we just create it for the
current lunch target, but the idea is that eventually when
all product config is in starlark, all the products will
have their platform definitions in the tree at once.

Bug: 249685973
Test: Presubmits
Change-Id: I08c82ff28dcf62f09d3b1d2e3186a6b961e12f6e
2023-01-05 12:49:14 -08:00
Paul Duffin
c639059fd8 Make CodegenContext reference *android.Context
Previously, it stored an android.Context (no pointer) which while it
worked (because the current contents are themselves pointers) it is
inconsistent with how the rest of the code references it and could
cause weird behavior if additional fields were added to the Context.

Test: m nothing
      m bp2build
Change-Id: I9c70f925dde85e5b15431cc232b0c2eb6371ec6d
2022-11-05 17:43:12 +00:00
usta
4f5d2c1e97 include symlink metrics in bp2build_metrics.pb
Bug: b/256212479
Test: Prior to thi CL bp2build.symlink_forest event was missing in bp2build_metrics.pb after a clean mixed build
Change-Id: I53bfc4114a383c0d1f9c4c7945e7d4c69bc50b0c
2022-10-31 11:38:10 -04:00
Spandan Das
5af0bd3e48 Create a new mode in soong_ui to generate API only BUILD files
The generated Bazel workspace will only contain api specific targets.
This is feasible since these targets do not have any cross dependencies
with the targets in the bp2build workspace

The advantages of a new mode are
1. Does not pollute bp2build workspace with api targets
2. Does not block api targets with the current allowlist conversion
   mechansims in bp2build
(In the future we might want to combine these two workspaces)

A Soong module type will generate a Bazel target if it implements
ApiProvider interface

Test: m apigen
Test: m nothing

Change-Id: I69c57ca6539f932e0ad554ce84a87fb7936fdba0
2022-10-04 17:32:56 +00:00
Usta Shrestha
c6057154b8 cosmetic: switch instead of if-else
Bug: N/A
Test: m bp2build
Change-Id: Idf37af869f814a0a75957808f3f33200ff9800c0
2022-09-24 04:29:53 +00:00
Kevin Dagostino
60f562ac7e adding /out/soong_injection/metrics/converted_modules_path_map.json
This file can be used by atest/scripts/tools to determine which modules
have been converted and what their bazel build path is.

Test: b build //packages/modules/adb/...
will generate the file at /out/soong_injection/metrics/converted_modules_path_map.json
Also added a unit test to check that the file is created.

{
  "adbd": "//packages/modules/adb",
  "adbd_test": "//packages/modules/adb",
  "add_ext4_encrypt": "//external/e2fsprogs/contrib",
  ....
}

Change-Id: Ibd424c487840d84c8a4fb635828a73541220b36b
2022-09-20 04:01:13 +00:00
Sasha Smundak
8bea267caf Implement bp2build for the package module
* We are interested mostly in the conversion the `default_applicable_licenses`
  attribute, as `default_visibility` cannot be handled until every module's
  `visibility` is handled.
* Several referenced license modules had to be manually enabled for
  conversion, and likewise a few trivial Android.bp containing only
  package and license modules.
* As Bazel allows only a single `package` rule, the package rules in a
  manually converted BUILD.bazel files were removed (in
  external/protobuf and prebuilts/clang/host/linux-x86 trees).
* The converted package rule is emitted before the `load` statements per
  Bazel documentation.

Bug: 190817312
Test: treehugger
Change-Id: If8bf6fee1580177de3bb402923615bcd48923ed2
2022-09-14 13:49:27 -07:00
Sasha Smundak
fb58949414 Handle nameless modules during bp2build conversion.
So far it is `package` module.

Test: treehugger
Change-Id: Ibf3af0b0bf0a532e2ea1d478275a5ac3784ef170
2022-09-14 09:32:17 -07:00
Alix
94e2603ab7 refactoring build_conversion.go to remove panic
Returning errors throughout instead of calling panic()
Errors will be more useful for testing

Test: bp2build tests
Change-Id: I3b03f0a30e7a80878e91c7f0e2df5a94d9d6b780
2022-09-09 20:25:51 +00:00
Cole Faust
ea602c5a41 Remove old BUILD file merging code
It's not needed anymore since aosp/2197837,
it should've been removed in that cl but I forgot.

Bug: 234167862
Test: ./build/bazel/ci/bp2build.sh
Change-Id: I3d67a6e1894ad401525070ad37d3158708898306
2022-08-31 15:12:47 -07:00
Cole Faust
324a92e404 Always merge build files
Previous behavior:

- Packge not listed in bp2buildKeepExistingBuildFile:
    - Use bp2build generated build file
- Package listed in bp2buildKeepExistingBuildFile:
    - Use handcrafted build file even if there were allowlisted bp2build
      modules in the same package.
- Package listed in bp2buildKeepExistingBuildFile and a soong module has
  a bp2build: { label } attribute:
    - Merge the handcrafted and bp2build generated build files

New behavior:

- Packge not listed in bp2buildKeepExistingBuildFile:
    - Use bp2build generated build file
- Package listed in bp2buildKeepExistingBuildFile:
    - Merge with bp2build generated build file.

Bug: 234167862
Test: ./build/bazel/ci/bp2build.sh
Change-Id: Ifbaf4f8f0f5158b5b2bd6d534eb2311e2e5f399b
2022-08-30 16:07:23 -07:00
Sasha Smundak
f2bb26f492 Show module's type and path when reporting dependency problems
Test: treehugger
Change-Id: I25c3eddbeeb10bd6b9bfa9e869f6fbc98d2a6ec4
2022-08-04 14:49:25 -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
Sam Delmerico
932c01cf9e export Java variables to Bazel
Test: build/bazel/bp2build.sh
Change-Id: Ia06f9265c9f96e6add6edbd0cee925fe37b430d3
2022-04-08 14:15:43 +00:00
Liz Kammer
72beb34609 Add package for printing starlark formatted data
Bug: 216168792
Test: build/bazel/ci/bp2build.sh
Change-Id: I3a06b19396f7ffe1c638042cda7e731dd840f1d6
2022-02-08 17:32:28 -05:00
Chris Parsons
492bd91a51 Add bp2build metrics per module type
For example, new metrics at HEAD highlight that 99 of 1379 total
cc_library_static modules are converted.

Test: m bp2build, printproto
Change-Id: I6cc4227124e9a130b75911f3e40e6585d731d00a
2022-01-21 11:52:24 -05: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
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
947fdbfdee Log bp2build_metrics .pb
Also share `Save(pb proto.Message, filepath string)`

Bug: 201539536
Test: bp2build_metrics.pb has expected content & path
Test: m nothing
Test: {bp2build,mixed_{libc,droid}}.sh
Test: CI
Change-Id: I7d8ad87fca6a4b0355010090a527f5ae67b27c88
2021-12-13 13:03:44 -05:00
Liz Kammer
46fb7aba4d Support empty strings in bp2build
Previously, could not set an empty string as a value of an attribute;
however, this is necessary in some cases. To not unnecessarily create an
empty string, use string pointers for attributes rather than strings.

Test: go test bp2build tests
Change-Id: I03b3a3567452d455246d22d81f86c317d06b7c39
2021-12-01 10:14:49 -05:00
Jingwen Chen
58ff6801f4 Fix bp2build select generation for inter-attribute soong config
variable usage.

There's bug a in the current soong_config_variable handling
implementation where a soong_config_variable sets conditions_default
value for an attr, and a non-conditions_default value for another attr.
This results in the former attr not properly setting the zero value for
the non-conditions_default select key, resulting in the pretty printer
omitting the attribute totally.

The current implementation in this CL ensures that the zero value is set
whenever this happens at the module level. This is seen in
library_linking_strategy_cc_defaults (see comments in code, and the new
tests)

Test: CI
Bug: 198556411

Change-Id: Ibaeb94508c51a7429fb7a08df610cbb5470f76d2
2021-11-23 08:37:30 +00:00
Liz Kammer
0eae52e0de bp2build; Update handling of linker flags
Test: build/bazel/ci/bp2build.sh
Bug: 197920036
Change-Id: I6e3100574fa0e40bcd8cf0e6af0efd3310aa41bf
2021-10-07 16:07:40 -04:00
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
447f6c99c9 Bp2Build common properties auto-handling
Introduce `commonAttributes` & `fillCommonBp2BuildModuleAttrs used in
CreateBazelTargetModule

Adapt `bp2BuildInfo` to use `commonAttrs` instead of `Name`.
And thus also all downstream users of `CreateBazelTargetModule`.

As initial user, the Soong `required` property will be
translated to Bazel's `data`.

Bug: 198146582, 196091467
Test: build_converstion_test.go:TestCommonBp2BuildModuleAttrs
Test: go test
Test: mixed_{libc,droid}.sh
Change-Id: Ib500e40f7e2cb48c459f1ebe3188962fc41ec124
2021-10-04 14:43:04 +00:00
Liz Kammer
7a210ac233 bp2build: Add support for export_.*headers props
Soong supports export_.*_headers properties, the libraries contained in
this list must also be within a shared/static/whole_static/header libs
property. For bp2build, we eliminate this duplication. The libraries
not listed in an export_.*_headers property will migrate to an attribute
prepended with implementation_, those in export_.*_headers will not have
a prefix.

Test: build/bazel/ci/bp2build.sh
Test: build/bazel/ci/mixed_libc.sh
Bug: 198241472
Change-Id: I3eb84c983ec5d241c8a568e411dfd5619d3184a7
2021-09-23 16:07:45 -04:00
Jingwen Chen
310bc8f5f4 bp2build: Refactor metrics collection to use exported functions.
This CL splits the metric count into handcrafted, generated, and
unconverted modules.

Test: CI
Test: m bp2build, the metrics reported are identical.
Change-Id: I80e3d2fd2989222bd40b6433b4a1924b4943d0ba
2021-09-20 11:54:00 +00:00
Jingwen Chen
afb84bd78f Fix bp2build-progress generating an empty converted_modules list, and
duplicate module names.

We were using the value receiver on AddConvertedModule before, which
didn't actually mutate the internal slice state.

Test: Run bp2build-progress.py
Change-Id: Ic60f8f6214a91dc129abf62c57dd0b85efffb283
2021-09-20 10:31:46 +00:00
Jingwen Chen
6117450ead bp2build: add converted modules to codegen metrics, and remove the
compat layer.

The list of converted modules is used for tracking bp2build progress.

The module_name_to_label aliases weren't really adding much value to
mixed builds, so let's drop the feature for now and simplify the code.

Test: CI
Test: USE_BAZEL_ANALYSIS=1 m droid
Change-Id: I3269344cfe6d1c72c108d66c6e820bc0ec19bb34
2021-09-17 08:47:16 +00:00
Jingwen Chen
16d90a8954 Remove __bp2build__ prefix trimming.
This is no longer needed after r.android.com/1792714

Test: CI
Change-Id: I808c3124cf1a4f3ebe5d25e41f346a818c3cc57c
2021-09-17 07:16:59 +00:00
Liz Kammer
83d07a4c41 Merge "Expand handling of unconverted deps in bp2build" 2021-09-15 13:49:48 +00: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
Liz Kammer
32a0339340 Bp2build: handle embedded structs as blueprint
For structs that are embedded, Blueprint does not nest under the
embedded name, flattening them into the original struct for blueprint
files (e.g.
9fd2ed93df:proptools/unpack_test.go;l=402-431;drc=3adb2409648d6f8b25354ac47f083dae87731f10).
We should do the same for bp2build.

This will also allow us to embed structs for bp2build conversion
allowing more reuse.

Test: go test bp2build tests
Change-Id: I9ce088462adaf59bffa80bea76cd488e31f98e9d
2021-09-14 14:41:36 -04:00
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
0da7ce6f39 Document testing & build_conversion purposes
Formatter also relocated some imports

Test: Existing tests pass
Change-Id: I48b1cb65400e463a6b4e91fd9fe76e13d8d81cd6
2021-08-23 22:04:53 +00:00
Liz Kammer
2ada09a546 Don't create a new module for bp2build conversion.
A performance improvement for bp2build as Blueprint/Soong no longer have
the overhead of additional modules. The creation of these modules
results in:
* traversal of additional modules for each subsequent mutator
* synchronization over a go channel to collect newly created modules:
https://cs.android.com/android/platform/superproject/+/master:build/blueprint/context.go;l=2594,2600;drc=1602226f23181b8c3fbfcaf3358f0297e839d7d3

We avoid both of these by storing the information directly in the
underlying module.

Also as a fringe benefit, removes some necessary boilerplate for
conversion.

For benchmarks, reduces runtime ~1% for 1% converted, ~24% for 100%
converted. See more: go/benchmarks-for-https:-r.android.com-1792714

Test: ran benchmarks/tests in bp2build
Test: build/bazel/ci/bp2build.sh
Change-Id: Ie9273b8cbab5bc6edac1728067ce184382feb211
2021-08-17 15:57:09 -04:00