Commit graph

183 commits

Author SHA1 Message Date
Dan Willemsen
9f9f77dfc2 Merge "Prepare soong for python 3.11" into main 2023-08-17 19:14:46 +00:00
Dan Willemsen
339a63f044 Prepare soong for python 3.11
Due to upstream changes in python path calculations, I'm simplifying the
python launcher to work more like a standard python distribution. This
is effectively changing the stdlib path from `internal/stdlib` to
`internal/python3.10` (or `3.11`, etc). This allows us to specify the
zip file as PYTHONHOME, set PYTHONPLATLIBDIR to `internal` and use the
default detection after that.

That does mean during upgrades that the stdlib pkg path will change, so
move the source vs prebuilt calculation from the Android.bp into Soong
to choose which stdlib module to pick up (with the corresponding
`pkg_path`)

Bug: 278602456
Test: treehugger with python3.10
Test: a python3.11 source + 3.10 prebuilt build
Test: a python3.11 source+prebuilt build
Change-Id: I8b02e7b22a1f1d1e02819ae1a31a99cdc985542c
2023-08-16 21:47:03 -04:00
Trevor Radcliffe
d3243d5e74 Use relative path instead of base for python proto
We encountered a duplicate sources bug in python proto generation
because we're only using the base name. This CL makes it use the
entire path to avoid this.

Fixes: 295333879
Test: Presubmits
Change-Id: I4ab821508cd5979bd595e327c1ccd3d68110fba6
2023-08-15 18:33:00 +00:00
Spandan Das
09f6b1390c Merge changes I8ca452aa,I437fc890,If9446700 into main
* changes:
  Handle .proto files in different package for filegroups
  Handle .proto files that end up in a different package
  Allow creation of BazelTargets in a different directory
2023-08-08 00:51:52 +00:00
Spandan Das
c53767e434 Handle .proto files that end up in a different package
Bazel poses a strict requirement that .proto files and proto_library
must be in the same package. This CL handles this automatically by
creating the proto_library in a separate dir/package if necessary

Implementation details
- Partition the `srcs` by package. `srcs` has been computed using
  `transformSubpackagePath`, so the information about packages is
  available at this point
- Create a proto_library in each package by using
  `CommonAttributes.Dir`. Collect all these additional libraries
  and put them in `info.Proto_libraries` so that they get added as deps
  of (cc|python|...)_proto_library
- Add an import_prefix to the proto_library in subpackages relative to
  the current directory. This relies on the assumption that every src is
  beneath the current directory (Soong will complain if a path in
  Android.bp contains ../)

filegroup module type uses a separate code-path to create proto_library.
This will be handled in the next CL in stack.

Test: bp2build unit tests
Test: TH
Test: Built the failing internal module mentioned in
b/292583584#comment1

Bug: 292583584

Change-Id: I437fc89092321b26c5f0511387cde9e84084d6f9
2023-08-07 19:18:03 +00:00
yike
1aaeea39da Convert merge_annotation_zips_test to b test
Test: b test //frameworks/base/api:merge_annotation_zips_test
Bug: 293225210
Change-Id: Ia53b4168894b5c70c843ca315d963fa905ef582f
2023-08-01 18:57:59 +00:00
Zi Wang
bbb1b74cbf Add data_device_bins_both properties for python_test_host
Test: presubmits and manual verification

Bug: 274930471
Change-Id: Iafc85526afdb8264526e8a5a33319fa33a23c66b
2023-05-19 10:32:49 -07:00
Colin Cross
e8c70c5bd5 Enable host cross python test builds
Ic37c8db918873ddf324c86b12b5412952b0f2be2 converted python_binary_host
and python_library_host from HostSupportedNoCross to HostSupported,
but left python_test_host.  Do the same for python_test_host.

Fixes dependencies between java_test_host modules that create
host cross variants and python_test_host modules that were missing
host cross variants.

Bug: 282918027
Test: builds
Change-Id: Iae687aa3aa0f0b005f2dd27469f631145247a008
2023-05-18 11:51:56 -07:00
Krzysztof Kosiński
ebb25bd22e Delete Python 2 embedded launcher test.
There are no remaining Python 2 binaries using an embedded
launcher in Android.

Bug: 245854393
Test: m par_test py2-cmd py3-cmd && build/soong/python/tests/runtest.sh
Change-Id: I241bbaa417060b51b4d2883011ccb43e22ace4c8
2023-05-04 17:52:12 +00:00
Cole Faust
d82f036b89 bp2build support for python_test(_host)
There was a request for using b with python tests. bp2build python
tests exactly the same way as python binaries so that they can be
used with `b`.

Bug: None
Test: go test
Change-Id: Id68a6a73572745a4885b3e5bb1b8452e36baa982
2023-04-13 16:10:59 -07:00
Qiao Yang
2a3a42683c stub_template_host redirect SIGINT and SIGTERM to subprocess
Test: manual
Change-Id: I561f581f7413dc18b2d449f4ef338db3b6b9ca47
2023-03-22 00:17:24 +00:00
Ziwei Zhang
e75fcf4ddb Merge "Add python template for mobly tests." 2023-03-20 02:16:04 +00:00
Cole Faust
edc4c505f9 Make using python 2 an error
Except if BUILD_BROKEN_USES_SOONG_PYTHON2_MODULES is set, and except for
some core py2 modules that can't be removed until python2 is fully gone.

Bug: 203436762
Test: m nothing
Change-Id: I62ccb6f5687eab1e79c372ffc234a90ca5b566ac
2023-03-09 11:56:04 -08:00
Ziwei Zhang
c3bb83a57b Add python template for mobly tests.
Mobly is a Python-based test framework that specializes in supporting
test cases that require multiple devices. There are some Mobly based
Android tests, but these tests cannot be added to xTS since they are
not using TF. Currently TF provides a 2-device Mobly test runner.
This change is a short-term solution to help teams (eg. bluetooth) to
add their multi-device Mobly tests to xTS without writing TF configs.
For long-term, device infra team and xTS infra team will provide a
solution for more complex multi-device tests in xTS and deprecate this
TF template.

Test: manually check the generated mobly xml config
Bug: 272239365
Change-Id: I252cc774094eebbd9264243d30023ace4839c2cd
2023-03-08 21:37:58 +08: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
909d237c84 Revert "Dynamically assemble the list of python launcher shared libs for precompiling"
This reverts commit aa5b377ee9.

Reason for revert: this broke musl builds by removing the install dependency from python binaries to the launcher shared libraries: https://android-build.googleplex.com/builds/submitted/9600042/unit_tests_x86_64_musl/latest/view/logs/build_error.log

Change-Id: I4e13f333f287831ba13724f13ab2be789a92b476
2023-02-13 23:17:40 +00:00
Cole Faust
aa5b377ee9 Dynamically assemble the list of python launcher shared libs for precompiling
Still fall back to the hardcoded list for what to put in LOCAL_SHARED_LIBRARIES,
because I couldn't figure out a good way to get those modules at the moment.

Bug: 259718110
Test: Presubmits
Change-Id: Ia992ffea8819d8c67280b08bc45505f77af09de0
2023-02-02 13:47:56 -08:00
Cole Faust
5c503d1c43 Precompile python sources
This signifigantly improves the startup time of soong-built
python binaries. For example, running
`m apexer && time out/host/linux-x86/bin/apexer` gives
0.734s before this cl, and 0.094s after.

Fixes: 259718110
Test: Presubmits
Change-Id: Ib19e83e2c60c39a849525be117279c318de3afa7
2023-01-27 15:43:38 -08:00
Cole Faust
4d247e6f21 Refactor python rules
The goal of this cl is to simplify the python rules,
mostly by removing the "decorator" pattern that they
currently use, and instead making separate module
types for libraries, binaries, and tests that inherit
from each other.

Bug: 259718110
Test: Verified ninja files are unchanged (they only change in the list of soong sources because I added/deleted files)
Change-Id: I1e836e2cc4782c7818f91db7df7895de3b8db7ca
2023-01-25 10:40:59 -08:00
Cole Faust
216805457c Allow adding extra tradefed options in the Android.bp file
Some tests need to add custom tradefed options, but still want to
keep most of the soong autogenerated tradefed xml file.

Expose a test_options: { tradefed_options: [...] } property that
will allow tests to add more options to the autogenerated xml file.

Fixes: 184895128
Test: go test, and verified that the ninja files did not change for aosp_arm64
Change-Id: I50d4ad139322e9e207202f1e1a50f5bbb424aa6f
2023-01-03 12:47:11 -08:00
Tahsin Loqman
77dc7d0839 Revert "Allow adding extra tradefed options in the Android.bp file"
This reverts commit 8ec823cba1.

Reason for revert: DroidMonitor: Potential culprit for Bug b/262965953 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Change-Id: I236cc36981d8b30527ca286632727f8ca267e969
2022-12-19 16:27:25 +00:00
Cole Faust
8ec823cba1 Allow adding extra tradefed options in the Android.bp file
Some tests need to add custom tradefed options, but still want to
keep most of the soong autogenerated tradefed xml file.

Expose a test_options: { tradefed_options: [...] } property that
will allow tests to add more options to the autogenerated xml file.

Fixes: 184895128
Test: go test, and verified that the ninja files did not change for aosp_arm64
Change-Id: I75f7eb002c8325ce7cdc76e12e76e16195320620
2022-12-09 15:23:26 -08:00
Cole Faust
caf766b74f Remove flags that enable the new python path behavior
The new behavior has been enabled by default, and these
flags aren't necessary anymore.

Fixes: 245583294
Test: m py_dont_import_folder_of_entrypoint_test && /ssd/aosp-master/out/host/linux-x86/testcases/py_dont_import_folder_of_entrypoint_test/x86_64/py_dont_import_folder_of_entrypoint_test
Change-Id: I5b6f98da51791bc5d28662ef799a10c1bb6a35a0
2022-10-21 16:07:56 -07:00
Wei Li
f18404f331 Merge "Fix some issues in bp2build converter for python_binary_host." 2022-10-13 03:35:38 +00: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
Cole Faust
45891bd93a Merge "Revert^2 "Enable new python path behavior by default"" 2022-10-11 20:37:54 +00:00
Cole Faust
02ad4016cc Revert^2 "Enable new python path behavior by default"
This reverts commit 4d5cc709fa.

Reason for revert: Acloud issue was fixed in aosp/2243150, make sure the host unit tests are run on this cl via go/abtd before submitting

Change-Id: Ie148430d331a01a9877adaf3cb88f1c57af136a0
Bug: 245583294
Bug: 247578564
Bug: 251688241
2022-10-11 18:15:36 +00:00
Lais Andrade
dd0cc36b27 Merge "Revert "Enable new python path behavior by default"" 2022-10-07 13:28:30 +00:00
Lais Andrade
4d5cc709fa Revert "Enable new python path behavior by default"
This reverts commit 5fe655d1c7.

Reason for revert: DroidMonitor: Potential culprit for Bug b/251688241 - verifying through ABTD before revert submission. This is part of the standard investigation process, and does not mean your CL will be reverted.

Change-Id: I1ea4df27557fc891d8f0156ec5681f9b0c601c98
2022-10-07 10:09:09 +00:00
Treehugger Robot
be5f83ef1b Merge "Enable new python path behavior by default" 2022-10-07 01:02:30 +00:00
Cole Faust
5fe655d1c7 Enable new python path behavior by default
Now that usages have been updated, enable the new
behavior by default. If everything goes well with
this, we can then remove the flags.

Bug: 245583294
Bug: 247578564
Test: Presubmits
Change-Id: Idac8d2dc0f96ae750dba4a99b32525676d0d6f25
2022-10-05 11:51:26 -07:00
Bob Badour
1825cb03a2 [LSC] Add LOCAL_LICENSE_KINDS to build/soong
Added SPDX-license-identifier-Apache-2.0 to:
  python/tests/dont_import_folder_of_entrypoint/Android.bp
  python/tests/top_level_dirs/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Change-Id: I7a1ea160c685361318f9a8543e10b83eeb9dcb7f
2022-09-29 10:18:32 -07:00
Cole Faust
40c34500c4 Add binary properties to python_defaults and add modern_python_path_defaults
So that we can more easily enable these new flags on several
modules.

It seems you can still apply a python_defaults to a python_library
even with this change, so I didn't break it out into a separate
python_binary_defaults.

Bug: 245583294
Test: m py_dont_import_folder_of_entrypoint_test && out/host/linux-x86/testcases/py_dont_import_folder_of_entrypoint_test/x86_64/py_dont_import_folder_of_entrypoint_test
Change-Id: Iecf9c1845df4630bafdea9957eb2450c15f8596b
2022-09-26 12:05:03 -07:00
Cole Faust
eb3a900c5c Add flag to not add directory of entrypoint to sys.path
The python interpreter will by default add the directory of
the entrypoint script to the beginning of sys.path. This
can be disabled in python 3.11+ (which is not released yet)
using the PYTHON_SAFE_PATH environment variable or the -P flag.
As a workaround to have this behavior in older python versions,
we can make an __soong_entrypoint_redirector__.py file at the
root of the zip file that is the entrypoint, and then that
file will redirect to the real entrypoint.

This brings non-embedded-launcher python modules closer to
the embedded launcher version. The embedded launcher binaries
already act like this because they start at an __main__.py file
at the root of the zip file.

Bug: 245583294
Test: m py_dont_import_folder_of_entrypoint_test && out/host/linux-x86/nativetest64/py_dont_import_folder_of_entrypoint_test/py_dont_import_folder_of_entrypoint_test
Change-Id: I39aaf04fb19c3ba7f5c9d98220872d6d08abf736
2022-09-26 11:22:38 -07:00
Cole Faust
2f037821b0 Merge "Add flag to not add top-level modules to PYTHONPATH" 2022-09-26 17:24:08 +00:00
Cole Faust
af4b13dbe4 Add flag to not add top-level modules to PYTHONPATH
stub_template_host.txt added all the top-level modules to the
PYTHONPATH, which isn't correct, and caused absl.logging to
override the built-in logging module.

Removing this also makes it more consistent with python binaries
built with embedded_launcher: true. embedded_launcher: true
binaries don't add the top-level modules.

Fixes: 245583294
Test: m py_dont_add_top_level_dirs_test && out/host/linux-x86/testcases/py_dont_add_top_level_dirs_test/x86_64/py_dont_add_top_level_dirs_test
Change-Id: Id3069565d2b2c4b2bda0ff5301e757a7b4201751
2022-09-23 11:06:11 -07:00
Bob Badour
302756ae83 [LSC] Add LOCAL_LICENSE_KINDS to build/soong
Added SPDX-license-identifier-Apache-2.0 to:
  python/tests/proto_pkg_path/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Change-Id: I17e9945a265d0ede3e291ed6f5d410dde035fbe5
2022-09-22 13:34:03 -07:00
Cole Faust
43ac21f53d Make protobufs respect pkg_path properly
Currently, python protobuf sources are generated as if
pkg_path didn't exist, but then are moved into the pkg_path
directory after being generated. This means they're generated
with import statements in them that don't include the pkg_path.
These import statements won't work at all when pkg_path is at
least 2 levels deep, but currently erroneously work with a 1
level deep pkg_path because we mistakenly add the top-level
modules in a soong-built python zip to the PYTHONPATH. We want
to remove those modules from the PYTHONPATH, so the generated
protobuf source files have to use the correct imports.

Since there are existing cases of code that needs to be updated,
guard this new behavior behind a flag, protos_respect_pkg_path.
We will set this to true on modules individually as we update
them, and then eventually change the default to true and remove
this flag.

Bug: 247578564
Test: m py_proto_pkg_path_test && out/host/linux-x86/nativetest64/py_proto_pkg_path_test/py_proto_pkg_path_test
Change-Id: I3695cf5521837da087592f2ad5350201035b7b0e
2022-09-20 16:00:51 -07:00
Cole Faust
d02ca056a3 Don't close file descriptors when starting python program
Python programs run via a wrapper script. That wrapper script
can be started with open file descriptors, for example by using
the <(echo foo) syntax in bash. The shouldn't be closed when
starting the real script.

Bug: 203436762
Test: Presubmits
Change-Id: Ib20450f713b15c8a5527d1e433bfd9635cead85f
2022-09-09 10:27:15 -07:00
Colin Cross
d079e0b270 Reformat build/soong for go 1.19
Test: none
Change-Id: I132368f0fcbdb5ea088b5b84dbe4ccfdd9e94cad
2022-08-17 10:43:13 -07:00
Zhenhuang Wang
0ac5a431a9 Move common test_options properties into the android package
Multiple modules (e.g. java, cc, python, rust) define the `test_options`
field. Extract the common properties in test_options to share across
different test rules.

Bug: 240928948
Test: `refreshmod` and diff with original module-info.json
Change-Id: I404a7a157b4ccaa53d800ee2217559ff695bd825
2022-08-17 01:19:15 +08:00
Cole Faust
01243368d7 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
2022-06-09 13:28:25 -07:00
Cole Faust
53b62098d0 Add bp2build converter for python protobuf files
Bug: 196084681
Test: b run //build/bazel/examples/python/protobuf:build_bazel_examples_python_protobuf_main --config=linux_x86_64
Change-Id: I4d806902d262351231f64686a5d24513a25d9749
2022-05-26 15:54:23 -07:00
Cole Faust
b09da7e863 Add imports property to py_library rules
This is to avoid having it hardcoded in a fork of the
py_library rule.

Most import attributes should just be set to ".", but
our previous solution always hardcoded it to ".." instead,
for ndkstubgen. ndkstubgen uses pkg_path: "ndkstubgen",
i.e., it set pkg_path to the name of the folder that
contained the Android.bp file. In this specific scenario,
imports = ".." works. Recreate that behavior here as well,
because we don't handle pkg_path properly yet.

Fixes: 233081071
Test: build/bazel/ci/bp2build.sh
Change-Id: Ib5e6a8edf428c74d4b5947f0ec53a2151001367a
2022-05-19 12:38:27 -07:00
Colin Cross
4111c52fa2 Support building python pars against static or shared musl libc
Support building python pars against musl libc by either adding
libc_musl as an install dependency or using the static version
of the python launchers.

Bug: 179809553
Test: m USE_HOST_MUSL=true apexer deapexer
Test: m USE_HOST_MUSL=true BUILD_HOST_static=true apexer deapexer
Change-Id: I4a56efb227bea746836eb785d929eb4b5d8e15f1
2022-03-08 15:15:56 -08:00
Colin Cross
c68db4b305 Remove InstallBypassMake and ToMakePath
InstallBypassMake and ToMakePath are obsolete, remove them.

Bug: 204136549
Test: m checkbuild
Change-Id: Ie5a6f7254b3d317ed6039e114ed6aec35e1ce273
2021-12-15 15:22:53 -08:00
Liz Kammer
be46fccc40 Use one mutator for all bp2build conversion.
Each conversion required defining a separate mutator, which will each
operate on _all_ modules and requires each to repeat checks whether the
mutator should operator. Instead, we introduce a single mutator and
modules can define a ConvertWithBp2build to implement bp2build
conversion for that module.

Test: bp2build.sh
Bug: 183079158
Change-Id: I99d4b51f441c2903879092c5b56313d606d4338d
2021-12-14 09:37:45 -05:00
Jingwen Chen
89e2188d49 Allowlist //build/soong/cc/{ndkstubgen,symbolfile}.
This contains the tool to generate stub libraries.

Bug: 208215661
Bug: 207812332

Test: b run //build/soong/cc/ndkstubgen
Change-Id: Id48d74381457e0a62aca0ed7f8a9367886863bfd
2021-12-03 01:13:40 +00: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
Colin Cross
d5e7af9003 Switch default for InstallBypassMake to true
Enable InstallBypassMake for all module types by switching its default
to true.

Bug: 204136549
Test: m checkbuild
Change-Id: Ied082995e74d71dee6aecea99689ac3f63600d3b
2021-11-22 21:57:36 -08:00