xref: /aosp_15_r20/frameworks/base/tools/aapt2/Android.bp (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1//
2// Copyright (C) 2017 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//
16
17package {
18    default_applicable_licenses: ["Android-Apache-2.0"],
19}
20
21toolSources = [
22    "cmd/ApkInfo.cpp",
23    "cmd/Command.cpp",
24    "cmd/Compile.cpp",
25    "cmd/Convert.cpp",
26    "cmd/Diff.cpp",
27    "cmd/Dump.cpp",
28    "cmd/Link.cpp",
29    "cmd/Optimize.cpp",
30    "cmd/Util.cpp",
31]
32
33cc_defaults {
34    name: "aapt2_defaults",
35    cpp_std: "gnu++2b",
36    cflags: [
37        "-Wall",
38        "-Werror",
39        "-Wno-unused-parameter",
40    ],
41    cppflags: [
42        "-Wno-missing-field-initializers",
43        "-fno-exceptions",
44        "-fno-rtti",
45        "-Wno-deprecated-declarations",
46    ],
47    target: {
48        windows: {
49            compile_multilib: "64",
50            enabled: true,
51            cflags: ["-Wno-maybe-uninitialized"],
52            ldflags: ["-static"],
53        },
54        darwin: {
55            cflags: ["-D_DARWIN_UNLIMITED_STREAMS"],
56        },
57    },
58    header_libs: [
59        "jni_headers",
60        "native_headers",
61    ],
62    static_libs: [
63        "libandroidfw",
64        "libutils",
65        "liblog",
66        "libcutils",
67        "libexpat",
68        "libziparchive",
69        "libpng",
70        "libbase",
71        "libprotobuf-cpp-full",
72        "libz",
73        "libbuildversion",
74        "libidmap2_policies",
75    ],
76    stl: "libc++_static",
77}
78
79// ==========================================================
80// NOTE: Do not add any shared libraries.
81// AAPT2 is built to run on many environments
82// that may not have the required dependencies.
83// ==========================================================
84
85// ==========================================================
86// Build the host static library: aapt2
87// ==========================================================
88cc_library_host_static {
89    name: "libaapt2",
90    srcs: [
91        "compile/IdAssigner.cpp",
92        "compile/InlineXmlFormatParser.cpp",
93        "compile/PseudolocaleGenerator.cpp",
94        "compile/Pseudolocalizer.cpp",
95        "compile/XmlIdCollector.cpp",
96        "configuration/ConfigurationParser.cpp",
97        "dump/DumpManifest.cpp",
98        "filter/AbiFilter.cpp",
99        "filter/ConfigFilter.cpp",
100        "format/Archive.cpp",
101        "format/Container.cpp",
102        "format/binary/BinaryResourceParser.cpp",
103        "format/binary/ResChunkPullParser.cpp",
104        "format/binary/ResEntryWriter.cpp",
105        "format/binary/TableFlattener.cpp",
106        "format/binary/XmlFlattener.cpp",
107        "format/proto/ProtoDeserialize.cpp",
108        "format/proto/ProtoSerialize.cpp",
109        "io/File.cpp",
110        "io/FileSystem.cpp",
111        "io/StringStream.cpp",
112        "io/Util.cpp",
113        "io/ZipArchive.cpp",
114        "link/AutoVersioner.cpp",
115        "link/FeatureFlagsFilter.cpp",
116        "link/FlagDisabledResourceRemover.cpp",
117        "link/ManifestFixer.cpp",
118        "link/NoDefaultResourceRemover.cpp",
119        "link/PrivateAttributeMover.cpp",
120        "link/ReferenceLinker.cpp",
121        "link/ResourceExcluder.cpp",
122        "link/TableMerger.cpp",
123        "link/XmlCompatVersioner.cpp",
124        "link/XmlNamespaceRemover.cpp",
125        "link/XmlReferenceLinker.cpp",
126        "optimize/MultiApkGenerator.cpp",
127        "optimize/ResourceDeduper.cpp",
128        "optimize/ResourceFilter.cpp",
129        "optimize/Obfuscator.cpp",
130        "optimize/VersionCollapser.cpp",
131        "process/ProductFilter.cpp",
132        "process/SymbolTable.cpp",
133        "split/TableSplitter.cpp",
134        "text/Printer.cpp",
135        "text/Unicode.cpp",
136        "text/Utf8Iterator.cpp",
137        "util/Files.cpp",
138        "util/Util.cpp",
139        "Debug.cpp",
140        "DominatorTree.cpp",
141        "java/AnnotationProcessor.cpp",
142        "java/ClassDefinition.cpp",
143        "java/JavaClassGenerator.cpp",
144        "java/ManifestClassGenerator.cpp",
145        "java/ProguardRules.cpp",
146        "LoadedApk.cpp",
147        "Resource.cpp",
148        "ResourceParser.cpp",
149        "ResourceTable.cpp",
150        "ResourceUtils.cpp",
151        "ResourceValues.cpp",
152        "SdkConstants.cpp",
153        "trace/TraceBuffer.cpp",
154        "xml/XmlActionExecutor.cpp",
155        "xml/XmlDom.cpp",
156        "xml/XmlPullParser.cpp",
157        "xml/XmlUtil.cpp",
158        "ApkInfo.proto",
159        "Configuration.proto",
160        "Resources.proto",
161        "ResourceMetadata.proto",
162        "ResourcesInternal.proto",
163        "ValueTransformer.cpp",
164    ],
165    proto: {
166        export_proto_headers: true,
167        type: "full",
168    },
169    defaults: ["aapt2_defaults"],
170}
171
172// ==========================================================
173// Build the host tests: aapt2_tests
174// ==========================================================
175cc_test_host {
176    name: "aapt2_tests",
177    srcs: [
178        "test/Builders.cpp",
179        "test/Common.cpp",
180        "test/Fixture.cpp",
181        "**/*_test.cpp",
182    ] + toolSources,
183    static_libs: [
184        "libaapt2",
185        "libgmock",
186    ],
187    defaults: ["aapt2_defaults"],
188    data: [
189        "integration-tests/CompileTest/**/*",
190        "integration-tests/CommandTests/**/*",
191        "integration-tests/ConvertTest/**/*",
192        "integration-tests/DumpTest/**/*",
193        ":resource-flagging-test-app-apk",
194        ":resource-flagging-test-app-r-java",
195    ],
196}
197
198// ==========================================================
199// Build the host executable: aapt2
200// ==========================================================
201cc_binary_host {
202    name: "aapt2",
203    srcs: ["Main.cpp"] + toolSources,
204    use_version_lib: true,
205    static_libs: ["libaapt2"],
206    defaults: ["aapt2_defaults"],
207    dist: {
208        targets: ["aapt2_artifacts"],
209    },
210}
211
212// ==========================================================
213// Dist the protos
214// ==========================================================
215genrule {
216    name: "aapt2-protos",
217    tools: [":soong_zip"],
218    srcs: [
219        "ApkInfo.proto",
220        "Configuration.proto",
221        "ResourcesInternal.proto",
222        "ResourceMetadata.proto",
223        "Resources.proto",
224    ],
225    out: ["aapt2-protos.zip"],
226    cmd: "mkdir $(genDir)/protos && " +
227        "cp $(in) $(genDir)/protos && " +
228        "$(location :soong_zip) -o $(out) -C $(genDir)/protos -D $(genDir)/protos",
229    dist: {
230        targets: [
231            "sdk_repo",
232            "aapt2_artifacts",
233        ],
234    },
235}
236