vendor_snapshot_test.go 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740
  1. // Copyright 2021 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 cc
  15. import (
  16. "android/soong/android"
  17. "fmt"
  18. "path/filepath"
  19. "reflect"
  20. "strings"
  21. "testing"
  22. )
  23. func checkJsonContents(t *testing.T, ctx android.TestingSingleton, jsonPath string, key string, value string) {
  24. jsonOut := ctx.MaybeOutput(jsonPath)
  25. if jsonOut.Rule == nil {
  26. t.Errorf("%q expected but not found", jsonPath)
  27. return
  28. }
  29. if !strings.Contains(jsonOut.Args["content"], fmt.Sprintf("%q:%q", key, value)) {
  30. t.Errorf("%q must include %q:%q but it only has %v", jsonPath, key, value, jsonOut.Args["content"])
  31. }
  32. }
  33. func TestVendorSnapshotCapture(t *testing.T) {
  34. bp := `
  35. cc_library {
  36. name: "libvndk",
  37. vendor_available: true,
  38. product_available: true,
  39. vndk: {
  40. enabled: true,
  41. },
  42. nocrt: true,
  43. }
  44. cc_library {
  45. name: "libvendor",
  46. vendor: true,
  47. nocrt: true,
  48. }
  49. cc_library {
  50. name: "libvendor_override",
  51. vendor: true,
  52. nocrt: true,
  53. overrides: ["libvendor"],
  54. }
  55. cc_library {
  56. name: "libvendor_available",
  57. vendor_available: true,
  58. nocrt: true,
  59. min_sdk_version: "29",
  60. }
  61. cc_library_headers {
  62. name: "libvendor_headers",
  63. vendor_available: true,
  64. nocrt: true,
  65. }
  66. cc_binary {
  67. name: "vendor_bin",
  68. vendor: true,
  69. nocrt: true,
  70. }
  71. cc_binary {
  72. name: "vendor_available_bin",
  73. vendor_available: true,
  74. nocrt: true,
  75. }
  76. cc_binary {
  77. name: "vendor_bin_override",
  78. vendor: true,
  79. nocrt: true,
  80. overrides: ["vendor_bin"],
  81. }
  82. cc_prebuilt_library_static {
  83. name: "libb",
  84. vendor_available: true,
  85. srcs: ["libb.a"],
  86. nocrt: true,
  87. no_libcrt: true,
  88. stl: "none",
  89. }
  90. cc_object {
  91. name: "obj",
  92. vendor_available: true,
  93. }
  94. cc_library {
  95. name: "libllndk",
  96. llndk: {
  97. symbol_file: "libllndk.map.txt",
  98. },
  99. }
  100. `
  101. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  102. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  103. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  104. ctx := testCcWithConfig(t, config)
  105. // Check Vendor snapshot output.
  106. snapshotDir := "vendor-snapshot"
  107. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  108. snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
  109. var jsonFiles []string
  110. for _, arch := range [][]string{
  111. []string{"arm64", "armv8-a"},
  112. []string{"arm", "armv7-a-neon"},
  113. } {
  114. archType := arch[0]
  115. archVariant := arch[1]
  116. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  117. // For shared libraries, only non-VNDK vendor_available modules are captured
  118. sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
  119. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  120. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
  121. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
  122. jsonFiles = append(jsonFiles,
  123. filepath.Join(sharedDir, "libvendor.so.json"),
  124. filepath.Join(sharedDir, "libvendor_available.so.json"))
  125. // LLNDK modules are not captured
  126. CheckSnapshotExclude(t, ctx, snapshotSingleton, "libllndk", "libllndk.so", sharedDir, sharedVariant)
  127. // For static libraries, all vendor:true and vendor_available modules (including VNDK) are captured.
  128. // Also cfi variants are captured, except for prebuilts like toolchain_library
  129. staticVariant := fmt.Sprintf("android_vendor.29_%s_%s_static", archType, archVariant)
  130. staticCfiVariant := fmt.Sprintf("android_vendor.29_%s_%s_static_cfi", archType, archVariant)
  131. staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
  132. CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
  133. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.a", staticDir, staticVariant)
  134. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.cfi.a", staticDir, staticCfiVariant)
  135. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.a", staticDir, staticVariant)
  136. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.cfi.a", staticDir, staticCfiVariant)
  137. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.a", staticDir, staticVariant)
  138. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.cfi.a", staticDir, staticCfiVariant)
  139. jsonFiles = append(jsonFiles,
  140. filepath.Join(staticDir, "libb.a.json"),
  141. filepath.Join(staticDir, "libvndk.a.json"),
  142. filepath.Join(staticDir, "libvndk.cfi.a.json"),
  143. filepath.Join(staticDir, "libvendor.a.json"),
  144. filepath.Join(staticDir, "libvendor.cfi.a.json"),
  145. filepath.Join(staticDir, "libvendor_available.a.json"),
  146. filepath.Join(staticDir, "libvendor_available.cfi.a.json"))
  147. checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libb.a.json"), "MinSdkVersion", "apex_inherit")
  148. checkJsonContents(t, snapshotSingleton, filepath.Join(staticDir, "libvendor_available.a.json"), "MinSdkVersion", "29")
  149. // For binary executables, all vendor:true and vendor_available modules are captured.
  150. if archType == "arm64" {
  151. binaryVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
  152. binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
  153. CheckSnapshot(t, ctx, snapshotSingleton, "vendor_bin", "vendor_bin", binaryDir, binaryVariant)
  154. CheckSnapshot(t, ctx, snapshotSingleton, "vendor_available_bin", "vendor_available_bin", binaryDir, binaryVariant)
  155. jsonFiles = append(jsonFiles,
  156. filepath.Join(binaryDir, "vendor_bin.json"),
  157. filepath.Join(binaryDir, "vendor_available_bin.json"))
  158. checkOverrides(t, ctx, snapshotSingleton, filepath.Join(binaryDir, "vendor_bin_override.json"), []string{"vendor_bin"})
  159. }
  160. // For header libraries, all vendor:true and vendor_available modules are captured.
  161. headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
  162. jsonFiles = append(jsonFiles, filepath.Join(headerDir, "libvendor_headers.json"))
  163. // For object modules, all vendor:true and vendor_available modules are captured.
  164. objectVariant := fmt.Sprintf("android_vendor.29_%s_%s", archType, archVariant)
  165. objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
  166. CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
  167. jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
  168. checkOverrides(t, ctx, snapshotSingleton, filepath.Join(sharedDir, "libvendor_override.so.json"), []string{"libvendor"})
  169. }
  170. for _, jsonFile := range jsonFiles {
  171. // verify all json files exist
  172. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  173. t.Errorf("%q expected but not found", jsonFile)
  174. }
  175. }
  176. // fake snapshot should have all outputs in the normal snapshot.
  177. fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
  178. for _, output := range snapshotSingleton.AllOutputs() {
  179. fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
  180. if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
  181. t.Errorf("%q expected but not found", fakeOutput)
  182. }
  183. }
  184. }
  185. func TestVendorSnapshotDirected(t *testing.T) {
  186. bp := `
  187. cc_library_shared {
  188. name: "libvendor",
  189. vendor: true,
  190. nocrt: true,
  191. }
  192. cc_library_shared {
  193. name: "libvendor_available",
  194. vendor_available: true,
  195. nocrt: true,
  196. }
  197. genrule {
  198. name: "libfoo_gen",
  199. cmd: "",
  200. out: ["libfoo.so"],
  201. }
  202. cc_prebuilt_library_shared {
  203. name: "libfoo",
  204. vendor: true,
  205. prefer: true,
  206. srcs: [":libfoo_gen"],
  207. }
  208. cc_library_shared {
  209. name: "libfoo",
  210. vendor: true,
  211. nocrt: true,
  212. }
  213. `
  214. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  215. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  216. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  217. config.TestProductVariables.DirectedVendorSnapshot = true
  218. config.TestProductVariables.VendorSnapshotModules = make(map[string]bool)
  219. config.TestProductVariables.VendorSnapshotModules["libvendor"] = true
  220. config.TestProductVariables.VendorSnapshotModules["libfoo"] = true
  221. ctx := testCcWithConfig(t, config)
  222. // Check Vendor snapshot output.
  223. snapshotDir := "vendor-snapshot"
  224. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  225. snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
  226. var includeJsonFiles []string
  227. for _, arch := range [][]string{
  228. []string{"arm64", "armv8-a"},
  229. []string{"arm", "armv7-a-neon"},
  230. } {
  231. archType := arch[0]
  232. archVariant := arch[1]
  233. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  234. sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
  235. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  236. // Included modules
  237. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
  238. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
  239. // Check that snapshot captures "prefer: true" prebuilt
  240. CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
  241. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
  242. // Excluded modules. Modules not included in the directed vendor snapshot
  243. // are still include as fake modules.
  244. CheckSnapshotRule(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
  245. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libvendor_available.so.json"))
  246. }
  247. // Verify that each json file for an included module has a rule.
  248. for _, jsonFile := range includeJsonFiles {
  249. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  250. t.Errorf("include json file %q not found", jsonFile)
  251. }
  252. }
  253. }
  254. func TestVendorSnapshotUse(t *testing.T) {
  255. frameworkBp := `
  256. cc_library {
  257. name: "libvndk",
  258. vendor_available: true,
  259. product_available: true,
  260. vndk: {
  261. enabled: true,
  262. },
  263. nocrt: true,
  264. }
  265. cc_library {
  266. name: "libvendor",
  267. vendor: true,
  268. nocrt: true,
  269. no_libcrt: true,
  270. stl: "none",
  271. system_shared_libs: [],
  272. }
  273. cc_library {
  274. name: "libvendor_available",
  275. vendor_available: true,
  276. nocrt: true,
  277. no_libcrt: true,
  278. stl: "none",
  279. system_shared_libs: [],
  280. }
  281. cc_library {
  282. name: "lib32",
  283. vendor: true,
  284. nocrt: true,
  285. no_libcrt: true,
  286. stl: "none",
  287. system_shared_libs: [],
  288. compile_multilib: "32",
  289. }
  290. cc_library {
  291. name: "lib64",
  292. vendor: true,
  293. nocrt: true,
  294. no_libcrt: true,
  295. stl: "none",
  296. system_shared_libs: [],
  297. compile_multilib: "64",
  298. }
  299. cc_library {
  300. name: "libllndk",
  301. llndk: {
  302. symbol_file: "libllndk.map.txt",
  303. },
  304. }
  305. cc_binary {
  306. name: "bin",
  307. vendor: true,
  308. nocrt: true,
  309. no_libcrt: true,
  310. stl: "none",
  311. system_shared_libs: [],
  312. }
  313. cc_binary {
  314. name: "bin32",
  315. vendor: true,
  316. nocrt: true,
  317. no_libcrt: true,
  318. stl: "none",
  319. system_shared_libs: [],
  320. compile_multilib: "32",
  321. }
  322. `
  323. vndkBp := `
  324. vndk_prebuilt_shared {
  325. name: "libvndk",
  326. version: "31",
  327. target_arch: "arm64",
  328. vendor_available: true,
  329. product_available: true,
  330. vndk: {
  331. enabled: true,
  332. },
  333. arch: {
  334. arm64: {
  335. srcs: ["libvndk.so"],
  336. export_include_dirs: ["include/libvndk"],
  337. },
  338. arm: {
  339. srcs: ["libvndk.so"],
  340. export_include_dirs: ["include/libvndk"],
  341. },
  342. },
  343. }
  344. // old snapshot module which has to be ignored
  345. vndk_prebuilt_shared {
  346. name: "libvndk",
  347. version: "26",
  348. target_arch: "arm64",
  349. vendor_available: true,
  350. product_available: true,
  351. vndk: {
  352. enabled: true,
  353. },
  354. arch: {
  355. arm64: {
  356. srcs: ["libvndk.so"],
  357. export_include_dirs: ["include/libvndk"],
  358. },
  359. arm: {
  360. srcs: ["libvndk.so"],
  361. export_include_dirs: ["include/libvndk"],
  362. },
  363. },
  364. }
  365. // different arch snapshot which has to be ignored
  366. vndk_prebuilt_shared {
  367. name: "libvndk",
  368. version: "31",
  369. target_arch: "arm",
  370. vendor_available: true,
  371. product_available: true,
  372. vndk: {
  373. enabled: true,
  374. },
  375. arch: {
  376. arm: {
  377. srcs: ["libvndk.so"],
  378. export_include_dirs: ["include/libvndk"],
  379. },
  380. },
  381. }
  382. vndk_prebuilt_shared {
  383. name: "libllndk",
  384. version: "31",
  385. target_arch: "arm64",
  386. vendor_available: true,
  387. product_available: true,
  388. arch: {
  389. arm64: {
  390. srcs: ["libllndk.so"],
  391. },
  392. arm: {
  393. srcs: ["libllndk.so"],
  394. },
  395. },
  396. }
  397. `
  398. vendorProprietaryBp := `
  399. cc_library {
  400. name: "libvendor_without_snapshot",
  401. vendor: true,
  402. nocrt: true,
  403. no_libcrt: true,
  404. stl: "none",
  405. system_shared_libs: [],
  406. }
  407. cc_library_shared {
  408. name: "libclient",
  409. vendor: true,
  410. nocrt: true,
  411. no_libcrt: true,
  412. stl: "none",
  413. system_shared_libs: [],
  414. shared_libs: ["libvndk", "libvendor_available", "libllndk"],
  415. static_libs: ["libvendor", "libvendor_without_snapshot"],
  416. arch: {
  417. arm64: {
  418. shared_libs: ["lib64"],
  419. },
  420. arm: {
  421. shared_libs: ["lib32"],
  422. },
  423. },
  424. srcs: ["client.cpp"],
  425. }
  426. cc_library_shared {
  427. name: "libclient_cfi",
  428. vendor: true,
  429. nocrt: true,
  430. no_libcrt: true,
  431. stl: "none",
  432. system_shared_libs: [],
  433. static_libs: ["libvendor"],
  434. sanitize: {
  435. cfi: true,
  436. },
  437. srcs: ["client.cpp"],
  438. }
  439. cc_library_shared {
  440. name: "libvndkext",
  441. vendor: true,
  442. nocrt: true,
  443. no_libcrt: true,
  444. stl: "none",
  445. system_shared_libs: [],
  446. vndk: {
  447. extends: "libvndk",
  448. enabled: true,
  449. }
  450. }
  451. cc_binary {
  452. name: "bin_without_snapshot",
  453. vendor: true,
  454. nocrt: true,
  455. no_libcrt: true,
  456. stl: "libc++_static",
  457. system_shared_libs: [],
  458. static_libs: ["libvndk"],
  459. srcs: ["bin.cpp"],
  460. }
  461. vendor_snapshot {
  462. name: "vendor_snapshot",
  463. version: "31",
  464. arch: {
  465. arm64: {
  466. vndk_libs: [
  467. "libvndk",
  468. "libllndk",
  469. ],
  470. static_libs: [
  471. "libc++_static",
  472. "libc++demangle",
  473. "libunwind",
  474. "libvendor",
  475. "libvendor_available",
  476. "libvndk",
  477. "lib64",
  478. ],
  479. shared_libs: [
  480. "libvendor",
  481. "libvendor_override",
  482. "libvendor_available",
  483. "lib64",
  484. ],
  485. binaries: [
  486. "bin",
  487. "bin_override",
  488. ],
  489. },
  490. arm: {
  491. vndk_libs: [
  492. "libvndk",
  493. "libllndk",
  494. ],
  495. static_libs: [
  496. "libvendor",
  497. "libvendor_available",
  498. "libvndk",
  499. "lib32",
  500. ],
  501. shared_libs: [
  502. "libvendor",
  503. "libvendor_override",
  504. "libvendor_available",
  505. "lib32",
  506. ],
  507. binaries: [
  508. "bin32",
  509. ],
  510. },
  511. }
  512. }
  513. vendor_snapshot_static {
  514. name: "libvndk",
  515. version: "31",
  516. target_arch: "arm64",
  517. compile_multilib: "both",
  518. vendor: true,
  519. arch: {
  520. arm64: {
  521. src: "libvndk.a",
  522. },
  523. arm: {
  524. src: "libvndk.a",
  525. },
  526. },
  527. shared_libs: ["libvndk"],
  528. export_shared_lib_headers: ["libvndk"],
  529. }
  530. vendor_snapshot_shared {
  531. name: "libvendor",
  532. version: "31",
  533. target_arch: "arm64",
  534. compile_multilib: "both",
  535. vendor: true,
  536. shared_libs: [
  537. "libvendor_without_snapshot",
  538. "libvendor_available",
  539. "libvndk",
  540. ],
  541. arch: {
  542. arm64: {
  543. src: "libvendor.so",
  544. export_include_dirs: ["include/libvendor"],
  545. },
  546. arm: {
  547. src: "libvendor.so",
  548. export_include_dirs: ["include/libvendor"],
  549. },
  550. },
  551. }
  552. vendor_snapshot_shared {
  553. name: "libvendor_override",
  554. version: "31",
  555. target_arch: "arm64",
  556. compile_multilib: "both",
  557. vendor: true,
  558. overrides: ["libvendor"],
  559. shared_libs: [
  560. "libvendor_without_snapshot",
  561. "libvendor_available",
  562. "libvndk",
  563. ],
  564. arch: {
  565. arm64: {
  566. src: "override/libvendor.so",
  567. export_include_dirs: ["include/libvendor"],
  568. },
  569. arm: {
  570. src: "override/libvendor.so",
  571. export_include_dirs: ["include/libvendor"],
  572. },
  573. },
  574. }
  575. vendor_snapshot_static {
  576. name: "lib32",
  577. version: "31",
  578. target_arch: "arm64",
  579. compile_multilib: "32",
  580. vendor: true,
  581. arch: {
  582. arm: {
  583. src: "lib32.a",
  584. },
  585. },
  586. }
  587. vendor_snapshot_shared {
  588. name: "lib32",
  589. version: "31",
  590. target_arch: "arm64",
  591. compile_multilib: "32",
  592. vendor: true,
  593. arch: {
  594. arm: {
  595. src: "lib32.so",
  596. },
  597. },
  598. }
  599. vendor_snapshot_static {
  600. name: "lib64",
  601. version: "31",
  602. target_arch: "arm64",
  603. compile_multilib: "64",
  604. vendor: true,
  605. arch: {
  606. arm64: {
  607. src: "lib64.a",
  608. },
  609. },
  610. }
  611. vendor_snapshot_shared {
  612. name: "lib64",
  613. version: "31",
  614. target_arch: "arm64",
  615. compile_multilib: "64",
  616. vendor: true,
  617. arch: {
  618. arm64: {
  619. src: "lib64.so",
  620. },
  621. },
  622. }
  623. vendor_snapshot_static {
  624. name: "libvendor",
  625. version: "31",
  626. target_arch: "arm64",
  627. compile_multilib: "both",
  628. vendor: true,
  629. arch: {
  630. arm64: {
  631. cfi: {
  632. src: "libvendor.cfi.a",
  633. export_include_dirs: ["include/libvendor_cfi"],
  634. },
  635. src: "libvendor.a",
  636. export_include_dirs: ["include/libvendor"],
  637. },
  638. arm: {
  639. cfi: {
  640. src: "libvendor.cfi.a",
  641. export_include_dirs: ["include/libvendor_cfi"],
  642. },
  643. src: "libvendor.a",
  644. export_include_dirs: ["include/libvendor"],
  645. },
  646. },
  647. }
  648. vendor_snapshot_shared {
  649. name: "libvendor_available",
  650. version: "31",
  651. target_arch: "arm64",
  652. compile_multilib: "both",
  653. vendor: true,
  654. arch: {
  655. arm64: {
  656. src: "libvendor_available.so",
  657. export_include_dirs: ["include/libvendor"],
  658. },
  659. arm: {
  660. src: "libvendor_available.so",
  661. export_include_dirs: ["include/libvendor"],
  662. },
  663. },
  664. }
  665. vendor_snapshot_static {
  666. name: "libvendor_available",
  667. version: "31",
  668. target_arch: "arm64",
  669. compile_multilib: "both",
  670. vendor: true,
  671. arch: {
  672. arm64: {
  673. src: "libvendor_available.a",
  674. export_include_dirs: ["include/libvendor"],
  675. },
  676. arm: {
  677. src: "libvendor_available.so",
  678. export_include_dirs: ["include/libvendor"],
  679. },
  680. },
  681. }
  682. vendor_snapshot_static {
  683. name: "libc++_static",
  684. version: "31",
  685. target_arch: "arm64",
  686. compile_multilib: "64",
  687. vendor: true,
  688. arch: {
  689. arm64: {
  690. src: "libc++_static.a",
  691. },
  692. },
  693. }
  694. vendor_snapshot_static {
  695. name: "libc++demangle",
  696. version: "31",
  697. target_arch: "arm64",
  698. compile_multilib: "64",
  699. vendor: true,
  700. arch: {
  701. arm64: {
  702. src: "libc++demangle.a",
  703. },
  704. },
  705. }
  706. vendor_snapshot_static {
  707. name: "libunwind",
  708. version: "31",
  709. target_arch: "arm64",
  710. compile_multilib: "64",
  711. vendor: true,
  712. arch: {
  713. arm64: {
  714. src: "libunwind.a",
  715. },
  716. },
  717. }
  718. vendor_snapshot_binary {
  719. name: "bin",
  720. version: "31",
  721. target_arch: "arm64",
  722. compile_multilib: "64",
  723. vendor: true,
  724. arch: {
  725. arm64: {
  726. src: "bin",
  727. },
  728. },
  729. symlinks: ["binfoo", "binbar"],
  730. }
  731. vendor_snapshot_binary {
  732. name: "bin_override",
  733. version: "31",
  734. target_arch: "arm64",
  735. compile_multilib: "64",
  736. vendor: true,
  737. overrides: ["bin"],
  738. arch: {
  739. arm64: {
  740. src: "override/bin",
  741. },
  742. },
  743. symlinks: ["binfoo", "binbar"],
  744. }
  745. vendor_snapshot_binary {
  746. name: "bin32",
  747. version: "31",
  748. target_arch: "arm64",
  749. compile_multilib: "32",
  750. vendor: true,
  751. arch: {
  752. arm: {
  753. src: "bin32",
  754. },
  755. },
  756. }
  757. // old snapshot module which has to be ignored
  758. vendor_snapshot_binary {
  759. name: "bin",
  760. version: "26",
  761. target_arch: "arm64",
  762. compile_multilib: "first",
  763. vendor: true,
  764. arch: {
  765. arm64: {
  766. src: "bin",
  767. },
  768. },
  769. }
  770. // different arch snapshot which has to be ignored
  771. vendor_snapshot_binary {
  772. name: "bin",
  773. version: "31",
  774. target_arch: "arm",
  775. compile_multilib: "first",
  776. vendor: true,
  777. arch: {
  778. arm64: {
  779. src: "bin",
  780. },
  781. },
  782. }
  783. `
  784. depsBp := GatherRequiredDepsForTest(android.Android)
  785. mockFS := map[string][]byte{
  786. "deps/Android.bp": []byte(depsBp),
  787. "framework/Android.bp": []byte(frameworkBp),
  788. "framework/symbol.txt": nil,
  789. "vendor/Android.bp": []byte(vendorProprietaryBp),
  790. "vendor/bin": nil,
  791. "vendor/override/bin": nil,
  792. "vendor/bin32": nil,
  793. "vendor/bin.cpp": nil,
  794. "vendor/client.cpp": nil,
  795. "vendor/include/libvndk/a.h": nil,
  796. "vendor/include/libvendor/b.h": nil,
  797. "vendor/include/libvendor_cfi/c.h": nil,
  798. "vendor/libc++_static.a": nil,
  799. "vendor/libc++demangle.a": nil,
  800. "vendor/libunwind.a": nil,
  801. "vendor/libvndk.a": nil,
  802. "vendor/libvendor.a": nil,
  803. "vendor/libvendor.cfi.a": nil,
  804. "vendor/libvendor.so": nil,
  805. "vendor/override/libvendor.so": nil,
  806. "vendor/lib32.a": nil,
  807. "vendor/lib32.so": nil,
  808. "vendor/lib64.a": nil,
  809. "vendor/lib64.so": nil,
  810. "vndk/Android.bp": []byte(vndkBp),
  811. "vndk/include/libvndk/a.h": nil,
  812. "vndk/libvndk.so": nil,
  813. "vndk/libllndk.so": nil,
  814. }
  815. config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
  816. config.TestProductVariables.DeviceVndkVersion = StringPtr("31")
  817. config.TestProductVariables.Platform_vndk_version = StringPtr("32")
  818. ctx := CreateTestContext(config)
  819. ctx.Register()
  820. _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "vendor/Android.bp", "vndk/Android.bp"})
  821. android.FailIfErrored(t, errs)
  822. _, errs = ctx.PrepareBuildActions(config)
  823. android.FailIfErrored(t, errs)
  824. sharedVariant := "android_vendor.31_arm64_armv8-a_shared"
  825. staticVariant := "android_vendor.31_arm64_armv8-a_static"
  826. binaryVariant := "android_vendor.31_arm64_armv8-a"
  827. sharedCfiVariant := "android_vendor.31_arm64_armv8-a_shared_cfi"
  828. staticCfiVariant := "android_vendor.31_arm64_armv8-a_static_cfi"
  829. shared32Variant := "android_vendor.31_arm_armv7-a-neon_shared"
  830. binary32Variant := "android_vendor.31_arm_armv7-a-neon"
  831. // libclient uses libvndk.vndk.31.arm64, libvendor.vendor_static.31.arm64, libvendor_without_snapshot
  832. libclientCcFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("cc").Args["cFlags"]
  833. for _, includeFlags := range []string{
  834. "-Ivndk/include/libvndk", // libvndk
  835. "-Ivendor/include/libvendor", // libvendor
  836. } {
  837. if !strings.Contains(libclientCcFlags, includeFlags) {
  838. t.Errorf("flags for libclient must contain %#v, but was %#v.",
  839. includeFlags, libclientCcFlags)
  840. }
  841. }
  842. libclientLdFlags := ctx.ModuleForTests("libclient", sharedVariant).Rule("ld").Args["libFlags"]
  843. for _, input := range [][]string{
  844. []string{sharedVariant, "libvndk.vndk.31.arm64"},
  845. []string{sharedVariant, "libllndk.vndk.31.arm64"},
  846. []string{staticVariant, "libvendor.vendor_static.31.arm64"},
  847. []string{staticVariant, "libvendor_without_snapshot"},
  848. } {
  849. outputPaths := GetOutputPaths(ctx, input[0] /* variant */, []string{input[1]} /* module name */)
  850. if !strings.Contains(libclientLdFlags, outputPaths[0].String()) {
  851. t.Errorf("libflags for libclient must contain %#v, but was %#v", outputPaths[0], libclientLdFlags)
  852. }
  853. }
  854. libclientAndroidMkSharedLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkSharedLibs
  855. if g, w := libclientAndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib64"}; !reflect.DeepEqual(g, w) {
  856. t.Errorf("wanted libclient AndroidMkSharedLibs %q, got %q", w, g)
  857. }
  858. libclientAndroidMkStaticLibs := ctx.ModuleForTests("libclient", sharedVariant).Module().(*Module).Properties.AndroidMkStaticLibs
  859. if g, w := libclientAndroidMkStaticLibs, []string{"libvendor", "libvendor_without_snapshot"}; !reflect.DeepEqual(g, w) {
  860. t.Errorf("wanted libclient AndroidMkStaticLibs %q, got %q", w, g)
  861. }
  862. libclient32AndroidMkSharedLibs := ctx.ModuleForTests("libclient", shared32Variant).Module().(*Module).Properties.AndroidMkSharedLibs
  863. if g, w := libclient32AndroidMkSharedLibs, []string{"libvndk.vendor", "libvendor_available.vendor", "libllndk.vendor", "lib32"}; !reflect.DeepEqual(g, w) {
  864. t.Errorf("wanted libclient32 AndroidMkSharedLibs %q, got %q", w, g)
  865. }
  866. // libclient_cfi uses libvendor.vendor_static.31.arm64's cfi variant
  867. libclientCfiCcFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("cc").Args["cFlags"]
  868. if !strings.Contains(libclientCfiCcFlags, "-Ivendor/include/libvendor_cfi") {
  869. t.Errorf("flags for libclient_cfi must contain %#v, but was %#v.",
  870. "-Ivendor/include/libvendor_cfi", libclientCfiCcFlags)
  871. }
  872. libclientCfiLdFlags := ctx.ModuleForTests("libclient_cfi", sharedCfiVariant).Rule("ld").Args["libFlags"]
  873. libvendorCfiOutputPaths := GetOutputPaths(ctx, staticCfiVariant, []string{"libvendor.vendor_static.31.arm64"})
  874. if !strings.Contains(libclientCfiLdFlags, libvendorCfiOutputPaths[0].String()) {
  875. t.Errorf("libflags for libclientCfi must contain %#v, but was %#v", libvendorCfiOutputPaths[0], libclientCfiLdFlags)
  876. }
  877. // bin_without_snapshot uses libvndk.vendor_static.31.arm64 (which reexports vndk's exported headers)
  878. binWithoutSnapshotCcFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("cc").Args["cFlags"]
  879. if !strings.Contains(binWithoutSnapshotCcFlags, "-Ivndk/include/libvndk") {
  880. t.Errorf("flags for bin_without_snapshot must contain %#v, but was %#v.",
  881. "-Ivendor/include/libvndk", binWithoutSnapshotCcFlags)
  882. }
  883. binWithoutSnapshotLdFlags := ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Rule("ld").Args["libFlags"]
  884. libVndkStaticOutputPaths := GetOutputPaths(ctx, staticVariant, []string{"libvndk.vendor_static.31.arm64"})
  885. if !strings.Contains(binWithoutSnapshotLdFlags, libVndkStaticOutputPaths[0].String()) {
  886. t.Errorf("libflags for bin_without_snapshot must contain %#v, but was %#v",
  887. libVndkStaticOutputPaths[0], binWithoutSnapshotLdFlags)
  888. }
  889. // libvendor.so is installed by libvendor.vendor_shared.31.arm64
  890. ctx.ModuleForTests("libvendor.vendor_shared.31.arm64", sharedVariant).Output("libvendor.so")
  891. // lib64.so is installed by lib64.vendor_shared.31.arm64
  892. ctx.ModuleForTests("lib64.vendor_shared.31.arm64", sharedVariant).Output("lib64.so")
  893. // lib32.so is installed by lib32.vendor_shared.31.arm64
  894. ctx.ModuleForTests("lib32.vendor_shared.31.arm64", shared32Variant).Output("lib32.so")
  895. // libvendor_available.so is installed by libvendor_available.vendor_shared.31.arm64
  896. ctx.ModuleForTests("libvendor_available.vendor_shared.31.arm64", sharedVariant).Output("libvendor_available.so")
  897. // libvendor_without_snapshot.so is installed by libvendor_without_snapshot
  898. ctx.ModuleForTests("libvendor_without_snapshot", sharedVariant).Output("libvendor_without_snapshot.so")
  899. // bin is installed by bin.vendor_binary.31.arm64
  900. bin64Module := ctx.ModuleForTests("bin.vendor_binary.31.arm64", binaryVariant)
  901. bin64Module.Output("bin")
  902. // also test symlinks
  903. bin64MkEntries := android.AndroidMkEntriesForTest(t, ctx, bin64Module.Module())
  904. bin64KatiSymlinks := bin64MkEntries[0].EntryMap["LOCAL_SOONG_INSTALL_SYMLINKS"]
  905. // Either AndroidMk entries contain symlinks, or symlinks should be installed by Soong
  906. for _, symlink := range []string{"binfoo", "binbar"} {
  907. if inList(symlink, bin64KatiSymlinks) {
  908. continue
  909. }
  910. bin64Module.Output(symlink)
  911. }
  912. // bin32 is installed by bin32.vendor_binary.31.arm64
  913. ctx.ModuleForTests("bin32.vendor_binary.31.arm64", binary32Variant).Output("bin32")
  914. // bin_without_snapshot is installed by bin_without_snapshot
  915. ctx.ModuleForTests("bin_without_snapshot", binaryVariant).Output("bin_without_snapshot")
  916. // libvendor, libvendor_available and bin don't have vendor.31 variant
  917. libvendorVariants := ctx.ModuleVariantsForTests("libvendor")
  918. if inList(sharedVariant, libvendorVariants) {
  919. t.Errorf("libvendor must not have variant %#v, but it does", sharedVariant)
  920. }
  921. libvendorAvailableVariants := ctx.ModuleVariantsForTests("libvendor_available")
  922. if inList(sharedVariant, libvendorAvailableVariants) {
  923. t.Errorf("libvendor_available must not have variant %#v, but it does", sharedVariant)
  924. }
  925. binVariants := ctx.ModuleVariantsForTests("bin")
  926. if inList(binaryVariant, binVariants) {
  927. t.Errorf("bin must not have variant %#v, but it does", sharedVariant)
  928. }
  929. // test overrides property
  930. binOverrideModule := ctx.ModuleForTests("bin_override.vendor_binary.31.arm64", binaryVariant)
  931. binOverrideModule.Output("bin")
  932. binOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, binOverrideModule.Module())
  933. binOverrideEntry := binOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
  934. if !inList("bin", binOverrideEntry) {
  935. t.Errorf("bin_override must override bin but was %q\n", binOverrideEntry)
  936. }
  937. libvendorOverrideModule := ctx.ModuleForTests("libvendor_override.vendor_shared.31.arm64", sharedVariant)
  938. libvendorOverrideModule.Output("libvendor.so")
  939. libvendorOverrideMkEntries := android.AndroidMkEntriesForTest(t, ctx, libvendorOverrideModule.Module())
  940. libvendorOverrideEntry := libvendorOverrideMkEntries[0].EntryMap["LOCAL_OVERRIDES_MODULES"]
  941. if !inList("libvendor", libvendorOverrideEntry) {
  942. t.Errorf("libvendor_override must override libvendor but was %q\n", libvendorOverrideEntry)
  943. }
  944. }
  945. func TestVendorSnapshotSanitizer(t *testing.T) {
  946. bp := `
  947. vendor_snapshot {
  948. name: "vendor_snapshot",
  949. version: "28",
  950. arch: {
  951. arm64: {
  952. static_libs: [
  953. "libsnapshot",
  954. "note_memtag_heap_sync",
  955. ],
  956. objects: [
  957. "snapshot_object",
  958. ],
  959. vndk_libs: [
  960. "libclang_rt.hwasan",
  961. ],
  962. },
  963. },
  964. }
  965. vendor_snapshot_static {
  966. name: "libsnapshot",
  967. vendor: true,
  968. target_arch: "arm64",
  969. version: "28",
  970. arch: {
  971. arm64: {
  972. src: "libsnapshot.a",
  973. cfi: {
  974. src: "libsnapshot.cfi.a",
  975. },
  976. hwasan: {
  977. src: "libsnapshot.hwasan.a",
  978. },
  979. },
  980. },
  981. }
  982. vendor_snapshot_static {
  983. name: "note_memtag_heap_sync",
  984. vendor: true,
  985. target_arch: "arm64",
  986. version: "28",
  987. arch: {
  988. arm64: {
  989. src: "note_memtag_heap_sync.a",
  990. },
  991. },
  992. }
  993. vndk_prebuilt_shared {
  994. name: "libclang_rt.hwasan",
  995. version: "28",
  996. target_arch: "arm64",
  997. vendor_available: true,
  998. product_available: true,
  999. vndk: {
  1000. enabled: true,
  1001. },
  1002. arch: {
  1003. arm64: {
  1004. srcs: ["libclang_rt.hwasan.so"],
  1005. },
  1006. },
  1007. }
  1008. vendor_snapshot_object {
  1009. name: "snapshot_object",
  1010. vendor: true,
  1011. target_arch: "arm64",
  1012. version: "28",
  1013. arch: {
  1014. arm64: {
  1015. src: "snapshot_object.o",
  1016. },
  1017. },
  1018. stl: "none",
  1019. }
  1020. cc_test {
  1021. name: "vstest",
  1022. gtest: false,
  1023. vendor: true,
  1024. compile_multilib: "64",
  1025. nocrt: true,
  1026. no_libcrt: true,
  1027. stl: "none",
  1028. static_libs: ["libsnapshot"],
  1029. system_shared_libs: [],
  1030. }
  1031. `
  1032. mockFS := map[string][]byte{
  1033. "vendor/Android.bp": []byte(bp),
  1034. "vendor/libc++demangle.a": nil,
  1035. "vendor/libclang_rt.hwasan.so": nil,
  1036. "vendor/libsnapshot.a": nil,
  1037. "vendor/libsnapshot.cfi.a": nil,
  1038. "vendor/libsnapshot.hwasan.a": nil,
  1039. "vendor/note_memtag_heap_sync.a": nil,
  1040. "vendor/snapshot_object.o": nil,
  1041. }
  1042. config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
  1043. config.TestProductVariables.DeviceVndkVersion = StringPtr("28")
  1044. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1045. config.TestProductVariables.SanitizeDevice = []string{"hwaddress"}
  1046. ctx := testCcWithConfig(t, config)
  1047. // Check non-cfi, cfi and hwasan variant.
  1048. staticVariant := "android_vendor.28_arm64_armv8-a_static"
  1049. staticCfiVariant := "android_vendor.28_arm64_armv8-a_static_cfi"
  1050. staticHwasanVariant := "android_vendor.28_arm64_armv8-a_static_hwasan"
  1051. staticHwasanCfiVariant := "android_vendor.28_arm64_armv8-a_static_hwasan_cfi"
  1052. staticModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticVariant).Module().(*Module)
  1053. assertString(t, staticModule.outputFile.Path().Base(), "libsnapshot.a")
  1054. staticCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticCfiVariant).Module().(*Module)
  1055. assertString(t, staticCfiModule.outputFile.Path().Base(), "libsnapshot.cfi.a")
  1056. staticHwasanModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanVariant).Module().(*Module)
  1057. assertString(t, staticHwasanModule.outputFile.Path().Base(), "libsnapshot.hwasan.a")
  1058. staticHwasanCfiModule := ctx.ModuleForTests("libsnapshot.vendor_static.28.arm64", staticHwasanCfiVariant).Module().(*Module)
  1059. if !staticHwasanCfiModule.HiddenFromMake() || !staticHwasanCfiModule.PreventInstall() {
  1060. t.Errorf("Hwasan and Cfi cannot enabled at the same time.")
  1061. }
  1062. snapshotObjModule := ctx.ModuleForTests("snapshot_object.vendor_object.28.arm64", "android_vendor.28_arm64_armv8-a").Module()
  1063. snapshotObjMkEntries := android.AndroidMkEntriesForTest(t, ctx, snapshotObjModule)
  1064. // snapshot object must not add ".hwasan" suffix
  1065. assertString(t, snapshotObjMkEntries[0].EntryMap["LOCAL_MODULE"][0], "snapshot_object")
  1066. }
  1067. func TestVendorSnapshotExclude(t *testing.T) {
  1068. // This test verifies that the exclude_from_vendor_snapshot property
  1069. // makes its way from the Android.bp source file into the module data
  1070. // structure. It also verifies that modules are correctly included or
  1071. // excluded in the vendor snapshot based on their path (framework or
  1072. // vendor) and the exclude_from_vendor_snapshot property.
  1073. frameworkBp := `
  1074. cc_library_shared {
  1075. name: "libinclude",
  1076. srcs: ["src/include.cpp"],
  1077. vendor_available: true,
  1078. }
  1079. cc_library_shared {
  1080. name: "libexclude",
  1081. srcs: ["src/exclude.cpp"],
  1082. vendor: true,
  1083. exclude_from_vendor_snapshot: true,
  1084. }
  1085. cc_library_shared {
  1086. name: "libavailable_exclude",
  1087. srcs: ["src/exclude.cpp"],
  1088. vendor_available: true,
  1089. exclude_from_vendor_snapshot: true,
  1090. }
  1091. `
  1092. vendorProprietaryBp := `
  1093. cc_library_shared {
  1094. name: "libvendor",
  1095. srcs: ["vendor.cpp"],
  1096. vendor: true,
  1097. }
  1098. `
  1099. depsBp := GatherRequiredDepsForTest(android.Android)
  1100. mockFS := map[string][]byte{
  1101. "deps/Android.bp": []byte(depsBp),
  1102. "framework/Android.bp": []byte(frameworkBp),
  1103. "framework/include.cpp": nil,
  1104. "framework/exclude.cpp": nil,
  1105. "device/Android.bp": []byte(vendorProprietaryBp),
  1106. "device/vendor.cpp": nil,
  1107. }
  1108. config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
  1109. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  1110. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1111. ctx := CreateTestContext(config)
  1112. ctx.Register()
  1113. _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
  1114. android.FailIfErrored(t, errs)
  1115. _, errs = ctx.PrepareBuildActions(config)
  1116. android.FailIfErrored(t, errs)
  1117. // Test an include and exclude framework module.
  1118. AssertExcludeFromVendorSnapshotIs(t, ctx, "libinclude", false, vendorVariant)
  1119. AssertExcludeFromVendorSnapshotIs(t, ctx, "libexclude", true, vendorVariant)
  1120. AssertExcludeFromVendorSnapshotIs(t, ctx, "libavailable_exclude", true, vendorVariant)
  1121. // A vendor module is excluded, but by its path, not the
  1122. // exclude_from_vendor_snapshot property.
  1123. AssertExcludeFromVendorSnapshotIs(t, ctx, "libvendor", false, vendorVariant)
  1124. // Verify the content of the vendor snapshot.
  1125. snapshotDir := "vendor-snapshot"
  1126. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  1127. snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
  1128. var includeJsonFiles []string
  1129. var excludeJsonFiles []string
  1130. for _, arch := range [][]string{
  1131. []string{"arm64", "armv8-a"},
  1132. []string{"arm", "armv7-a-neon"},
  1133. } {
  1134. archType := arch[0]
  1135. archVariant := arch[1]
  1136. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  1137. sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
  1138. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  1139. // Included modules
  1140. CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
  1141. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
  1142. // Excluded modules
  1143. CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
  1144. excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
  1145. CheckSnapshotExclude(t, ctx, snapshotSingleton, "libvendor", "libvendor.so", sharedDir, sharedVariant)
  1146. excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libvendor.so.json"))
  1147. CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
  1148. excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
  1149. }
  1150. // Verify that each json file for an included module has a rule.
  1151. for _, jsonFile := range includeJsonFiles {
  1152. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  1153. t.Errorf("include json file %q not found", jsonFile)
  1154. }
  1155. }
  1156. // Verify that each json file for an excluded module has no rule.
  1157. for _, jsonFile := range excludeJsonFiles {
  1158. if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
  1159. t.Errorf("exclude json file %q found", jsonFile)
  1160. }
  1161. }
  1162. }
  1163. func TestVendorSnapshotExcludeInVendorProprietaryPathErrors(t *testing.T) {
  1164. // This test verifies that using the exclude_from_vendor_snapshot
  1165. // property on a module in a vendor proprietary path generates an
  1166. // error. These modules are already excluded, so we prohibit using the
  1167. // property in this way, which could add to confusion.
  1168. vendorProprietaryBp := `
  1169. cc_library_shared {
  1170. name: "libvendor",
  1171. srcs: ["vendor.cpp"],
  1172. vendor: true,
  1173. exclude_from_vendor_snapshot: true,
  1174. }
  1175. `
  1176. depsBp := GatherRequiredDepsForTest(android.Android)
  1177. mockFS := map[string][]byte{
  1178. "deps/Android.bp": []byte(depsBp),
  1179. "device/Android.bp": []byte(vendorProprietaryBp),
  1180. "device/vendor.cpp": nil,
  1181. }
  1182. config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
  1183. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  1184. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1185. ctx := CreateTestContext(config)
  1186. ctx.Register()
  1187. _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "device/Android.bp"})
  1188. android.FailIfErrored(t, errs)
  1189. _, errs = ctx.PrepareBuildActions(config)
  1190. android.CheckErrorsAgainstExpectations(t, errs, []string{
  1191. `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
  1192. `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
  1193. `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
  1194. `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
  1195. `module "libvendor\{.+,image:vendor.+,arch:arm64_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
  1196. `module "libvendor\{.+,image:vendor.+,arch:arm_.+\}" in vendor proprietary path "device" may not use "exclude_from_vendor_snapshot: true"`,
  1197. })
  1198. }
  1199. func TestRecoverySnapshotCapture(t *testing.T) {
  1200. bp := `
  1201. cc_library {
  1202. name: "libvndk",
  1203. vendor_available: true,
  1204. recovery_available: true,
  1205. product_available: true,
  1206. vndk: {
  1207. enabled: true,
  1208. },
  1209. nocrt: true,
  1210. }
  1211. cc_library {
  1212. name: "librecovery",
  1213. recovery: true,
  1214. nocrt: true,
  1215. }
  1216. cc_library {
  1217. name: "librecovery_available",
  1218. recovery_available: true,
  1219. nocrt: true,
  1220. }
  1221. cc_library_headers {
  1222. name: "librecovery_headers",
  1223. recovery_available: true,
  1224. nocrt: true,
  1225. }
  1226. cc_binary {
  1227. name: "recovery_bin",
  1228. recovery: true,
  1229. nocrt: true,
  1230. }
  1231. cc_binary {
  1232. name: "recovery_available_bin",
  1233. recovery_available: true,
  1234. nocrt: true,
  1235. }
  1236. cc_prebuilt_library_static {
  1237. name: "libb",
  1238. recovery_available: true,
  1239. srcs: ["libb.a"],
  1240. nocrt: true,
  1241. no_libcrt: true,
  1242. stl: "none",
  1243. }
  1244. cc_object {
  1245. name: "obj",
  1246. recovery_available: true,
  1247. }
  1248. `
  1249. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  1250. config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
  1251. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1252. ctx := testCcWithConfig(t, config)
  1253. // Check Recovery snapshot output.
  1254. snapshotDir := "recovery-snapshot"
  1255. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  1256. snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
  1257. var jsonFiles []string
  1258. for _, arch := range [][]string{
  1259. []string{"arm64", "armv8-a"},
  1260. } {
  1261. archType := arch[0]
  1262. archVariant := arch[1]
  1263. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  1264. // For shared libraries, only recovery_available modules are captured.
  1265. sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
  1266. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  1267. CheckSnapshot(t, ctx, snapshotSingleton, "libvndk", "libvndk.so", sharedDir, sharedVariant)
  1268. CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
  1269. CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
  1270. jsonFiles = append(jsonFiles,
  1271. filepath.Join(sharedDir, "libvndk.so.json"),
  1272. filepath.Join(sharedDir, "librecovery.so.json"),
  1273. filepath.Join(sharedDir, "librecovery_available.so.json"))
  1274. // For static libraries, all recovery:true and recovery_available modules are captured.
  1275. staticVariant := fmt.Sprintf("android_recovery_%s_%s_static", archType, archVariant)
  1276. staticDir := filepath.Join(snapshotVariantPath, archDir, "static")
  1277. CheckSnapshot(t, ctx, snapshotSingleton, "libb", "libb.a", staticDir, staticVariant)
  1278. CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.a", staticDir, staticVariant)
  1279. CheckSnapshot(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.a", staticDir, staticVariant)
  1280. jsonFiles = append(jsonFiles,
  1281. filepath.Join(staticDir, "libb.a.json"),
  1282. filepath.Join(staticDir, "librecovery.a.json"),
  1283. filepath.Join(staticDir, "librecovery_available.a.json"))
  1284. // For binary executables, all recovery:true and recovery_available modules are captured.
  1285. if archType == "arm64" {
  1286. binaryVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
  1287. binaryDir := filepath.Join(snapshotVariantPath, archDir, "binary")
  1288. CheckSnapshot(t, ctx, snapshotSingleton, "recovery_bin", "recovery_bin", binaryDir, binaryVariant)
  1289. CheckSnapshot(t, ctx, snapshotSingleton, "recovery_available_bin", "recovery_available_bin", binaryDir, binaryVariant)
  1290. jsonFiles = append(jsonFiles,
  1291. filepath.Join(binaryDir, "recovery_bin.json"),
  1292. filepath.Join(binaryDir, "recovery_available_bin.json"))
  1293. }
  1294. // For header libraries, all vendor:true and vendor_available modules are captured.
  1295. headerDir := filepath.Join(snapshotVariantPath, archDir, "header")
  1296. jsonFiles = append(jsonFiles, filepath.Join(headerDir, "librecovery_headers.json"))
  1297. // For object modules, all vendor:true and vendor_available modules are captured.
  1298. objectVariant := fmt.Sprintf("android_recovery_%s_%s", archType, archVariant)
  1299. objectDir := filepath.Join(snapshotVariantPath, archDir, "object")
  1300. CheckSnapshot(t, ctx, snapshotSingleton, "obj", "obj.o", objectDir, objectVariant)
  1301. jsonFiles = append(jsonFiles, filepath.Join(objectDir, "obj.o.json"))
  1302. }
  1303. for _, jsonFile := range jsonFiles {
  1304. // verify all json files exist
  1305. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  1306. t.Errorf("%q expected but not found", jsonFile)
  1307. }
  1308. }
  1309. }
  1310. func TestRecoverySnapshotExclude(t *testing.T) {
  1311. // This test verifies that the exclude_from_recovery_snapshot property
  1312. // makes its way from the Android.bp source file into the module data
  1313. // structure. It also verifies that modules are correctly included or
  1314. // excluded in the recovery snapshot based on their path (framework or
  1315. // vendor) and the exclude_from_recovery_snapshot property.
  1316. frameworkBp := `
  1317. cc_library_shared {
  1318. name: "libinclude",
  1319. srcs: ["src/include.cpp"],
  1320. recovery_available: true,
  1321. }
  1322. cc_library_shared {
  1323. name: "libexclude",
  1324. srcs: ["src/exclude.cpp"],
  1325. recovery: true,
  1326. exclude_from_recovery_snapshot: true,
  1327. }
  1328. cc_library_shared {
  1329. name: "libavailable_exclude",
  1330. srcs: ["src/exclude.cpp"],
  1331. recovery_available: true,
  1332. exclude_from_recovery_snapshot: true,
  1333. }
  1334. `
  1335. vendorProprietaryBp := `
  1336. cc_library_shared {
  1337. name: "librecovery",
  1338. srcs: ["recovery.cpp"],
  1339. recovery: true,
  1340. }
  1341. `
  1342. depsBp := GatherRequiredDepsForTest(android.Android)
  1343. mockFS := map[string][]byte{
  1344. "deps/Android.bp": []byte(depsBp),
  1345. "framework/Android.bp": []byte(frameworkBp),
  1346. "framework/include.cpp": nil,
  1347. "framework/exclude.cpp": nil,
  1348. "device/Android.bp": []byte(vendorProprietaryBp),
  1349. "device/recovery.cpp": nil,
  1350. }
  1351. config := TestConfig(t.TempDir(), android.Android, nil, "", mockFS)
  1352. config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
  1353. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1354. ctx := CreateTestContext(config)
  1355. ctx.Register()
  1356. _, errs := ctx.ParseFileList(".", []string{"deps/Android.bp", "framework/Android.bp", "device/Android.bp"})
  1357. android.FailIfErrored(t, errs)
  1358. _, errs = ctx.PrepareBuildActions(config)
  1359. android.FailIfErrored(t, errs)
  1360. // Test an include and exclude framework module.
  1361. AssertExcludeFromRecoverySnapshotIs(t, ctx, "libinclude", false, recoveryVariant)
  1362. AssertExcludeFromRecoverySnapshotIs(t, ctx, "libexclude", true, recoveryVariant)
  1363. AssertExcludeFromRecoverySnapshotIs(t, ctx, "libavailable_exclude", true, recoveryVariant)
  1364. // A recovery module is excluded, but by its path, not the
  1365. // exclude_from_recovery_snapshot property.
  1366. AssertExcludeFromRecoverySnapshotIs(t, ctx, "librecovery", false, recoveryVariant)
  1367. // Verify the content of the recovery snapshot.
  1368. snapshotDir := "recovery-snapshot"
  1369. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  1370. snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
  1371. var includeJsonFiles []string
  1372. var excludeJsonFiles []string
  1373. for _, arch := range [][]string{
  1374. []string{"arm64", "armv8-a"},
  1375. } {
  1376. archType := arch[0]
  1377. archVariant := arch[1]
  1378. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  1379. sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
  1380. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  1381. // Included modules
  1382. CheckSnapshot(t, ctx, snapshotSingleton, "libinclude", "libinclude.so", sharedDir, sharedVariant)
  1383. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libinclude.so.json"))
  1384. // Excluded modules
  1385. CheckSnapshotExclude(t, ctx, snapshotSingleton, "libexclude", "libexclude.so", sharedDir, sharedVariant)
  1386. excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libexclude.so.json"))
  1387. CheckSnapshotExclude(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
  1388. excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
  1389. CheckSnapshotExclude(t, ctx, snapshotSingleton, "libavailable_exclude", "libavailable_exclude.so", sharedDir, sharedVariant)
  1390. excludeJsonFiles = append(excludeJsonFiles, filepath.Join(sharedDir, "libavailable_exclude.so.json"))
  1391. }
  1392. // Verify that each json file for an included module has a rule.
  1393. for _, jsonFile := range includeJsonFiles {
  1394. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  1395. t.Errorf("include json file %q not found", jsonFile)
  1396. }
  1397. }
  1398. // Verify that each json file for an excluded module has no rule.
  1399. for _, jsonFile := range excludeJsonFiles {
  1400. if snapshotSingleton.MaybeOutput(jsonFile).Rule != nil {
  1401. t.Errorf("exclude json file %q found", jsonFile)
  1402. }
  1403. }
  1404. }
  1405. func TestRecoverySnapshotDirected(t *testing.T) {
  1406. bp := `
  1407. cc_library_shared {
  1408. name: "librecovery",
  1409. recovery: true,
  1410. nocrt: true,
  1411. }
  1412. cc_library_shared {
  1413. name: "librecovery_available",
  1414. recovery_available: true,
  1415. nocrt: true,
  1416. }
  1417. genrule {
  1418. name: "libfoo_gen",
  1419. cmd: "",
  1420. out: ["libfoo.so"],
  1421. }
  1422. cc_prebuilt_library_shared {
  1423. name: "libfoo",
  1424. recovery: true,
  1425. prefer: true,
  1426. srcs: [":libfoo_gen"],
  1427. }
  1428. cc_library_shared {
  1429. name: "libfoo",
  1430. recovery: true,
  1431. nocrt: true,
  1432. }
  1433. `
  1434. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  1435. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  1436. config.TestProductVariables.RecoverySnapshotVersion = StringPtr("current")
  1437. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1438. config.TestProductVariables.DirectedRecoverySnapshot = true
  1439. config.TestProductVariables.RecoverySnapshotModules = make(map[string]bool)
  1440. config.TestProductVariables.RecoverySnapshotModules["librecovery"] = true
  1441. config.TestProductVariables.RecoverySnapshotModules["libfoo"] = true
  1442. ctx := testCcWithConfig(t, config)
  1443. // Check recovery snapshot output.
  1444. snapshotDir := "recovery-snapshot"
  1445. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  1446. snapshotSingleton := ctx.SingletonForTests("recovery-snapshot")
  1447. var includeJsonFiles []string
  1448. for _, arch := range [][]string{
  1449. []string{"arm64", "armv8-a"},
  1450. } {
  1451. archType := arch[0]
  1452. archVariant := arch[1]
  1453. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  1454. sharedVariant := fmt.Sprintf("android_recovery_%s_%s_shared", archType, archVariant)
  1455. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  1456. // Included modules
  1457. CheckSnapshot(t, ctx, snapshotSingleton, "librecovery", "librecovery.so", sharedDir, sharedVariant)
  1458. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery.so.json"))
  1459. // Check that snapshot captures "prefer: true" prebuilt
  1460. CheckSnapshot(t, ctx, snapshotSingleton, "prebuilt_libfoo", "libfoo.so", sharedDir, sharedVariant)
  1461. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "libfoo.so.json"))
  1462. // Excluded modules. Modules not included in the directed recovery snapshot
  1463. // are still include as fake modules.
  1464. CheckSnapshotRule(t, ctx, snapshotSingleton, "librecovery_available", "librecovery_available.so", sharedDir, sharedVariant)
  1465. includeJsonFiles = append(includeJsonFiles, filepath.Join(sharedDir, "librecovery_available.so.json"))
  1466. }
  1467. // Verify that each json file for an included module has a rule.
  1468. for _, jsonFile := range includeJsonFiles {
  1469. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  1470. t.Errorf("include json file %q not found", jsonFile)
  1471. }
  1472. }
  1473. }
  1474. func TestSnapshotInRelativeInstallPath(t *testing.T) {
  1475. bp := `
  1476. cc_library {
  1477. name: "libvendor_available",
  1478. vendor_available: true,
  1479. nocrt: true,
  1480. }
  1481. cc_library {
  1482. name: "libvendor_available_var",
  1483. vendor_available: true,
  1484. stem: "libvendor_available",
  1485. relative_install_path: "var",
  1486. nocrt: true,
  1487. }
  1488. `
  1489. config := TestConfig(t.TempDir(), android.Android, nil, bp, nil)
  1490. config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
  1491. config.TestProductVariables.Platform_vndk_version = StringPtr("29")
  1492. ctx := testCcWithConfig(t, config)
  1493. // Check Vendor snapshot output.
  1494. snapshotDir := "vendor-snapshot"
  1495. snapshotVariantPath := filepath.Join("out/soong", snapshotDir, "arm64")
  1496. snapshotSingleton := ctx.SingletonForTests("vendor-snapshot")
  1497. var jsonFiles []string
  1498. for _, arch := range [][]string{
  1499. []string{"arm64", "armv8-a"},
  1500. []string{"arm", "armv7-a-neon"},
  1501. } {
  1502. archType := arch[0]
  1503. archVariant := arch[1]
  1504. archDir := fmt.Sprintf("arch-%s-%s", archType, archVariant)
  1505. // For shared libraries, only non-VNDK vendor_available modules are captured
  1506. sharedVariant := fmt.Sprintf("android_vendor.29_%s_%s_shared", archType, archVariant)
  1507. sharedDir := filepath.Join(snapshotVariantPath, archDir, "shared")
  1508. sharedDirVar := filepath.Join(sharedDir, "var")
  1509. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available", "libvendor_available.so", sharedDir, sharedVariant)
  1510. CheckSnapshot(t, ctx, snapshotSingleton, "libvendor_available_var", "libvendor_available.so", sharedDirVar, sharedVariant)
  1511. jsonFiles = append(jsonFiles,
  1512. filepath.Join(sharedDir, "libvendor_available.so.json"),
  1513. filepath.Join(sharedDirVar, "libvendor_available.so.json"))
  1514. }
  1515. for _, jsonFile := range jsonFiles {
  1516. // verify all json files exist
  1517. if snapshotSingleton.MaybeOutput(jsonFile).Rule == nil {
  1518. t.Errorf("%q expected but not found", jsonFile)
  1519. }
  1520. }
  1521. // fake snapshot should have all outputs in the normal snapshot.
  1522. fakeSnapshotSingleton := ctx.SingletonForTests("vendor-fake-snapshot")
  1523. for _, output := range snapshotSingleton.AllOutputs() {
  1524. fakeOutput := strings.Replace(output, "/vendor-snapshot/", "/fake/vendor-snapshot/", 1)
  1525. if fakeSnapshotSingleton.MaybeOutput(fakeOutput).Rule == nil {
  1526. t.Errorf("%q expected but not found", fakeOutput)
  1527. }
  1528. }
  1529. }