blob: 37167aa5d3726614a441a4f38c9ef2a9aab4d368 [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}` +
Zhi Dou8a35a6f2023-07-19 18:04:24 +000030 ` ${declarations}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070031 ` ${values}` +
32 ` --cache ${out}.tmp` +
Zhi Dou9dc24512023-07-24 21:19:55 +000033 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
Joe Onoratofee845a2023-05-09 08:14:14 -070034 // ` --build-id ${release_version}` +
35 CommandDeps: []string{
36 "${aconfig}",
37 },
38 Restat: true,
Zhi Dou8a35a6f2023-07-19 18:04:24 +000039 }, "release_version", "package", "declarations", "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 Onorato37f900c2023-07-18 16:58:16 -070042 javaRule = pctx.AndroidStaticRule("java_aconfig_library",
Joe Onoratofee845a2023-05-09 08:14:14 -070043 blueprint.RuleParams{
44 Command: `rm -rf ${out}.tmp` +
45 ` && mkdir -p ${out}.tmp` +
46 ` && ${aconfig} create-java-lib` +
Joe Onoratob7c294a2023-07-28 05:30:25 -070047 ` --mode ${mode}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070048 ` --cache ${in}` +
49 ` --out ${out}.tmp` +
50 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
51 ` && rm -rf ${out}.tmp`,
52 CommandDeps: []string{
53 "$aconfig",
54 "$soong_zip",
55 },
56 Restat: true,
Joe Onoratob7c294a2023-07-28 05:30:25 -070057 }, "mode")
Joe Onorato2f99c472023-06-21 18:10:28 -070058
Joe Onorato37f900c2023-07-18 16:58:16 -070059 // For java_aconfig_library: Generate java file
60 cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
61 blueprint.RuleParams{
62 Command: `rm -rf ${gendir}` +
63 ` && mkdir -p ${gendir}` +
64 ` && ${aconfig} create-cpp-lib` +
65 ` --cache ${in}` +
66 ` --out ${gendir}`,
67 CommandDeps: []string{
68 "$aconfig",
69 "$soong_zip",
70 },
71 }, "gendir")
72
Joe Onorato2f99c472023-06-21 18:10:28 -070073 // For all_aconfig_declarations
74 allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
75 blueprint.RuleParams{
76 Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
77 CommandDeps: []string{
78 "${aconfig}",
79 },
80 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -070081)
82
83func init() {
84 registerBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -070085 pctx.HostBinToolVariable("aconfig", "aconfig")
86 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -070087}
88
89func registerBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -070090 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
91 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
92 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato37f900c2023-07-18 16:58:16 -070093 ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
Joe Onorato981c9262023-06-21 15:16:23 -070094 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -070095 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -070096}