blob: 6b433c93d1a9699d1c4856bfe01b11806515e076 [file] [log] [blame]
Joe Onoratofee845a2023-05-09 08:14:14 -07001// Copyright 2023 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
Joe Onorato981c9262023-06-21 15:16:23 -070015package aconfig
Joe Onoratofee845a2023-05-09 08:14:14 -070016
17import (
18 "android/soong/android"
19 "github.com/google/blueprint"
20)
21
22var (
Joe Onorato981c9262023-06-21 15:16:23 -070023 pctx = android.NewPackageContext("android/soong/aconfig")
Joe Onoratofee845a2023-05-09 08:14:14 -070024
Joe Onorato981c9262023-06-21 15:16:23 -070025 // For aconfig_declarations: Generate cache file
Joe Onoratofee845a2023-05-09 08:14:14 -070026 aconfigRule = pctx.AndroidStaticRule("aconfig",
27 blueprint.RuleParams{
28 Command: `${aconfig} create-cache` +
Joe Onorato81b25ed2023-06-21 13:49:37 -070029 ` --package ${package}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070030 ` --declarations ${in}` +
31 ` ${values}` +
32 ` --cache ${out}.tmp` +
33 ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
34 // ` --build-id ${release_version}` +
35 CommandDeps: []string{
36 "${aconfig}",
37 },
38 Restat: true,
Joe Onorato81b25ed2023-06-21 13:49:37 -070039 }, "release_version", "package", "values")
Joe Onoratofee845a2023-05-09 08:14:14 -070040
Joe Onorato981c9262023-06-21 15:16:23 -070041 // For java_aconfig_library: Generate java file
Joe Onoratofee845a2023-05-09 08:14:14 -070042 srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
43 blueprint.RuleParams{
44 Command: `rm -rf ${out}.tmp` +
45 ` && mkdir -p ${out}.tmp` +
46 ` && ${aconfig} create-java-lib` +
47 ` --cache ${in}` +
48 ` --out ${out}.tmp` +
49 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
50 ` && rm -rf ${out}.tmp`,
51 CommandDeps: []string{
52 "$aconfig",
53 "$soong_zip",
54 },
55 Restat: true,
56 })
57)
58
59func init() {
60 registerBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -070061 pctx.HostBinToolVariable("aconfig", "aconfig")
62 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -070063}
64
65func registerBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -070066 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
67 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
68 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
69 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -070070}