Commit Graph

174 Commits

Author SHA1 Message Date
Vladimir Marko 982e384a63 Fix profileCommand to remove the profile first.
This fixes a discrepancy between clean and incremental
builds exposed by
    https://android-review.googlesource.com/1671710 .

Test: m
Bug: 148067697
Change-Id: I0de078045075417a4123f7c3821c723f1e8e6b68
2021-04-29 09:10:30 +01:00
Paul Duffin f7c99f5983 Add GetEmbeddedPrebuilt and IsModulePrebuilt
Dedups the many repetitions of the code to obtain a *Prebuilt from a
module.

Bug: 177892522
Test: m nothing
Change-Id: I1ededbe9ee79e89ea6dd8882dfee4be0bf0b51b7
2021-04-28 14:02:04 +01:00
Treehugger Robot bdae1e5765 Merge "Drop DexPreoptImages field in dexpreopt config" 2021-04-27 01:53:45 +00:00
Jeongik Cha b19b58a015 Drop DexPreoptImages field in dexpreopt config
The field isn't used anymore.
And DexPreoptImagesDeps will have the slice of which size is the same as
Archs to avoid an error.

Bug: 158843648
Test: m
Change-Id: I520063ff7376811febbc82e1a0a43785feb5bbb2
2021-04-26 23:41:40 +09:00
Vladimir Marko fa64af9961 Merge "profman: Clean up output profile type options." 2021-04-26 07:34:21 +00:00
Vladimir Marko 230bd421a8 profman: Clean up output profile type options.
Test: m  # Check output boot profiles with hexdump.
Bug: 148067697
Change-Id: Ic20f415ad4eee1fd6396f320b757420884764d2c
2021-04-23 15:19:16 +01:00
Paul Duffin 7d1d083ec1 Check consistency of the BootJars/UpdatableBootJars config
Both out/soong/dexpreopt.config and out/soong/soong.variables contain
configuration for the BootJars and UpdatableBootJars that MUST be
identical. If they are not then it can lead to broken builds.

This change adds a consistency check for them that will make the issue
more obvious.

Bug: 186195980
Test: DIST_DIR=out/bionic-dist ./art/tools/dist_linux_bionic.sh -j80 com.android.art.host com.android.support.apexer --skip-soong-tests
      Ran the previous command with and without the fix in
      https://r.android.com/1684877. Without the fix the build reported
      an inconsistency in the configuration, with that fix the build
      passed.
Change-Id: I10fbe328ba4f1fbd9db4708409979e9824c196ef
2021-04-23 12:23:01 +01:00
Treehugger Robot a3693772a6 Merge "Expose "full" dexpreopt.config" 2021-04-23 06:47:57 +00:00
Jeongik Cha 19ade89042 Fix toJsonClassLoaderContextRec size bug
toJsonClassLoaderContextRec's size is twice as large than expected. And
the initial values is filled with null value.

Bug: 158843648
Test: m nothing(testcase is added)
Change-Id: I24c23269bd16baa18481f34b85c543d41f26d0e0
2021-04-22 11:58:43 +00:00
Jeongik Cha c6246671ea Expose "full" dexpreopt.config
1. Instead of 'slim' config, use full config even for libs
2. Define moduleJSONConfig for fields which cannot be converted to JSON
field directly(Path type field, ProfileBootListing,
DexPreoptImagesDeps are added in this CL) and exclude fields which is
convertible(DexPreoptImageLocations)

Bug: 158843648
Test: m dist
Change-Id: I3f9192ab5292bd079be1b686bb3b25735a836cbc
2021-04-19 18:24:42 +09:00
Jeongik Cha 33a3a8182f Made ManifestPath OptionalPath instead of Path
because it is actually an optional value.

Bug: 158843648
Test: m nothing
Change-Id: If323eacf6a7aa83dcf5ce4825ad8cabeeaa97ac9
2021-04-15 09:12:49 +09:00
Ulyana Trafimovich a8f6db972f Merge changes I1f0ab4af,Iea3be0fc
* changes:
  Fix AAPT path in dexpreopt.
  Allow modules that don't run verify_uses_libraries to have nonempty CLC.
2021-03-29 09:24:00 +00:00
Ulya Trafimovich dd622951a4 Fix AAPT path in dexpreopt.
Dexpreopt uses AAPT to parse `targetSdkVersion` from the manifest, so it
the generated dexpreopt.sh script that calls AAPT must depend on it,
otherwise AAPT might not be built by the time it is used. Tool
dependencies are handled via the global Soong config and the
DEXPREOPT_GEN_DEPS variable that Soong generates for Make. This config
always uses Soong tool paths, like out/soong/host/linux-x86/bin/aapt
rather than out/host/linux-x86/bin/aapt.

This CL fixes a mistake in dexpreopt rule that used context-dependent
AAPT path (so, when called from Make, the dependency was on Soong tool,
but a Make tool was actually used, so it failed sometimes).

Bug: 132357300
Test: lunch aosp_cf_x86_64_phone-userdebug && m
Change-Id: I1f0ab4afac98e6239f324e7f3571d670fd7a36cd
2021-03-25 12:52:49 +00:00
Ulyana Trafimovich 2258cbbe42 Merge "Allow using updatable boot jars in dexpreopt (but don't use them yet)." 2021-03-25 10:13:45 +00:00
Paul Duffin b506c9dc11 Cleanup usages of Dex2oatDepTag
Creates a new deptag type for it so that it can implement the marker
interfaces that will exclude it from being added to the APEX and from
visibility enforcement. The latter is probably not an issue ATM because
the dependencies are added after visibility checks are enforced but
this code is undergoing lots of refactoring so that may change.

Bug: 177892522
Test: m nothing
Change-Id: Ibd167d557adec761a2e3eed78f4d334c40a04fb9
2021-03-24 14:34:40 +00:00
Ulya Trafimovich 9023b02c00 Allow using updatable boot jars in dexpreopt (but don't use them yet).
This CL handles updatable boot jars in the same hacky way as we handle
non-updatable boot jars: it creates a set of predefined paths to the dex
jars in a global config, then traverses all modules in a singleton
context, finds updatable boot jars and adds copy rules from these jars
to the predefined paths. A proper way would be to register dependencies
of the dexpreopted modules on the boot jars and extracting paths to dex
files by walking these dependencies.

Bug: 178467404
Test: lunch aosp_cf_x86_64_phone-userdebug && m
Test: added new Soong test
Change-Id: I87f764109315f79315d73bf43799b70eb010fc0b
2021-03-24 11:16:11 +00:00
Paul Duffin 9fc9f53423 Group all the preparations needed for testing dexpreopt
Make it easier to test dexpreopt functionality by grouping all the
fixture preparations together.

Bug: 177892522
Test: m nothing
Change-Id: I94f66e3ec82efc4fd791f4fdab678d298565e452
2021-03-24 08:30:27 +00:00
Paul Duffin f8e3d8341a Use more inclusive language in dexpreopt/testing.go
Bug: 177892522
Test: m nothing
Change-Id: Idbb37485a573ddd25c4da48ab88f9c559fca5434
2021-03-24 08:26:48 +00:00
Ulya Trafimovich bd6b076f80 Allow modules that don't run verify_uses_libraries to have nonempty CLC.
There are modules that would have passed verify_uses_library check, but
don't run it for some reason (the check gets enabled either with an
explicit setting, or if the module has nonempty <ues-library> lists in
the build properties). Previously all such modules were assumed to have
empty CLC, which is not always true. In particular, compatibility
libraries are ignored, which affected e.g. Calendar and messaging apps.

This CL gives such apps a chance to have correct CLC. The goal for the
future is to enforce verify_library_check by default.

Bug: 132357300
Test: lunch aosp_cf_x86_64_phone-userdebug && m
Change-Id: Iea3be0fc9d7775c52950848b5a3fd3b7fcd36c53
2021-03-22 10:49:31 +00:00
Ulya Trafimovich 0aba252e15 Reimplement verify_uses_libraries.sh in manifest_check.py.
Previously there were two different scripts that did similar things:
1) build/soong/scripts/manifest_check.py
2) build/make/core/verify_uses_libraries.sh

Both scripts extracted <uses-library> tags and `targetSdkVersion` from
the manifests of Java modules, but 1) worked for XML manifests, and 2)
worked for APKs. This CL reimplements the functionality from 2) in 1),
so that one script can handle both XML manifests and APKs.

Bug: 132357300

Test: lunch cf_x86_64_phone-userdebug && m && launch_cvd \
      adb wait-for-device && adb root && adb logcat \
      | grep -E 'ClassLoaderContext [a-z ]+ mismatch'
      # empty grep output, no errors

Change-Id: Id1b66e4f3f30f307dba70cb111c7571762cb546a
2021-03-15 13:50:49 +00:00
Paul Duffin 4fced5582d Support test fixtures in dexpreopt package
The tests in dexpreopt are unit tests that don't require the use of
test fixtures but there are a number of tests in java and apex packages
that need to configure dexpreopt behavior so this changes adds support
for modifying the dexpreopt configuration in test fixtures.

Bug: 181070625
Test: m nothing
Change-Id: I7b64c9cf0a94cc548c27b55c5a7875be5ff0e18d
2021-03-10 10:13:09 +00:00
Nicolas Geoffray b4f9d5c837 Merge "Stop using '&' for class loader context." 2021-03-08 11:16:09 +00:00
Nicolas Geoffray 863f3b9fb4 Stop using '&' for class loader context.
Test: m
Bug: 132357300
Change-Id: I01a5008d5b84820f793c1c23fe2e4c4687cf4acf
2021-03-05 18:14:10 +00:00
Ulya Trafimovich 4a13acb07d Use compiler filter "verify" for dexpreopt w/o class loader context.
In cases when class loader context cannot be computed at build time and
verify_uses_libraries check is relaxed (RELAX_USES_LIBRARY_CHECK=true)
dexpreopt uses a special compiler filter that suppresses AOT-compilation
to native code and applies only those optimizations that do not require
class loader context. Previously the "extract" filter was used. Now ART
supports using "verify" filter in this configuration.

Bug: 132357300
Test: lunch cf_x86_64_phone-userdebug && m && launch_cvd \
      adb wait-for-device && adb root && adb logcat \
      | grep -E 'ClassLoaderContext [a-z ]+ mismatch'
      # empty grep output, no errors
Change-Id: Id4933aa94ea96894278355283383c16d103e98c9
2021-03-02 12:32:23 +00:00
Ulya Trafimovich 8c35fcf4d5 Add non-fatal mode for verify_uses_libraries check.
The new mode is enabled with environment variable
RELAX_USES_LIBRARY_CHECK. If the variable is set to true, then a
verify_uses_libraries check failure does not fail the build, instead it
sets a special compiler filter "extract" for dexpreopt, which means that
the DEX file will be extracted, but it won't be compiled to native code.
Class loader context will be set to empty in this case (not &, as it is
going to be deprecated soon).

If the variable RELAX_USES_LIBRARY_CHECK is unset or set to something
other than "true", then the old behaviour of the verify_uses_libraries
check is preserved.

The intended use case for this flag is to have a smoother migration path
for the Java modules that need to add <uses-library> information in
the build files. The flag allows to quickly silence build errors. This
flag should be used with caution and only as a temporary measure, as it
masks real errors and affects performance.

verify_uses_libraries check is reworked so that it writes the error
message to a status file (which is used instead of the former timestamp
file). Currently the stored error message is not used, but it may be
used later to produce a warning. Dexpreopt command checks if the status
file exists and is nonempty; if that is the case, then compiler filter
is set to "extract".
Bug: 132357300

Test: Manually add some mismatch between the libraries in the Android.bp
      and Android.mk files for dexpreopted apps, build with
      RELAX_USES_LIBRARY_CHECK=true and obsserve that the build doesn't
      fail and they are compiled with compiler-filter "extract".
      Unset RELAX_USES_LIBRARY_CHECK and observe that the build fails.

Change-Id: Ibb5d993a25b1df1d2e70b7d5aafc6997f9d64e67
2021-02-22 15:41:03 +00:00
Ulya Trafimovich 65556a87d3 Preserve <uses-library> order in dexpreopt.config files.
Library order is important because it is used to construct class loader
context, which is then written into OAT/ODEX files and chacked against
class loader context constructed by PackageManager on the device. If the
orders are different, dexpreopted code is rejected.

Soong avoids using Go maps for class loader context representation
precisely for that reason. However, for the modules defined in makefiles
dexpreopt configs were serialized to JSON and unmarshaled to Go maps,
which resulted in wrong order of libraries. This CL changes Go
representation of class loader contexts imported from JSON and makes the
order stable.

Bug: 132357300
Test: lunch cf_x86_64_phone-userdebug && m && launch_cvd \
      adb wait-for-device && adb root && adb logcat \
      | grep -E 'ClassLoaderContext [a-z ]+ mismatch'
      # empty grep output, no errors
Change-Id: I15f51617f9573c0bbcb324cf2592daf719cad586
2021-02-11 16:58:51 +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
Ulyana Trafimovich a4fce3b488 Merge "Write module dexpreopt.config for Make." 2021-02-01 10:16:57 +00:00
Ulya Trafimovich 76b0852a48 Write module dexpreopt.config for Make.
This is needed for Java libraries that are <uses-library> dependencies
of Java libraries and apps defined as Make modules. Each dexpreopted
module in Make generates a dexpreopt.config file, which incorporates
information from its dependencies' dexpreopt.config files. For
dependencies that are Make modules their dexpreopt.config files are
generated by Make, and for Soong modules they are generated by Soong.
Since Soong doesn't know which libraries are used by Make, it generates
build rules for a superset of the necessary libraries.

Bug: 132357300
Test: lunch aosp_cf_x86_phone-userdebug && m
Change-Id: I325b1037658736ee3c02450b08c00eca1a175962
2021-01-28 06:29:13 +00:00
Paul Duffin 4c183c7581 Merge "Make dexpreopt tools available for all java tests" 2021-01-26 12:08:30 +00:00
Paul Duffin 635aa0834f Make dexpreopt tools available for all java tests
Bug: 177892522
Test: m nothing
Change-Id: I594bddae692ef76dc8c3da504934d0151b13d4c9
2021-01-25 19:15:19 +00:00
Ulyana Trafimovich 27878ca164 Merge "Use tree representation for class loader context in Make." 2021-01-25 14:32:23 +00:00
Ulya Trafimovich 5ec688962c Use tree representation for class loader context in Make.
Previously Make class loader contexts used a simplified one-level map.
Now they use the same tree representation as in Soong. The difference
between Make and Soong represenataions is insubstantial and caused only
by the language differences between JSON and Go.

Bug: 132357300
Test: lunch aosp_cf_x86_phone-userdebug && m
Change-Id: Ia273afb7f026dbe3b25d4327d55143657b026b98
2021-01-22 12:00:32 +00:00
Paul Duffin 9f04524673 Allow createGlobalSoongConfig() to be used from tests
Previously, the createGlobalSoongConfig() function was explicitly
prevented from being used in tests because it would fail. However, it
turns out that is no longer the case and it does now work.

That allows the following changes to be made:
* Tests no longer need to use GlobalSoongConfigForTests() to
  prepopulate the cache.
* GlobalSoongConfigForTests() is only needed in the dexpreopt
  package.

Bug: 177892522
Test: m nothing
Change-Id: Ifcbb1a44254c5d2d10c1d02ab23227488d1d1ed1
2021-01-21 15:44:30 +00:00
Nicolas Geoffray 324234bd00 Merge "dexpreopt: Use the dirty-image-objects path from frameworks/base." 2021-01-20 18:13:20 +00:00
Nicolas Geoffray 1086e604b9 dexpreopt: Use the dirty-image-objects path from frameworks/base.
Test: m
Bug: 176171716
Change-Id: Ifbc08ae03e2b1bec7161948970bd197386e3b305
2021-01-20 14:31:32 +00:00
Ulya Trafimovich a4a1c4ee98 Support building boot images with disabled dexpreopt.
Bug: 176171716
Test: build_mainline_modules.sh and ensure that the ART boot image is
    built: `find out -type f -name '*.art'` is nonempty for every arch.
Change-Id: Ibc45581eef2b205c750a30709780cf659ba7cfa1
2021-01-20 14:03:07 +00:00
Ulya Trafimovich 7bc1cf508f Remove obsolete class loader context API and update unit tests.
The removed API has been unused since https://r.android.com/1533342
(except for unit tests).

Changes in the unit tests reflect the change of API in
https://r.android.com/1533342: early errors caused by unknown library
paths at CLC construction time have been replaced with late errors at
the time of CLC validation.

Bug: 132357300
Test: m nothing
Change-Id: I739c7c41b6f882b7e28cdd6acd05961d754d8687
2021-01-05 15:41:55 +00:00
Ulya Trafimovich c9f2b9494d Fix library order in class loader context to agree with PackageManager.
PackageManager adds compatibility libraries for different SDK versions
in descending order, and Soong should do the same.

Bug: 132357300

Test: lunch aosp_cf_x86_phone-userdebug && m \
  && launch_cvd \
  && adb wait-for-device \
  && adb logcat | grep -E 'ClassLoaderContext [a-z ]+ mismatch'

  [no messages "ClassLoaderContext classpath element mismatch"]

Change-Id: Ib1d981808ae4022b2c6e73f407a003e8b8e9c7d6
2020-12-23 18:22:26 +00:00
Ulya Trafimovich 88bb6f6342 Unify addition of class loader subcontext from dependencies.
Previously CLC construction was scattered across different module types
and dependency tags. This CL moves all logic to one function, which
handles all special cases. This will allow to simplify CLC API and
reduce the number of different ways in which CLC is constructed.

Previously some of the cases failed early (at the time when a library is
added to CLC) if the build/install paths were unknown. Other cases did
not fail early, but were validated later before CLC was used. Late
failures are necessary because some of the libraries with unknown paths
still have to be processed by manifest_fixer (which doesn't need library
paths), but they do not use dexpreopt (which needs library paths). This
CL removes the early failures (all paths are still validated later).

The CLC tests do not fail because they use a private method that toggles
the "strict" flag (that enforces early/late failure mode) manually in
the method call.

The CL also makes a functional change in the way CLC is constructed for
component libraries that have an OptionalImplicitSdkLibrary(), or
libraries that are disguised as SDK libraries via `provides_uses_lib`.
Previously such a component/disguised library X was added to its own CLC
as a sibling element of X's own <uses-library> dependencies, which
created incorrect CLC structure. Now this is handled by addCLCFromDep,
when X is processed as dependency and added as a top-level CLC element
with its sub-CLC properly nested under it.

Bug: 132357300
Test: lunch aosp_cf_x86_phone-userdebug && m
Change-Id: I6a512209b87b81d785875f10f76b21c81b2ed579
2020-12-21 22:16:21 +00:00
Ulyana Trafimovich 678ddb9d24 Merge changes I697a65e4,Iaac6aaf6
* changes:
  Do not propagate <uses-library> deps through static SDK component libs.
  Make error message more precise.
2020-12-07 10:01:40 +00:00
Ulya Trafimovich 78210f6c9b Make error message more precise.
Bug: 132357300
Test: m nothing
Change-Id: Iaac6aaf61a3bbf8476f0b11cf2c01d7d96a79920
2020-12-02 13:06:47 +00:00
Colin Cross f1a035e6be Pass pctx and ctx to NewRuleBuilder
Enable the RuleBuilder and RuleBuilderCommand methods to access
the BuilderContext by passing it to NewRuleBuilder instead of
RuleBuilder.Build.

Test: genrule_test.go
Test: rule_builder_test.go
Test: m checkbuild
Change-Id: I63e6597e19167393876dc2259d6f521363b7dabc
2020-12-01 16:22:16 -08:00
Ulya Trafimovich 480d174a16 Documenting dexpreopt/class_loader_context.go.
Test: m nothing
Bug: 173092919
Change-Id: Iec64d7449a66b45be547e0d42bb3808215750cd1
2020-11-27 18:10:22 +00:00
Ulya Trafimovich 78a7155c17 Assume any <uses-library> is shared, add only toplevel ones to manifest.
This patch reworks the approach introduced in
https://r.android.com/1450819. That patch based the decision which
libraries should be added to the manifest <uses-library> tags by the
manifest_fixer on the "shared" status of the library.

That approach is incorrect for two reasons:

  - It doesn't make sense to have a non-shared library in class loader
    context ("shared" libraries are those specified in
    frameworks/base/data/etc/platform.xml, and they are the only ones
    that PackageManager knows about).

  - It doesn't make sense to add anything but the top-level of the
    class loader context tree to the manifest, because this part of the
    tree is flattened to a sequence, and PackageManager cannot restore
    it to the previous tree shape (there is an information loss).

This patch removes the "shared" bit of information from class loader
context elements and assumes that all libraries that end up in class
loader context are shared. Consequently, only the top-level libraries
should be passed to manifest_fixer.

Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Bug: 168686456
Change-Id: I902690f0f38f1047fa79cf6ccbe956077eceaab0
2020-11-25 14:47:05 +00:00
Ulyana Trafimovich d8d8e726a5 Merge changes Iebfbf2ff,Ibd974268
* changes:
  Rename fields and methods to reflect class loader context changes.
  Do not add dependencies of shared SDK libraries to manifest_fixer.
2020-11-17 10:22:00 +00:00
Colin Cross 1af783fae7 Merge "Replace android.WriteFile rule with android.WriteFileRule" 2020-11-16 23:11:41 +00:00
Ulya Trafimovich a8c28e27bc Do not add dependencies of shared SDK libraries to manifest_fixer.
Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Bug: 168686456
Change-Id: Ibd9742684fa6a8f1353ca0e513f7fa814a6ec9fc
2020-11-16 14:58:11 +00:00
Ulya Trafimovich 18554243de Add nested class loader subcontext at the proper hierarchy level.
When adding a subcontext in a class loader context tree, there are two
possible cases: 1) the root of the subcontext is itself a <uses-library>
and should be present as a node in the tree, or 2) the root is not a
<uses-library>, but some of its dependencies are -- in that case they
should be disconnected from the root, and the resulting forrest should
be added at the top-level.

Example:

  1) C is a <uses-library>:

     A
     ├── B
     └── C
         ├── D
         └── E
             └── F

  2) C is not a <uses-library>:

     A
     ├── B
     ├── D
     └── E
         └── F

Before the patch subcontexts for transitive dependencies were added
before the subcontext for the direct dependency (even if it was a
<uses-library>, resulting in case-2 hierarchy when case-1 should have
been used. Previosuly this didn't matter because class loader context
was a flat set of libraries, but now it matters because class loader
context is a tree.

This patch changes the order in which libraries are added, so that
direct dependencies are added before transitive ones. The context adding
method now accepts an "implicit root" parameter, so that when adding
transitive dependencies it can check if the corresponding direct
dependency is a <uses-library> and already present in the context.

Partially constructed class loader context is now propagated top-down
into aapt.buildActions, so that the method can use existing part of the
context to decide where the missing part should be connected.

Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Change-Id: I649aff9e27494306885a4f4fc90226c399636b57
2020-11-16 14:57:05 +00:00
Ulya Trafimovich 5e13a7307e Disallow adding nested conditional class loader context.
Nested conditional context doesn't make sense because conditional
context is only needed for compatibility libraries, and those are only
used by apps, and apps are always at the root of class loader context
tree. Therefore, trying to add conditional nested context can only mean
an error somewhere on the way.

Test: lunch aosp_cf_x86_phone-userdebug && m
Bug: 132357300
Change-Id: Iadeaaf89fdb11cb23b107c6fb074b1bc765256be
2020-11-16 12:17:30 +00:00