Commit graph

36 commits

Author SHA1 Message Date
Paul Duffin
ec0fe1775b Avoid hiddenapi ignoring prebuilt with missing dex implementation jar
Previously, when a prebuilt was preferred but did not provide a
suitable boot dex jar both the source and the prebuilt were silently
ignored which meant that the "hiddenapi list" command was not given a
complete set of boot dex jars. That could either lead to incorrect
hiddenapi flags being set or the "hiddenapi list" command failing if it
could not find a class. Debugging the cause of either of those cases
can be very time consuming so this change fails early and makes the
cause very explicit.

Bug: 181267622
Test: m nothing
Change-Id: I6763ddb9ba90ed2e501d0cf7984f6655237e905d
2021-03-01 12:58:28 +00:00
Paul Duffin
2c36f24082 Sort hiddenapi monolithic files by signature
Adds a new --key_field option to merge_csv.py which specifies the name
of the field that should be used to sort the input. If specified it
causes that field to be the first in each row and performs the merge
operation of a merge sort on the input files. That assumes that each
input file is already sorted into the same order.

Modifies the rules that use merge_csv.py to pass in:
    --key_field signature
to sort the rows by signature.

Bug: 180387396
Test: Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change other than
      changing the order.
Change-Id: Idcd5f0fea373b520b604889e1c280f21ed495660
2021-02-16 17:38:08 +00:00
Paul Duffin
82b3fcf123 Remove duplicates in monolithic hidden API files
Previously, multiple APEX variants of some boot jars were being
processed by hiddenapi to extract information which resulted in
duplicate entries in the monolithic hidden API files.

This change applies the same filter that was previously used to ensure
that the hiddenapi-flags.csv file did not include any duplicates to all
sources of hidden API information.

Bug: 180102243
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change other than
      removing some duplicates entries.
Change-Id: I9ffc8586d5d6efea4e3440be2dfd5424790665c8
2021-02-16 13:28:26 +00:00
Paul Duffin
f8f4af8f1a Remove implicit dependency from <x> -> <x>-hiddenapi
It can be removed as all implicit dependencies have been replaced with
explicit ones so it is no longer needed.

Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
Change-Id: I3da5fcb3b244a295502f2cacc94a504250d4d616
2021-02-16 13:28:26 +00:00
Paul Duffin
031d8693b3 Allow explicitly specified additional annotations for hiddenapi
Adds the hiddenapi_additional_annotations to allow a library to list
the libraries that provided additional hiddenapi related annotations
for a library.

Modifies merge_csv.py so it can process multiple zip files at the same
time and uses that to merge the embedded .uau files from a module and
those it depends upon.

Bug: 180102243
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
Change-Id: I796520021c7357398a9e2a09f1029e4a578b05b3
2021-02-16 13:28:26 +00:00
Paul Duffin
f75e527c2b Move logic for selecting the primary module into initHiddenAPI()
Bug: 178361284
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
      Also verified that the hiddenapi files created when using the
      prebuilts (using SOONG_CONFIG_art_module_source_build=false) are
      the same as when using the source. There is a slight difference
      in the order but otherwise identical.
Change-Id: I831da5fa41eb7668b07bbdc4dd08ec2cdb8803d0
2021-02-11 15:43:28 +00:00
Paul Duffin
9d67ca6ab7 Allow dex jars from prebuilt_apex to be used by hiddenapi
Invokes hiddenAPIExtractInformation() on the dex jar provided by the
deapexer (on behalf of prebuilt_apex) so that hiddenAPI can extract the
information it needs, if anything, from the dex file (and accompanying
classes implementation file).

The dex file provided by deapexer has already had the hiddenapi
information encoded into it so it does not need to do that again.

This change adds the primary parameter to hiddenAPIExtractInformation()
and checks it (and also the hiddenAPI.active property) before it does
anything. That ensures that it behaves correctly when called directly
as well as when called from hiddenAPIExtractAndEncode().

Bug: 178361284
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
      Also verified that the hiddenapi files created when using the
      prebuilts (using SOONG_CONFIG_art_module_source_build=false) are
      the same as when using the source. There is a slight difference
      in the order but otherwise identical.
Change-Id: I7abb63fd310bb94787ab7f4821e5fd283dc03046
2021-02-08 19:10:50 +00:00
Paul Duffin
4fd997bc13 Refactor the hiddenAPI() method for reusability
A follow up change needs to be able to contribute to the information
the hiddenapi process collates without having a dex file encoded. This
change pushes all the functionality related to information gathering
into the hiddenAPIGenerateCSV() method and then renames it and the
hiddenAPI() method to make it clearer what they do.

Bug: 178361284
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
Change-Id: I04417720216a0fbadcd88e6185e7de6570af6216
2021-02-08 19:10:50 +00:00
Paul Duffin
4103e92c4b Extract initHiddenAPI() from hiddenapi()
Previously, the hiddenapi() method combined both checks to determine
whether a module contributed to/was modified by the hiddenapi process
and logic to create ninja rules to perform those tasks. This change
separates the former out into a new initHiddenAPI() method.

The main purpose of this is to simplify the process of allowing the
CSV generation to be separated from the encoding. That is required
because when a java_import retrieves its dex file from the apex it
has already been encoded.

The initHiddenAPI() method is only called for java.Library (and
indirectly for java.SdkLibrary) and java.Import modules which means
that the hiddenapi() method does nothing for any other module type.
That is consistent with the previous behaviour because while the
hiddenapi() method is called for other module types they fail because
the boot image jars only support java_library, java_sdk_library,
and java_import at the moment. While it will need to support
java_sdk_library_import once any of the libraries that are currently
provided as java_sdk_library modules switches to providing prebuilts
that is outside the scope of this work.

Bug: 178361284
Test: m droid
      Verified that hiddenapi files (both aggregated ones and for the
      individual modules) are not affected by this change.
Change-Id: Iaa91e0a8e2bffec03296dd894e9662556f4464c0
2021-02-08 19:10:50 +00:00
Paul Duffin
219b177279 Remove duplicate entries from hiddenapi files
Prevents the hiddenapi files index and metadata files from including
duplicate entries.

Bug: 178361284
Test: m droid
      Compared hiddenapi files before and after change
      Verified that the only differences were due to the removal of duplicates
      Used sort -u to remove duplicates from before file and compared with after file
Change-Id: I0b9e420aec42cdcf4584099a7ffd2ed9c3715d6d
2021-02-07 10:58:24 +00:00
Paul Duffin
612e610063 Switch hiddenapi to use OutputPath instead of ModuleOutPath
In order to allow the hiddenapi code which expects its inputs to be
ModuleOutPath to consume the output from the deapexer module type (used
by prebuilt_apex) this change converts the hiddenapi from using
ModuleOutPath to use OutputPath instead.

This is part of a general cleanup to remove ModuleOutPath that is
separated out in order to avoid having the hiddenapi work dependent
upon and possibly delayed by issues with that general cleanup.

Bug: 178361284
Bug: 179124768
Test: m droid
Change-Id: I890f775bf5e33528dbaa62b95fa4198185ff8bf8
2021-02-02 14:42:05 +00:00
Paul Duffin
34982f1096 Move creation of paths into hiddenAPIGenerateCSV
A minor refactoring to simplify the generation of the CSV files.

Test: m nothing
Bug: 178361284
Change-Id: If79d21c7cebc6643a404973d3e0e5f174d7b0bb1
2021-01-29 13:22:31 +00:00
Paul Duffin
ff774a04ad Add documentation for the different files created by hiddenapi
Test: m nothing
Bug: 178361284
Change-Id: Id55646b9d4b7bc1acdb4ed6a6dd4456b746eb54c
2021-01-29 13:19:51 +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
Andrei Onea
23fea04e27 Rename class2greylist
Use a more inclusive name (go/hiddenapi-list-renaming).
Bug: 163797539
Test: atest class2nonsdklisttest

Change-Id: I1b72c243746dde9926a11d5a559b84e753e8fd4f
2020-08-13 17:33:14 +01:00
Colin Cross
d783bbbace Use unzip -DD
We put reproducible timestamps in zip files so that the artifacts
are consistent, but that leads to old timestamps in the output
directory if they are unzipped as part of the build.  Use
unzip -DD when unzipping to update the timestamps.

Bug: 161015009
Test: touch -d 2020-01-01 ref; find $OUT/system -not -newer ref
Change-Id: I70407a627cb070e24be510faa6a774e3d9eae3a8
2020-07-12 05:37:46 +00:00
Paul Duffin
a2058f8b7d Apply hiddenapi encoding to java_sdk_library .impl
Adds a ConfigurationName property, and ConfigurationName() method that
allows a library to separate its name (e.g. framework-tethering.impl)
from the name used in the build configuration,
    e.g. ctx.Config().BootJars().

Updates hiddenapi processing to use ConfigurationName() instead of
ctx.ModuleName().

Changes java_sdk_library to set the ConfigurationName property
of the implementation library to the name of the module instead of
<module>.impl so that it will match the name in the boot jars list.

Bug: 159683330
Test: m framework-tethering
      dexdump ${PRODUCT_OUT}/apex/com.android.tethering/javalib/framework-tethering.jar | grep hiddenapi | wc -l
      Verify that there are >0 hiddenapi entries.
      Add java_sdk_library_import prefer=true for framework-tethering
      and repeat the above to verify that there are 0 hiddenapi entries.
      Apply this change, repeat above and verify that there are the same # of entries as before.
      Remove the prebuilt for framework-tethering
      Repeat the above and verify that there is no change to the # of entries
Merged-In: I6c3016c35d0fcb1b95d4f9b37a307a69878f8e0a
Change-Id: I6c3016c35d0fcb1b95d4f9b37a307a69878f8e0a
(cherry picked from commit c4422106a7)
2020-06-29 19:05:19 +01:00
Paul Duffin
c495d2bfed Add --no-force-assign-all for java_sdk_library
Previously, the flag was only added for java_library modules that were
being instrumented. This will also add if for java_sdk_library modules
too.

Bug: 156705688
Test: TARGET_BUILD_VARIANT=userdebug PRODUCT=mainline_modules_x86 EMMA_INSTRUMENT=true NATIVE_COVERAGE=true ./vendor/google/build/build_unbundled_coverage_mainline_module.sh -j8
Merged-In: I5d06ec037007b1770748df24a2e2e8691f177f4f
Change-Id: I5d06ec037007b1770748df24a2e2e8691f177f4f
(cherry picked from commit 31b84c83bf)
2020-05-20 08:19:56 +01:00
Jiyong Park
139fa4320f Merge changes Ibaf383c4,I2b1c0736
* changes:
  Expect added members for instrumented modules
  Reland "Turn on the instrumentation by default for the java code in APEXes"
2020-02-25 07:02:33 +00:00
Jiyong Park
93e57a0b86 Expect added members for instrumented modules
hiddenapi expects that all members in a class to have corresponding hidden
API flags. However, this can't be satisfied when the java module having
the class is instrumented; JaCoCo added a few number of synthetic
members. In this case, give 'no-force-assign-all' option to the hidden
api tool so that it doesn't complain about the synthetic methods.

Also, disabling instrumenting jacocoagent itself, because it doesn't
make sense.

Exempt-From-Owner-Approval: PS3 fixes a typo in a comment. PS2 got ORV.

Bug: 149353192
Test: SKIP_ABI_CHECKS=true EMMA_INSTRUMENT=true
EMMA_INSTRUMENT_FRAMEWORK=true SKIP_BOOT_JARS_CHECK=true m
out/soong/.intermediates/external/apache-xml/apache-xml/android_common_com.android.art.debug/hiddenapi/unaligned/unaligned.jar
Change-Id: Ibaf383c439945ab664e885af319548b56e2c8cb6
2020-02-25 07:01:18 +00:00
Artur Satayev
b5df8a04ad Merge CSV files generated by UnsupportedAppUsageProcessor.
Flow:
1. Annotation processor generates a CSV file per class as a CLASS_OUTPUT resource.
2. hiddenapi.go extracts individual .csv files and merges them into an index.csv file per module.
3. hiddenapi_singleton.go merges individual index.csv files into a combined .csv file.

In a follow up hiddenapi-index.csv would replace unsupportedappusage_index.csv

Bug: 145132366
Change-Id: I87d92f9c8d4b1cc1df526fc576ee3c2101116b58
Test: diff unsupportedappusage_index.csv hiddenapi-index.csv
2020-02-20 20:21:49 +00:00
Paul Duffin
d2acecaeb7 Improve hiddenapi processing so it does not require white list
Rather than have a special white list to contain the names of modules
that provide additional hiddenapi for modules on the bootclasspath
this defines a convention that such modules must have a name which is
of the format <x>-hiddenapi, where <x> is the name of the module on the
bootclasspath.

Bug: 73711752
Test: make droid && flashall -w && atest -p cts/tests/signature
Change-Id: Ib2d69dea9541b60a9bb81496f00edb65036d1ebb
2019-02-28 16:13:20 +00:00
Paul Duffin
c02e834ad6 Revert "Support libraries (not just boot jars) that have hiddenapi"
This reverts commit e5b5657f87.

The reverted change was added in order to gather the information about
the hiddenapi that is needed for the runtime to enforce the hiddenapi
accessibility rules. Without it the build broke with the following
error when the android.test.base library was not in the
PRODUCT_BOOT_JARS list:

AssertionError: Error processing: frameworks/base/config/hiddenapi-greylist.txt
The following entries were unexpected:
  Ljunit/framework/TestSuite;->isPublicTestMethod(Ljava/lang/reflect/Method;)Z
  Landroid/test/AndroidTestCase;->setTestContext(Landroid/content/Context;)V
  Landroid/test/InstrumentationTestCase;->runMethod(Ljava/lang/reflect/Method;I)V
  Landroid/test/AndroidTestCase;->getTestContext()Landroid/content/Context;
  Ljunit/framework/TestCase;->fName:Ljava/lang/String;
  Ljunit/framework/TestSuite;->isTestMethod(Ljava/lang/reflect/Method;)Z
  Please visit go/hiddenapi for more information.

However, it turns out that the runtime does not currently enforce
access to the hiddenapi of libraries that are not on the
PRODUCT_BOOT_JARS list. Gathering hiddenapi information for a library
not on the PRODUCT_BOOT_JARS list breaks the
CtsHiddenApiBlacklistApi27TestCases and
CtsHiddenApiBlacklistApi28TestCases test modules which use that
information to ensure that correct runtime behavior.

This change is being reverted simply because it does not work.

Bug: 126519737
Bug: 73711752
Test: make REMOVE_ATB_FROM_BCP=true droid and make droid
Change-Id: I1b4a7786b1061effa0e2d37832afa8570953a06e
2019-02-27 12:49:21 +00:00
Colin Cross
69f59a3327 Make RuleBuilder methods take Paths
There are no more Make paths being used in Soong now that
dexpreopting and hiddenapi are in Soong. Use the Path types
in the inputs to RuleBuilder, and fix all users of RuleBuilder.

This reapplies I886f803d9a3419a43b2cae412537645f94c5dfbf with
fixes to disable preopt for Soong-only builds when the global
dexpreopt.config doesn't exist.

Test: all soong tests
Test: m checkbuild
Change-Id: I4dae9ecd5de22f062f9478ec8f0747f099cf8190
2019-02-20 22:06:09 -08:00
Colin Cross
ab898dc4a4 Revert "Make RuleBuilder methods take Paths"
This reverts commit acdd694071.

Reason for revert: broke ndk build

Change-Id: I5655e48c15eb8f5f0267afdd853fbc25765b8623
2019-02-21 05:03:00 +00:00
Colin Cross
acdd694071 Make RuleBuilder methods take Paths
There are no more Make paths being used in Soong now that
dexpreopting and hiddenapi are in Soong. Use the Path types
in the inputs to RuleBuilder, and fix all users of RuleBuilder.

Test: all soong tests
Test: m checkbuild
Change-Id: I886f803d9a3419a43b2cae412537645f94c5dfbf
2019-02-20 14:23:37 -08:00
Paul Duffin
e5b5657f87 Support libraries (not just boot jars) that have hiddenapi
The build assumes (apart from one minor exception) that only modules
that are in the PRODUCT_BOOT_JARS list require processing as part of
the hiddenapi. Unfortunately, that is not true for android.test.base,
at least not when REMOVE_ATB_FROM_BCP=true.

This change adds a white list (containing android.test.base) of
additional modules that should be processed as part of the hiddenapi
and updates the hiddenapi.go file to use it.

It does not matter that android.test.base is a boot jar and in the
white list, the behavior is the same as it would be if it was only
in one.

Bug: 73711752
Test: make REMOVE_ATB_FROM_BCP=true droid and make droid
Change-Id: I1c64272f444e6866136c65fb7c48910d55811844
2019-02-15 14:35:30 +00:00
Colin Cross
f24a22a98a Move hiddenapi singleton rules to Soong
Move the rules that build hiddenapi-stubs-flags.txt,
hiddenapi-flags.csv and hiddenapi-greylist.csv into Soong.

Bug: 123645297
Test: m checkbuild
Test: m UNSAFE_DISABLE_HIDDEN_API_FLAGS=true
Change-Id: I90bf58710f6153ee8565994f799d3ec5699bc7fa
2019-02-06 11:23:40 -08:00
Colin Cross
571cccfcbc Prepare for a type-safe OnceKey
Add an opaque OnceKey type and use it for all calls to Once in
build/soong.  A future patch will convert the arguments to
Once* to OnceKey once users outside build/soong have been updated.

Test: onceper_test.go
Change-Id: Ifcb338e6e603e804e507203c9508d30ffb2df966
2019-02-06 01:52:41 +00:00
Colin Cross
feec25b084 Move dexpreopt.Script to android.RuleBuilder
Move dexpreopt.Script to android.RuleBuilder so that the builder
style can be used in more places.  Also add tests for it.

Test: rule_builder_test.go
Change-Id: I92a963bd112bf033b08899e930094b908acfcdfd
2019-02-05 13:28:43 -08:00
David Brazdil
91b4e3e78b Disable all-assigned check in hiddenapi on master-art
Master-art configurations do not have frameworks/base and therefore do
not have hidden API flags. Pass --no-force-assign-all to `hiddenapi`
when frameworks/base does not exist to disable the corresponding
assertion. This enables us to enforce the assertion on non-master-art
builds and also get rid of logspam about missing flags on ART buildbots.

Test: art/tools/buildbot-build.sh on master-art
Bug: 123143676
Change-Id: I074d9554fb11dab3eef904016375730520107ec2
2019-01-23 22:55:41 +00:00
Nicolas Geoffray
65fd8ba2fe Always do zipalign with uncompressDex.
Also preserve the alignment with hiddenapi.

Test: conscrypt apex has its conscrypt.jar zipaligned.
Change-Id: I43cc0eadb9548c3d8055e12c077fb7bbe1935fe6
2019-01-23 06:36:48 +00:00
David Brazdil
0f670a22df Replace hiddenapi-{public,private}-list.txt with a CSV file
`hiddenapi` is being refactored to work with a single CSV file as
opposued to a multitude of text files (one per flag). This patch
changes the singleton rule for listing public/private APIs from
stubs to expect a CSV as an output.

Bug: 119068555
Test: compiles, hiddenapi-flags.csv unchanged
Change-Id: I622521d59979a6b01ecc8065a278412fedf7b9bc
2019-01-21 14:30:49 +00:00
Colin Cross
cd964b3ea1 Maintain uncompressed dex through hiddenapi encode
hiddenapi encode unzips and rezips the dex jar.  Pass uncompressDex
into it so that it doesn't make classes.dex compressed in the dex
jar when it was previously uncompressed.

Bug: 123100239
Test: m checkbuild
Test: zipinfo $OUT/system/framework/conscrypt.jar shows uncompressed classes.dex
Change-Id: If36cde330eb0bcb1e1db3c582452c5faebc8ff29
2019-01-19 06:10:00 +00:00
David Brazdil
9fc36a68d0 Restore UNSAFE_DISABLE_HIDDENAPI_FLAGS functionality.
It got broken with the move to hiddenapi to Soong.

Test: UNSAFE_DISABLE_HIDDENAPI_FLAGS=true m -j32
Change-Id: Id369bfae8e118907b1f12faa7e4207494904edda
2019-01-18 11:12:33 +00:00
Colin Cross
8faf8fc060 Move hiddenapi to Soong
Perform hiddenapi CSV generation and dex encoding for Soong modules
in Soong.  This fixes an issue where dexpreopting was happening on
a different jar than was being installed.

Bug: 122856783
Test: m checkbuild
Test: no change out/target/common/obj/PACKAGING/hiddenapi-flags.csv
Test: only ordering change to out/target/common/obj/PACKAGING/hiddenapi-greylist.csv
Test: cts/tests/signature/runSignatureTests.sh
Change-Id: I4fc481efc29e73cb2bdaacf672e86d5f6f0075ae
2019-01-17 22:19:28 +00:00