Commit graph

18 commits

Author SHA1 Message Date
Dan Willemsen
b2d1cf93c7 Skip py2-cmd tests on Mac
Mac no longer builds python2

Test: prebuilt/build-tools/build-prebuilts.sh on Mac
Change-Id: I5857ba7ec023021e660e86df3573e4b6e3d1902b
2023-08-22 18:41:25 -04: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
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
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
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
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
Julien Desprez
d3dbf07c37 Mark par_test as not unit tests
They seem to be used as Soong validation. They are not implemented against the python
unit tests framework, so we can execute them as such in CI automatically.

Change-Id: I8fe662d5d3399d60c8a05acc79b4dd51b5d138a6
Test: presubmit
Bug: 183730987
2021-04-20 15:56:09 +00:00
Bob Badour
02040de891 Add LOCAL_LICENSE_KINDS to build/soong
Added SPDX-license-identifier-Apache-2.0 to:
  Android.bp
  android/Android.bp
  android/soongconfig/Android.bp
  androidmk/Android.bp
  apex/Android.bp
  bazel/Android.bp
  bp2build/Android.bp
  bpf/Android.bp
  bpfix/Android.bp
  cc/Android.bp
  cc/config/Android.bp
  cc/libbuildversion/Android.bp
  cc/libbuildversion/tests/Android.bp
  cc/ndk_api_coverage_parser/Android.bp
  cc/ndkstubgen/Android.bp
  cc/symbolfile/Android.bp
  cmd/dep_fixer/Android.bp
  cmd/diff_target_files/Android.bp
  cmd/extract_apks/Android.bp
  cmd/extract_jar_packages/Android.bp
  cmd/extract_linker/Android.bp
  cmd/fileslist/Android.bp
  cmd/host_bionic_inject/Android.bp
  cmd/javac_wrapper/Android.bp
  cmd/merge_zips/Android.bp
  cmd/multiproduct_kati/Android.bp
  cmd/path_interposer/Android.bp
  cmd/pom2bp/Android.bp
  cmd/pom2mk/Android.bp
  cmd/sbox/Android.bp
  cmd/soong_build/Android.bp
  cmd/soong_env/Android.bp
  cmd/soong_ui/Android.bp
  cmd/zip2zip/Android.bp
  cmd/zipsync/Android.bp
  cuj/Android.bp
  dexpreopt/Android.bp
  dexpreopt/dexpreopt_gen/Android.bp
  env/Android.bp
  etc/Android.bp
  filesystem/Android.bp
  finder/Android.bp
  finder/cmd/Android.bp
  genrule/Android.bp
  jar/Android.bp
  java/Android.bp
  java/config/Android.bp
  kernel/Android.bp
  linkerconfig/Android.bp
  linkerconfig/proto/Android.bp
  makedeps/Android.bp
  partner/Android.bp
  phony/Android.bp
  python/Android.bp
  python/tests/Android.bp
  remoteexec/Android.bp
  rust/Android.bp
  rust/config/Android.bp
  scripts/Android.bp
  sdk/Android.bp
  sh/Android.bp
  shared/Android.bp
  symbol_inject/Android.bp
  symbol_inject/cmd/Android.bp
  sysprop/Android.bp
  tradefed/Android.bp
  ui/build/Android.bp
  ui/logger/Android.bp
  ui/metrics/Android.bp
  ui/metrics/proc/Android.bp
  ui/status/Android.bp
  ui/terminal/Android.bp
  ui/tracer/Android.bp
  xml/Android.bp
  zip/Android.bp
  zip/cmd/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  finder/fs/Android.bp
  third_party/zip/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work

Change-Id: Ia47ca14f16b8c9f84f9d533a07e5b00e2c04e8d4
2021-02-06 04:23:21 +00:00
Dan Willemsen
7fa7646ad7 Add tests for py(2|3)-cmd
Test: m par_test{,3} py{2,3}-cmd; ./runtest.sh
Change-Id: I4aadd9fc85be4381bd9a0843064ceaa87150b5ee
2020-02-19 19:40:38 -08:00
Dan Willemsen
67d4258786 Test par file argument handling
This had been broken with my python3 launcher.

Test: build/soong/python/tests/runtest.sh
Change-Id: I0524e5a80244bf1080cb28237b23ef0d023e03dc
2019-12-03 23:54:04 -08:00
Dan Willemsen
8d4d7bee6d Add python3 embedded launcher support
Test: m par_test{,3}; build/soong/python/tests/runtest.sh
Change-Id: I9c0fac9e2947616fdeedbfc55026dc3065966e71
2019-11-04 19:48:19 -08:00
Dan Willemsen
22e9244b16 Add par_test
This test adds a number of checks for the visible python state inside a
hermetic par file.

Test: build/soong/python/tests/runtests.sh
Change-Id: I7188d862a309a09623169e1f967bde86707d41af
2019-02-14 02:18:05 +00:00