Commit graph

503 commits

Author SHA1 Message Date
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
Lukács T. Berki
72ab470a29 Merge "Multithread symlink forest removal." 2022-11-02 07:45:22 +00:00
Usta (Tsering) Shrestha
3bb3763afd Merge "include symlink metrics in bp2build_metrics.pb" 2022-10-31 20:00:36 +00:00
Lukacs T. Berki
bc5f731791 Multithread symlink forest removal.
This is a second attempt at aosp/2273288 which got rolled back because
it turned out that:

1. We make ~120K symlinks in AOSP (!), all of which need to be deleted
2. System calls are sometimes slow
3. Golang spawns a new OS-level thread for each blocking system calls to
   keep cores busy

All this together means that we sometimes had 10K system calls in
flight, which meant 10K OS-level threads, which is when Go gives up and
says "I created too many threads, please help".

The fix is to move the system calls into a pool of goroutines, which
soon end up on a pool of threads (since they mostly do blocking system
calls)

Test: Presubmits.
Change-Id: Ia9aefff3b0ed373f09bb6c8b2ec1d8b0f00b213b
2022-10-31 16:04:13 +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
Alix
b4e09a0ada Bp2build Java libs for java_binary -> java_import edge
Since Bazel's java_import requires a jars attribute to be specified,
the generated neverlink-duplicated module is of type java_library

Change-Id: I14a866dfc583507a9462add50d95060cbfe540c5
Bug: 244210934
Test: m bp2build, go test ./bp2build, manual inspection of generated Build and jar files
2022-10-28 20:26:38 +00:00
Christopher Parsons
ed2873aea0 Revert "Multithread symlink forest removal."
This reverts commit 6b236f1607.

Reason for revert: Breaks ab/aosp-master-bazel incremental builds. Details on b/254338319

Change-Id: I37eeeda50cff0475d91e7926fdf74216975a0037
2022-10-28 15:43:48 +00:00
Lukacs T. Berki
6b236f1607 Multithread symlink forest removal.
This makes symlink forest creation ca. 2x faster again, taking 2-3
seconds instead of 5.

Who would have thought that os.RemoveAll() is slow.

Test: Presubmits.
Change-Id: I91e41319c972dbf1113cf723e383c785433c18b9
2022-10-28 07:15:55 +00:00
Lukács T. Berki
4bb30b59a9 Merge changes from topic "separate-symlink-forest-invocation"
* changes:
  Build the symlink tree on multiple threads.
  Create Bazel symlink forest in a separate process.
2022-10-28 07:05:00 +00:00
Lukacs T. Berki
647e7abfa2 Build the symlink tree on multiple threads.
This makes it take ~5 seconds on AOSP instead of ~10. Frankly, the
speedup is somewhat disappointing but at least the code is not
complicated.

Test: Presubmits.
Change-Id: Icf94d7ca8bd80c458d014f4cf4cc1be7138deaa6
2022-10-27 10:17:20 +00:00
Lukacs T. Berki
c541cd27fa Create Bazel symlink forest in a separate process.
This helps with incrementality a lot: the symlink forest must depend on
almost every directory in the source tree so that if a new file is added
or removed from *anywhere*, it is regenerated.

Previously, we couldn't do this without invoking bp2build, which is
quite wasteful because bp2build takes way more time than the symlink
forest creation, even though we do the latter in a very suboptimal way
at the moment.

This means that if a source file is added or removed (which does not
affect globs), we don't pay the cost of bp2build anymore.

Also refactored symlink_forest.go on the side. Too much state was being
passed around in arguments.

This change reimplements aosp/2263423 ; the semantics of not touching an
output file is the exact same as order-only inputs and the latter is a
bit fewer lines of code.

Test: Presubmits.
Change-Id: I565c580df8a01bacf175d56747c3f50743d4a4d4
2022-10-27 08:08:45 +00:00
Yu Liu
2ff53da9f8 Merge "Support apex_test." 2022-10-26 16:37:59 +00:00
Usta Shrestha
783ec5c72c Remove a self-dependency of bp2build
bp2build (i.e. bootstrap.ninja#bp2build_workspace_marker) generate $OUT/soong/bp2build/**/BUILD.bazel files
Having them as a dependency would thus make bp2build_workspace_marker stale upon incremental builds (because we don't re-touch the marker file if it already exists)

See Also: https://android-review.googlesource.com/c/platform/build/soong/+/2263423

Bug: b/253450880
Test: NINJA_ARGS='-d explain' m --bazel-mode adbd
      repeat and see if bp2build is rerun
prior to this CL, one would see the input /usr/local/google/home/usta/aosp/out/soong/bp2build/build/make/tools/BUILD.bazel trigger bp2build over and over again

Change-Id: I904cd333a5d6ef506fc4019eda7623ef96a1daa3
2022-10-25 13:46:20 +00:00
Yu Liu
4c212ce058 Support apex_test.
Bug: 249744489
Test: Manual and unit test.
Change-Id: I866debf7ffee54a0f4649b5e5425a8e3cc3042a1
2022-10-24 10:35:12 -07:00
Usta Shrestha
49d04e89d8 cosmetics
Test: m --bazel-mode nothing
Bug: b/239044236
Change-Id: Iaffc315c696f2fa19a2525009010d5964cf5a7d1
2022-10-21 20:09:23 +00:00
Treehugger Robot
95ac23eeeb Merge "Introduce BazelStringOrLabelFromProp." 2022-10-20 18:26:20 +00: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
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
c5184ec089 Rename prebuilt_library_* to cc_prebuilt_library_*
Follow the convention of everything else in `cc`

Test: CI
Change-Id: I133d0b7119d4e9b357aada3467bc079f20dc0f60
2022-10-20 14:51:55 +00:00
Yu Liu
d6201013eb Make cc_genrule.srcs configurable.
Also disallow arch variant of genrule.out.

This is to be consistent with bazel where we are migrating to.

Bug: 254114674
Test: Manual
Change-Id: I685a2e64102b7bb68128b39931f0bc85878bc6de
2022-10-19 12:35:26 -07:00
Vinh Tran
827db14152 Merge "Default apex's compile_multilib to "first" in bp2build" 2022-10-17 14:12:29 +00:00
Vinh Tran
8f5310f90c Default apex's compile_multilib to "first" in bp2build
In Soong, decodeMultilib, used to get multilib to determine the dep variations, return "first" if defaultMultilib is set to "common". apex sets defaultMultilib to "common" which means equivalent compileMultilib in bp2build for apex should be "first" (See new Soong unit tests for more context).

This CL fixes bp2build for apex to be more correct.

Bug: 251559512
Test: go tests
Change-Id: Id1cb4407980fc1fab91822c81326f37fb4adfa0a
2022-10-13 16:59:30 -04:00
Wei Li
7d8f6182f9 Fix some issues in bp2build converter for python_binary_host.
1) Bp2build convert python_binary_host main attribute as LabelAttribute. Currently "main" attribute in python_binary_host is handled as string but for some modules (e.g certify_bootimg) the "main" attribute points to a file in its subpackage like "subpackage/file.py" and should be converted to "//.../subpackage:file.py".

2) Filter out duplicated labels in the merged list of "required" attributes of python_binary_host and its defaults.

Test: b build //system/tools/mkbootimg:certify_bootimg
Test: b build //build/make/tools/releasetools:check_target_files_signatures
Bug: 253081249
Bug: 253101186

Change-Id: Ic2cb4cadec2c1348da70af9f0730da9914d3a8ca
2022-10-12 17:43:20 -07:00
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
49b59385da Merge "Support cc_prebuilt_binary building with Bazel" 2022-10-10 21:37:35 +00:00
Spandan Das
4238c65a17 Converters for contributions to systemapi and vendorapi
The module types in scope of this conversion are
1. cc_library and cc_library_shared (non-null llndk or stubs prop)
2. cc_library_headers (all)

For (2), we need some postprocessing on the results of the parser
bp2BuildParseBaseProps. This is necessary because arch and os specific
API exports need to be flattened and added to the generateed API headers
target along NoConfigAxis
e.g.
```
The api equivalent of
cc_library_headers (
  name = "lifoo",
  deps = select({
  	"//build/bazel/platforms/arch:arm": ["arm_deps"],
  	"//build/bazel/platforms/arch:arm64": ["arm64_deps"],
	}),
)
should be
cc_api_library_headers (
  name = "lifoo",
  deps = ["arm_deps", "arm64_deps"],
)
```

For (1), we also need to generate 1:many header api targets so that
arch-specific deps can propagate arch metadata to the top-level
api_domain rule

Test: go test ./bp2build
Test: go test ./cc

Change-Id: Ie40cba1ac8e89f290b3d926c190d5e93abd52859
2022-10-07 23:48:00 +00:00
Treehugger Robot
41a7fedd39 Merge "Fix incrementality bug with merged BUILD files" 2022-10-07 22:21:26 +00:00
Cole Faust
fd88414b4c Fix incrementality bug with merged BUILD files
The merged build files should be added as ninja dependencies,
so we rerun when they're changed.

Fixes: 246552590
Test: m bp2build, m bp2build again and observe it didn't rerun. Then add a comment in external/protobuf/BUILD.bazel, run m bp2build again, and observe it reruns
Change-Id: I26ed035cc0a894500a192f9aa3371fb46519689b
2022-10-07 13:11:45 -07:00
Trevor Radcliffe
4e503ec09d Merge "Split ldflags in bp2build" 2022-10-07 17:31:29 +00:00
Treehugger Robot
d504adbead Merge "apex_key bp2build: disambiguate module and src deps." 2022-10-07 10:55:50 +00:00
Alex Márquez Pérez Muñíz Díaz Púras Thaureaux
b12ff59f0b Support cc_prebuilt_binary building with Bazel
Bp2build-enable cc_prebuilt_binary -> cc_prebuilt_binary

Bug: 241415823
Test: cc_prebuilt_binary_conversion_test.go
Change-Id: I007deef8d44f68993012f2114314d1cb52cfbb0e
2022-10-06 19:39:09 +00:00
Jingwen Chen
34feb1471a apex bp2build: refactor module names to be more meaningful.
Numbered module names weren't obvious.

Test: presubmits
Change-Id: Iee921e2965d1664ed1bccd934ab80f913eff6356
2022-10-06 13:02:30 +00:00
Jingwen Chen
1d873331ad apex_key bp2build: disambiguate module and src deps.
(and remove unused keyName field.)

The private_key and public_key props of an apex_key can point to either
a module or a string. If it's a module, then respect it. If it's a
string, there's additional product variable lookup to find the apex_key
files in product_vars's DefaultAppCertificate parent dir.

This is similar to android_app_certificate.

Test: presubmits
Change-Id: Ib258da14cb0c2df8b5f817fcbc46afebcf225db8
2022-10-06 05:56:05 +00:00
Spandan Das
e191ae76b6 Merge "Move API providing modules from bp2build to api_bp2build workspace" 2022-10-05 19:40:01 +00:00
Spandan Das
ee08eb3c81 Merge "Create a new mode in soong_ui to generate API only BUILD files" 2022-10-05 01:37:28 +00:00
Trevor Radcliffe
6d91fe70e2 Merge "Update tests for cc_* converters" 2022-10-04 19:06:21 +00:00
Spandan Das
8b4a5f352e Move API providing modules from bp2build to api_bp2build workspace
The module types in scope are
1. ndk_library
2. ndk_headers, versioned_ndk_headers
3. api_domain

These modules will no longer generate Bazel targets in bp2build
workspace. A new soong mode `api_bp2build` will be used to generate API
specific targets in a separate Bazel workspace at out/soong/api_bp2build

Test: go test ./bp2build

Change-Id: I01d06b6d8b8364c0d56d6d3f07f8f8bf21db31d7
2022-10-04 17:33:32 +00: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
Jingwen Chen
6a35072de2 Merge "Share certificate bp2build between android_app and apex." 2022-10-04 07:32:36 +00:00
Trevor Radcliffe
82dd855229 Update tests for cc_* converters
Forgot to update these tests when doing aosp/2233406

Bug: 249175838
Test: Unit tests
Change-Id: I50fbf7c232d0a7aec72af83bcbe805d785f82897
2022-10-03 20:27:27 +00:00
Trevor Radcliffe
ea6a45deda Split ldflags in bp2build
But do the splitting before adding $(location...) flags.

Fixes: 247830974
Test: Unit tests
Test: m nothing
Change-Id: I4a7e8e20f720a1074a5ffa17da4fe9b96ca6ed58
2022-10-03 20:10:08 +00:00
Colin Cross
9531e42407 Merge changes from topic "soong-riscv64"
* changes:
  Add riscv64-linux-android support
  Removed unused GCC references
2022-10-03 19:41:45 +00:00
Colin Cross
f05b0d35d2 Add riscv64-linux-android support
Add barebones riscv64-linux-android support.  This should be enough
to add riscv64-specific entries to Android.bp files, but can't
actually compile anything until there are riscv64 toolchains.

Test: arch_test.go
Change-Id: I0dcc7e797d9352dd38243be908a7f19004ff3db1
2022-10-03 08:43:13 -07:00
Jingwen Chen
bea58093b4 Share certificate bp2build between android_app and apex.
The certificate module is handled the same in Soong between android apps
and apexes, so share the bp2build code as well.

There are a few changes in this CL:

- If override_apex.certificate is unset, the generated apex also unsets
  it. This prevents the generated apex from using the base apex's
  certificate, which is most likely incorrect (e.g. google variant using
  the cert for the aosp variant). Instead, rely on the default
  certificate handling in the macro.
- If the certificate prop is a string, then it gets generated into
  certificate_name in order to disambiguate. This behavior is identical
  to android_app.

Test: added various unit tests.

Bug: 249089160
Fixes: 249089160
Change-Id: I99e18964ff546429a985d0f64dc21e2c69d35d9d
2022-10-03 09:20:47 +00:00
Treehugger Robot
fba6f7797c Merge "Add bp2build converter for bpf" 2022-09-29 03:04:46 +00:00
Zi Wang
b3cb38c3c8 Add bp2build converter for bpf
Bug: 240163393
Test: m bp2build
Test: bp2build/bpf_conversion_test.go
Change-Id: Ie3bbc64511146b099a766d7e8b56e93cef58ef68
2022-09-28 14:18:45 -07:00
Trevor Radcliffe
d4961319a9 Merge "Add additionalLinkerInputs for both version_script" 2022-09-28 16:01:36 +00:00
Sasha Smundak
05b0ba6d1c Convert Soong licenses attribute to Bazel's applicable_licenses attribute
Add it to the `CommonAttributes` struct and handle it in fillCommonBp2BuildModuleAttrs

Bug: 190817312
Test: treehugger
Change-Id: I7b21056e680384d4046372ee844512029721026e
2022-09-27 11:38:11 -07:00
Trevor Radcliffe
37ec2f7256 Add additionalLinkerInputs for both version_script
and dynamic_list.

Fixes: 249175838
Test: Unit tests
Change-Id: Id65e05cc9dbd294ce09dea36851d69d9962994c7
2022-09-27 01:50:11 +00:00
Treehugger Robot
018dcfce20 Merge "Unit test for missing module error" 2022-09-26 22:48:45 +00:00
Treehugger Robot
8c45f98c3e Merge "File paths to allow "./" prefix" 2022-09-26 21:02:34 +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