device_host_converter_test.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // Copyright 2019 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 java
  15. import (
  16. "android/soong/android"
  17. "reflect"
  18. "strings"
  19. "testing"
  20. )
  21. func TestDeviceForHost(t *testing.T) {
  22. bp := `
  23. java_library {
  24. name: "device_module",
  25. srcs: ["a.java"],
  26. java_resources: ["java-res/a/a"],
  27. }
  28. java_import {
  29. name: "device_import_module",
  30. jars: ["a.jar"],
  31. }
  32. java_device_for_host {
  33. name: "device_for_host_module",
  34. libs: [
  35. "device_module",
  36. "device_import_module",
  37. ],
  38. }
  39. java_library_host {
  40. name: "host_module",
  41. srcs: ["b.java"],
  42. java_resources: ["java-res/b/b"],
  43. static_libs: ["device_for_host_module"],
  44. }
  45. `
  46. ctx, config := testJava(t, bp)
  47. deviceModule := ctx.ModuleForTests("device_module", "android_common")
  48. deviceTurbineCombined := deviceModule.Output("turbine-combined/device_module.jar")
  49. deviceJavac := deviceModule.Output("javac/device_module.jar")
  50. deviceRes := deviceModule.Output("res/device_module.jar")
  51. deviceImportModule := ctx.ModuleForTests("device_import_module", "android_common")
  52. deviceImportCombined := deviceImportModule.Output("combined/device_import_module.jar")
  53. hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
  54. hostJavac := hostModule.Output("javac/host_module.jar")
  55. hostRes := hostModule.Output("res/host_module.jar")
  56. combined := hostModule.Output("combined/host_module.jar")
  57. resCombined := hostModule.Output("res-combined/host_module.jar")
  58. // check classpath of host module with dependency on device_for_host_module
  59. expectedClasspath := "-classpath " + strings.Join(android.Paths{
  60. deviceTurbineCombined.Output,
  61. deviceImportCombined.Output,
  62. }.Strings(), ":")
  63. if hostJavac.Args["classpath"] != expectedClasspath {
  64. t.Errorf("expected host_module javac classpath:\n%s\ngot:\n%s",
  65. expectedClasspath, hostJavac.Args["classpath"])
  66. }
  67. // check host module merged with static dependency implementation jars from device_for_host module
  68. expectedInputs := android.Paths{
  69. hostJavac.Output,
  70. deviceJavac.Output,
  71. deviceImportCombined.Output,
  72. }
  73. if !reflect.DeepEqual(combined.Inputs, expectedInputs) {
  74. t.Errorf("expected host_module combined inputs:\n%q\ngot:\n%q",
  75. expectedInputs, combined.Inputs)
  76. }
  77. // check host module merged with static dependency resource jars from device_for_host module
  78. expectedInputs = android.Paths{
  79. hostRes.Output,
  80. deviceRes.Output,
  81. }
  82. if !reflect.DeepEqual(resCombined.Inputs, expectedInputs) {
  83. t.Errorf("expected host_module res combined inputs:\n%q\ngot:\n%q",
  84. expectedInputs, resCombined.Inputs)
  85. }
  86. }
  87. func TestHostForDevice(t *testing.T) {
  88. bp := `
  89. java_library_host {
  90. name: "host_module",
  91. srcs: ["a.java"],
  92. java_resources: ["java-res/a/a"],
  93. }
  94. java_import_host {
  95. name: "host_import_module",
  96. jars: ["a.jar"],
  97. }
  98. java_host_for_device {
  99. name: "host_for_device_module",
  100. libs: [
  101. "host_module",
  102. "host_import_module",
  103. ],
  104. }
  105. java_library {
  106. name: "device_module",
  107. sdk_version: "core_platform",
  108. srcs: ["b.java"],
  109. java_resources: ["java-res/b/b"],
  110. static_libs: ["host_for_device_module"],
  111. }
  112. `
  113. ctx, config := testJava(t, bp)
  114. hostModule := ctx.ModuleForTests("host_module", config.BuildOSCommonTarget.String())
  115. hostJavac := hostModule.Output("javac/host_module.jar")
  116. hostRes := hostModule.Output("res/host_module.jar")
  117. hostImportModule := ctx.ModuleForTests("host_import_module", config.BuildOSCommonTarget.String())
  118. hostImportCombined := hostImportModule.Output("combined/host_import_module.jar")
  119. deviceModule := ctx.ModuleForTests("device_module", "android_common")
  120. deviceJavac := deviceModule.Output("javac/device_module.jar")
  121. deviceRes := deviceModule.Output("res/device_module.jar")
  122. combined := deviceModule.Output("combined/device_module.jar")
  123. resCombined := deviceModule.Output("res-combined/device_module.jar")
  124. // check classpath of device module with dependency on host_for_device_module
  125. expectedClasspath := "-classpath " + strings.Join(android.Paths{
  126. hostJavac.Output,
  127. hostImportCombined.Output,
  128. }.Strings(), ":")
  129. if deviceJavac.Args["classpath"] != expectedClasspath {
  130. t.Errorf("expected device_module javac classpath:\n%s\ngot:\n%s",
  131. expectedClasspath, deviceJavac.Args["classpath"])
  132. }
  133. // check device module merged with static dependency implementation jars from host_for_device module
  134. expectedInputs := android.Paths{
  135. deviceJavac.Output,
  136. hostJavac.Output,
  137. hostImportCombined.Output,
  138. }
  139. if !reflect.DeepEqual(combined.Inputs, expectedInputs) {
  140. t.Errorf("expected device_module combined inputs:\n%q\ngot:\n%q",
  141. expectedInputs, combined.Inputs)
  142. }
  143. // check device module merged with static dependency resource jars from host_for_device module
  144. expectedInputs = android.Paths{
  145. deviceRes.Output,
  146. hostRes.Output,
  147. }
  148. if !reflect.DeepEqual(resCombined.Inputs, expectedInputs) {
  149. t.Errorf("expected device_module res combined inputs:\n%q\ngot:\n%q",
  150. expectedInputs, resCombined.Inputs)
  151. }
  152. }