init.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // 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. package aconfig
  15. import (
  16. "android/soong/android"
  17. "github.com/google/blueprint"
  18. )
  19. var (
  20. pctx = android.NewPackageContext("android/soong/aconfig")
  21. // For aconfig_declarations: Generate cache file
  22. aconfigRule = pctx.AndroidStaticRule("aconfig",
  23. blueprint.RuleParams{
  24. Command: `${aconfig} create-cache` +
  25. ` --package ${package}` +
  26. ` --declarations ${in}` +
  27. ` ${values}` +
  28. ` --cache ${out}.tmp` +
  29. ` && ( if cmp -s ${out}.tmp ; then rm ${out}.tmp ; else mv ${out}.tmp ${out} ; fi )`,
  30. // ` --build-id ${release_version}` +
  31. CommandDeps: []string{
  32. "${aconfig}",
  33. },
  34. Restat: true,
  35. }, "release_version", "package", "values")
  36. // For java_aconfig_library: Generate java file
  37. srcJarRule = pctx.AndroidStaticRule("aconfig_srcjar",
  38. blueprint.RuleParams{
  39. Command: `rm -rf ${out}.tmp` +
  40. ` && mkdir -p ${out}.tmp` +
  41. ` && ${aconfig} create-java-lib` +
  42. ` --cache ${in}` +
  43. ` --out ${out}.tmp` +
  44. ` && $soong_zip -write_if_changed -jar -o ${out} -C ${out}.tmp -D ${out}.tmp` +
  45. ` && rm -rf ${out}.tmp`,
  46. CommandDeps: []string{
  47. "$aconfig",
  48. "$soong_zip",
  49. },
  50. Restat: true,
  51. })
  52. )
  53. func init() {
  54. registerBuildComponents(android.InitRegistrationContext)
  55. pctx.HostBinToolVariable("aconfig", "aconfig")
  56. pctx.HostBinToolVariable("soong_zip", "soong_zip")
  57. }
  58. func registerBuildComponents(ctx android.RegistrationContext) {
  59. ctx.RegisterModuleType("aconfig_declarations", DeclarationsFactory)
  60. ctx.RegisterModuleType("aconfig_values", ValuesFactory)
  61. ctx.RegisterModuleType("aconfig_value_set", ValueSetFactory)
  62. ctx.RegisterModuleType("java_aconfig_library", JavaDeclarationsLibraryFactory)
  63. }