blob: 58b6b8ba898cdf4fb19b3c589452e5e90db09100 [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"
Vinh Tran457ddef2023-08-02 13:50:26 -040019
Joe Onoratofee845a2023-05-09 08:14:14 -070020 "github.com/google/blueprint"
21)
22
23var (
Joe Onorato981c9262023-06-21 15:16:23 -070024 pctx = android.NewPackageContext("android/soong/aconfig")
Joe Onoratofee845a2023-05-09 08:14:14 -070025
Joe Onorato981c9262023-06-21 15:16:23 -070026 // For aconfig_declarations: Generate cache file
Joe Onoratofee845a2023-05-09 08:14:14 -070027 aconfigRule = pctx.AndroidStaticRule("aconfig",
28 blueprint.RuleParams{
29 Command: `${aconfig} create-cache` +
Joe Onorato81b25ed2023-06-21 13:49:37 -070030 ` --package ${package}` +
Zhi Dou8a35a6f2023-07-19 18:04:24 +000031 ` ${declarations}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070032 ` ${values}` +
33 ` --cache ${out}.tmp` +
34 ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
35 // ` --build-id ${release_version}` +
36 CommandDeps: []string{
37 "${aconfig}",
38 },
39 Restat: true,
Zhi Dou8a35a6f2023-07-19 18:04:24 +000040 }, "release_version", "package", "declarations", "values")
Joe Onoratofee845a2023-05-09 08:14:14 -070041
Joe Onorato981c9262023-06-21 15:16:23 -070042 // For java_aconfig_library: Generate java file
Joe Onorato37f900c2023-07-18 16:58:16 -070043 javaRule = pctx.AndroidStaticRule("java_aconfig_library",
Joe Onoratofee845a2023-05-09 08:14:14 -070044 blueprint.RuleParams{
45 Command: `rm -rf ${out}.tmp` +
46 ` && mkdir -p ${out}.tmp` +
47 ` && ${aconfig} create-java-lib` +
Joe Onoratob7c294a2023-07-28 05:30:25 -070048 ` --mode ${mode}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070049 ` --cache ${in}` +
50 ` --out ${out}.tmp` +
51 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
52 ` && rm -rf ${out}.tmp`,
53 CommandDeps: []string{
54 "$aconfig",
55 "$soong_zip",
56 },
57 Restat: true,
Joe Onoratob7c294a2023-07-28 05:30:25 -070058 }, "mode")
Joe Onorato2f99c472023-06-21 18:10:28 -070059
Joe Onorato37f900c2023-07-18 16:58:16 -070060 // For java_aconfig_library: Generate java file
61 cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
62 blueprint.RuleParams{
63 Command: `rm -rf ${gendir}` +
64 ` && mkdir -p ${gendir}` +
65 ` && ${aconfig} create-cpp-lib` +
66 ` --cache ${in}` +
67 ` --out ${gendir}`,
68 CommandDeps: []string{
69 "$aconfig",
70 "$soong_zip",
71 },
72 }, "gendir")
73
Vinh Tran457ddef2023-08-02 13:50:26 -040074 rustRule = pctx.AndroidStaticRule("rust_aconfig_library",
75 blueprint.RuleParams{
76 Command: `rm -rf ${gendir}` +
77 ` && mkdir -p ${gendir}` +
78 ` && ${aconfig} create-rust-lib` +
79 ` --mode ${mode}` +
80 ` --cache ${in}` +
81 ` --out ${gendir}`,
82 CommandDeps: []string{
83 "$aconfig",
84 "$soong_zip",
85 },
86 }, "gendir", "mode")
87
Joe Onorato2f99c472023-06-21 18:10:28 -070088 // For all_aconfig_declarations
89 allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
90 blueprint.RuleParams{
91 Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
92 CommandDeps: []string{
93 "${aconfig}",
94 },
95 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -070096)
97
98func init() {
99 registerBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -0700100 pctx.HostBinToolVariable("aconfig", "aconfig")
101 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -0700102}
103
104func registerBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -0700105 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
106 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
107 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato37f900c2023-07-18 16:58:16 -0700108 ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
Joe Onorato981c9262023-06-21 15:16:23 -0700109 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
Vinh Tran457ddef2023-08-02 13:50:26 -0400110 ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -0700111 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -0700112}