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# Build the jars twice. First with applying hiddenapi, creating a boot jar, then
19# a second time without to create a normal jar. We need to do this because we
20# want to load the jar once as an app module and once as a member of the boot
21# class path. The DexFileVerifier would fail on the former as it does not allow
22# hidden API access flags in dex files. DexFileVerifier is not invoked on boot
23# class path dex files, so the boot jar loads fine in the latter case.
24
25
26def build(ctx):
27  if ctx.jvm:
28    return  # The test does not build on JVM
29  ctx.default_build(use_hiddenapi=True)
30
31  # Move the jar file into the resource folder to be bundled with the test.
32  os.mkdir(ctx.test_dir / "res")
33  os.rename(ctx.test_dir / "674-hiddenapi.jar", ctx.test_dir / "res/boot.jar")
34
35  # Clear all intermediate files otherwise default-build would either skip
36  # compilation or fail rebuilding.
37  ctx.bash("rm -rf classes*")
38
39  ctx.default_build(use_hiddenapi=False)
40