deptag_test.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2020 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 android
  15. import (
  16. "testing"
  17. "github.com/google/blueprint"
  18. )
  19. type testInstallDependencyTagModule struct {
  20. ModuleBase
  21. Properties struct {
  22. Install_deps []string
  23. Deps []string
  24. }
  25. }
  26. func (t *testInstallDependencyTagModule) GenerateAndroidBuildActions(ctx ModuleContext) {
  27. outputFile := PathForModuleOut(ctx, "out")
  28. ctx.Build(pctx, BuildParams{
  29. Rule: Touch,
  30. Output: outputFile,
  31. })
  32. ctx.InstallFile(PathForModuleInstall(ctx), ctx.ModuleName(), outputFile)
  33. }
  34. var testInstallDependencyTagAlwaysDepTag = struct {
  35. blueprint.DependencyTag
  36. InstallAlwaysNeededDependencyTag
  37. }{}
  38. var testInstallDependencyTagNeverDepTag = struct {
  39. blueprint.DependencyTag
  40. }{}
  41. func (t *testInstallDependencyTagModule) DepsMutator(ctx BottomUpMutatorContext) {
  42. ctx.AddVariationDependencies(nil, testInstallDependencyTagAlwaysDepTag, t.Properties.Install_deps...)
  43. ctx.AddVariationDependencies(nil, testInstallDependencyTagNeverDepTag, t.Properties.Deps...)
  44. }
  45. func testInstallDependencyTagModuleFactory() Module {
  46. module := &testInstallDependencyTagModule{}
  47. InitAndroidArchModule(module, HostAndDeviceDefault, MultilibCommon)
  48. module.AddProperties(&module.Properties)
  49. return module
  50. }
  51. func TestInstallDependencyTag(t *testing.T) {
  52. bp := `
  53. test_module {
  54. name: "foo",
  55. deps: ["dep"],
  56. install_deps: ["install_dep"],
  57. }
  58. test_module {
  59. name: "install_dep",
  60. install_deps: ["transitive"],
  61. }
  62. test_module {
  63. name: "transitive",
  64. }
  65. test_module {
  66. name: "dep",
  67. }
  68. `
  69. result := GroupFixturePreparers(
  70. PrepareForTestWithArchMutator,
  71. FixtureWithRootAndroidBp(bp),
  72. FixtureRegisterWithContext(func(ctx RegistrationContext) {
  73. ctx.RegisterModuleType("test_module", testInstallDependencyTagModuleFactory)
  74. }),
  75. ).RunTest(t)
  76. config := result.Config
  77. hostFoo := result.ModuleForTests("foo", config.BuildOSCommonTarget.String()).Description("install")
  78. hostInstallDep := result.ModuleForTests("install_dep", config.BuildOSCommonTarget.String()).Description("install")
  79. hostTransitive := result.ModuleForTests("transitive", config.BuildOSCommonTarget.String()).Description("install")
  80. hostDep := result.ModuleForTests("dep", config.BuildOSCommonTarget.String()).Description("install")
  81. if g, w := hostFoo.Implicits.Strings(), hostInstallDep.Output.String(); !InList(w, g) {
  82. t.Errorf("expected host dependency %q, got %q", w, g)
  83. }
  84. if g, w := hostFoo.Implicits.Strings(), hostTransitive.Output.String(); !InList(w, g) {
  85. t.Errorf("expected host dependency %q, got %q", w, g)
  86. }
  87. if g, w := hostInstallDep.Implicits.Strings(), hostTransitive.Output.String(); !InList(w, g) {
  88. t.Errorf("expected host dependency %q, got %q", w, g)
  89. }
  90. if g, w := hostFoo.Implicits.Strings(), hostDep.Output.String(); InList(w, g) {
  91. t.Errorf("expected no host dependency %q, got %q", w, g)
  92. }
  93. deviceFoo := result.ModuleForTests("foo", "android_common").Description("install")
  94. deviceInstallDep := result.ModuleForTests("install_dep", "android_common").Description("install")
  95. deviceTransitive := result.ModuleForTests("transitive", "android_common").Description("install")
  96. deviceDep := result.ModuleForTests("dep", "android_common").Description("install")
  97. if g, w := deviceFoo.OrderOnly.Strings(), deviceInstallDep.Output.String(); !InList(w, g) {
  98. t.Errorf("expected device dependency %q, got %q", w, g)
  99. }
  100. if g, w := deviceFoo.OrderOnly.Strings(), deviceTransitive.Output.String(); !InList(w, g) {
  101. t.Errorf("expected device dependency %q, got %q", w, g)
  102. }
  103. if g, w := deviceInstallDep.OrderOnly.Strings(), deviceTransitive.Output.String(); !InList(w, g) {
  104. t.Errorf("expected device dependency %q, got %q", w, g)
  105. }
  106. if g, w := deviceFoo.OrderOnly.Strings(), deviceDep.Output.String(); InList(w, g) {
  107. t.Errorf("expected no device dependency %q, got %q", w, g)
  108. }
  109. }