blob: 3d62714bc9cd733a6939b42b4b488a337dca5442 [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}` +
Zhi Dou3f65a412023-08-10 21:47:40 +000033 ` ${default-permission}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070034 ` --cache ${out}.tmp` +
Zhi Dou9dc24512023-07-24 21:19:55 +000035 ` && ( if cmp -s ${out}.tmp ${out} ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
Joe Onoratofee845a2023-05-09 08:14:14 -070036 // ` --build-id ${release_version}` +
37 CommandDeps: []string{
38 "${aconfig}",
39 },
40 Restat: true,
Zhi Dou3f65a412023-08-10 21:47:40 +000041 }, "release_version", "package", "declarations", "values", "default-permission")
Joe Onoratofee845a2023-05-09 08:14:14 -070042
Joe Onorato981c9262023-06-21 15:16:23 -070043 // For java_aconfig_library: Generate java file
Joe Onorato37f900c2023-07-18 16:58:16 -070044 javaRule = pctx.AndroidStaticRule("java_aconfig_library",
Joe Onoratofee845a2023-05-09 08:14:14 -070045 blueprint.RuleParams{
46 Command: `rm -rf ${out}.tmp` +
47 ` && mkdir -p ${out}.tmp` +
48 ` && ${aconfig} create-java-lib` +
Joe Onoratob7c294a2023-07-28 05:30:25 -070049 ` --mode ${mode}` +
Joe Onoratofee845a2023-05-09 08:14:14 -070050 ` --cache ${in}` +
51 ` --out ${out}.tmp` +
52 ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
53 ` && rm -rf ${out}.tmp`,
54 CommandDeps: []string{
55 "$aconfig",
56 "$soong_zip",
57 },
58 Restat: true,
Joe Onoratob7c294a2023-07-28 05:30:25 -070059 }, "mode")
Joe Onorato2f99c472023-06-21 18:10:28 -070060
Joe Onorato37f900c2023-07-18 16:58:16 -070061 // For java_aconfig_library: Generate java file
62 cppRule = pctx.AndroidStaticRule("cc_aconfig_library",
63 blueprint.RuleParams{
64 Command: `rm -rf ${gendir}` +
65 ` && mkdir -p ${gendir}` +
66 ` && ${aconfig} create-cpp-lib` +
Dennis Shenc5e39f52023-09-14 18:52:49 +000067 ` --mode ${mode}` +
Joe Onorato37f900c2023-07-18 16:58:16 -070068 ` --cache ${in}` +
69 ` --out ${gendir}`,
70 CommandDeps: []string{
71 "$aconfig",
72 "$soong_zip",
73 },
Dennis Shenc5e39f52023-09-14 18:52:49 +000074 }, "gendir", "mode")
Joe Onorato37f900c2023-07-18 16:58:16 -070075
Vinh Tran457ddef2023-08-02 13:50:26 -040076 rustRule = pctx.AndroidStaticRule("rust_aconfig_library",
77 blueprint.RuleParams{
78 Command: `rm -rf ${gendir}` +
79 ` && mkdir -p ${gendir}` +
80 ` && ${aconfig} create-rust-lib` +
81 ` --mode ${mode}` +
82 ` --cache ${in}` +
83 ` --out ${gendir}`,
84 CommandDeps: []string{
85 "$aconfig",
86 "$soong_zip",
87 },
88 }, "gendir", "mode")
89
Joe Onorato2f99c472023-06-21 18:10:28 -070090 // For all_aconfig_declarations
91 allDeclarationsRule = pctx.AndroidStaticRule("all_aconfig_declarations_dump",
92 blueprint.RuleParams{
93 Command: `${aconfig} dump --format protobuf --out ${out} ${cache_files}`,
94 CommandDeps: []string{
95 "${aconfig}",
96 },
97 }, "cache_files")
Joe Onoratofee845a2023-05-09 08:14:14 -070098)
99
100func init() {
Yu Liu2cc802a2023-09-05 17:19:45 -0700101 RegisterBuildComponents(android.InitRegistrationContext)
Joe Onorato175073c2023-06-01 14:42:59 -0700102 pctx.HostBinToolVariable("aconfig", "aconfig")
103 pctx.HostBinToolVariable("soong_zip", "soong_zip")
Joe Onoratofee845a2023-05-09 08:14:14 -0700104}
105
Yu Liu2cc802a2023-09-05 17:19:45 -0700106func RegisterBuildComponents(ctx android.RegistrationContext) {
Joe Onorato981c9262023-06-21 15:16:23 -0700107 ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
108 ctx.RegisterModuleType("aconfig_values", ValuesFactory)
109 ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
Joe Onorato37f900c2023-07-18 16:58:16 -0700110 ctx.RegisterModuleType("cc_aconfig_library", CcAconfigLibraryFactory)
Joe Onorato981c9262023-06-21 15:16:23 -0700111 ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
Vinh Tran457ddef2023-08-02 13:50:26 -0400112 ctx.RegisterModuleType("rust_aconfig_library", RustAconfigLibraryFactory)
Joe Onorato2f99c472023-06-21 18:10:28 -0700113 ctx.RegisterParallelSingletonType("all_aconfig_declarations", AllAconfigDeclarationsFactory)
Joe Onoratofee845a2023-05-09 08:14:14 -0700114}