xref: /aosp_15_r20/art/test/817-hiddenapi/build.py (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1#
2# Copyright (C) 2022 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17
18
19def build(ctx):
20  if ctx.jvm:
21    return  # The test does not build on JVM
22
23  # Build the jars twice. First with applying hiddenapi, creating a boot jar, then
24  # a second time without to create a normal jar. We need to do this because we
25  # want to load the jar once as an app module and once as a member of the boot
26  # class path. The DexFileVerifier would fail on the former as it does not allow
27  # hidden API access flags in dex files. DexFileVerifier is not invoked on boot
28  # class path dex files, so the boot jar loads fine in the latter case.
29
30  ctx.default_build(use_hiddenapi=True)
31
32  # Move the jar file into the resource folder to be bundled with the test.
33  os.mkdir(ctx.test_dir / "res")
34  os.rename(ctx.test_dir / "817-hiddenapi.jar", ctx.test_dir / "res/boot.jar")
35
36  # Clear all intermediate files otherwise default-build would either skip
37  # compilation or fail rebuilding.
38  ctx.bash("rm -rf classes*")
39
40  ctx.default_build(use_hiddenapi=False)
41