androidmk_test.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  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 android
  15. import (
  16. "fmt"
  17. "io"
  18. "reflect"
  19. "runtime"
  20. "strings"
  21. "testing"
  22. "github.com/google/blueprint/proptools"
  23. )
  24. type customModule struct {
  25. ModuleBase
  26. properties struct {
  27. Default_dist_files *string
  28. Dist_output_file *bool
  29. }
  30. data AndroidMkData
  31. distFiles TaggedDistFiles
  32. outputFile OptionalPath
  33. // The paths that will be used as the default dist paths if no tag is
  34. // specified.
  35. defaultDistPaths Paths
  36. }
  37. const (
  38. defaultDistFiles_None = "none"
  39. defaultDistFiles_Default = "default"
  40. defaultDistFiles_Tagged = "tagged"
  41. )
  42. func (m *customModule) GenerateAndroidBuildActions(ctx ModuleContext) {
  43. m.base().licenseMetadataFile = PathForOutput(ctx, "meta_lic")
  44. // If the dist_output_file: true then create an output file that is stored in
  45. // the OutputFile property of the AndroidMkEntry.
  46. if proptools.BoolDefault(m.properties.Dist_output_file, true) {
  47. path := PathForTesting("dist-output-file.out")
  48. m.outputFile = OptionalPathForPath(path)
  49. // Previous code would prioritize the DistFiles property over the OutputFile
  50. // property in AndroidMkEntry when determining the default dist paths.
  51. // Setting this first allows it to be overridden based on the
  52. // default_dist_files setting replicating that previous behavior.
  53. m.defaultDistPaths = Paths{path}
  54. }
  55. // Based on the setting of the default_dist_files property possibly create a
  56. // TaggedDistFiles structure that will be stored in the DistFiles property of
  57. // the AndroidMkEntry.
  58. defaultDistFiles := proptools.StringDefault(m.properties.Default_dist_files, defaultDistFiles_Tagged)
  59. switch defaultDistFiles {
  60. case defaultDistFiles_None:
  61. // Do nothing
  62. case defaultDistFiles_Default:
  63. path := PathForTesting("default-dist.out")
  64. m.defaultDistPaths = Paths{path}
  65. m.distFiles = MakeDefaultDistFiles(path)
  66. case defaultDistFiles_Tagged:
  67. // Module types that set AndroidMkEntry.DistFiles to the result of calling
  68. // GenerateTaggedDistFiles(ctx) relied on no tag being treated as "" which
  69. // meant that the default dist paths would be whatever was returned by
  70. // OutputFiles(""). In order to preserve that behavior when treating no tag
  71. // as being equal to DefaultDistTag this ensures that
  72. // OutputFiles(DefaultDistTag) will return the same as OutputFiles("").
  73. m.defaultDistPaths = PathsForTesting("one.out")
  74. // This must be called after setting defaultDistPaths/outputFile as
  75. // GenerateTaggedDistFiles calls into OutputFiles(tag) which may use those
  76. // fields.
  77. m.distFiles = m.GenerateTaggedDistFiles(ctx)
  78. }
  79. }
  80. func (m *customModule) AndroidMk() AndroidMkData {
  81. return AndroidMkData{
  82. Custom: func(w io.Writer, name, prefix, moduleDir string, data AndroidMkData) {
  83. m.data = data
  84. },
  85. }
  86. }
  87. func (m *customModule) OutputFiles(tag string) (Paths, error) {
  88. switch tag {
  89. case DefaultDistTag:
  90. if m.defaultDistPaths != nil {
  91. return m.defaultDistPaths, nil
  92. } else {
  93. return nil, fmt.Errorf("default dist tag is not available")
  94. }
  95. case "":
  96. return PathsForTesting("one.out"), nil
  97. case ".multiple":
  98. return PathsForTesting("two.out", "three/four.out"), nil
  99. case ".another-tag":
  100. return PathsForTesting("another.out"), nil
  101. default:
  102. return nil, fmt.Errorf("unsupported module reference tag %q", tag)
  103. }
  104. }
  105. func (m *customModule) AndroidMkEntries() []AndroidMkEntries {
  106. return []AndroidMkEntries{
  107. {
  108. Class: "CUSTOM_MODULE",
  109. DistFiles: m.distFiles,
  110. OutputFile: m.outputFile,
  111. },
  112. }
  113. }
  114. func customModuleFactory() Module {
  115. module := &customModule{}
  116. module.AddProperties(&module.properties)
  117. InitAndroidModule(module)
  118. return module
  119. }
  120. // buildContextAndCustomModuleFoo creates a config object, processes the supplied
  121. // bp module and then returns the config and the custom module called "foo".
  122. func buildContextAndCustomModuleFoo(t *testing.T, bp string) (*TestContext, *customModule) {
  123. t.Helper()
  124. result := GroupFixturePreparers(
  125. // Enable androidmk Singleton
  126. PrepareForTestWithAndroidMk,
  127. FixtureRegisterWithContext(func(ctx RegistrationContext) {
  128. ctx.RegisterModuleType("custom", customModuleFactory)
  129. }),
  130. FixtureModifyProductVariables(func(variables FixtureProductVariables) {
  131. variables.DeviceProduct = proptools.StringPtr("bar")
  132. }),
  133. FixtureWithRootAndroidBp(bp),
  134. ).RunTest(t)
  135. module := result.ModuleForTests("foo", "").Module().(*customModule)
  136. return result.TestContext, module
  137. }
  138. func TestAndroidMkSingleton_PassesUpdatedAndroidMkDataToCustomCallback(t *testing.T) {
  139. if runtime.GOOS == "darwin" {
  140. // Device modules are not exported on Mac, so this test doesn't work.
  141. t.SkipNow()
  142. }
  143. bp := `
  144. custom {
  145. name: "foo",
  146. required: ["bar"],
  147. host_required: ["baz"],
  148. target_required: ["qux"],
  149. }
  150. `
  151. _, m := buildContextAndCustomModuleFoo(t, bp)
  152. assertEqual := func(expected interface{}, actual interface{}) {
  153. if !reflect.DeepEqual(expected, actual) {
  154. t.Errorf("%q expected, but got %q", expected, actual)
  155. }
  156. }
  157. assertEqual([]string{"bar"}, m.data.Required)
  158. assertEqual([]string{"baz"}, m.data.Host_required)
  159. assertEqual([]string{"qux"}, m.data.Target_required)
  160. }
  161. func TestGenerateDistContributionsForMake(t *testing.T) {
  162. dc := &distContributions{
  163. copiesForGoals: []*copiesForGoals{
  164. {
  165. goals: "my_goal",
  166. copies: []distCopy{
  167. distCopyForTest("one.out", "one.out"),
  168. distCopyForTest("two.out", "other.out"),
  169. },
  170. },
  171. },
  172. }
  173. dc.licenseMetadataFile = PathForTesting("meta_lic")
  174. makeOutput := generateDistContributionsForMake(dc)
  175. assertStringEquals(t, `.PHONY: my_goal
  176. $(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))
  177. $(call dist-for-goals,my_goal,one.out:one.out)
  178. $(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))
  179. $(call dist-for-goals,my_goal,two.out:other.out)
  180. `, strings.Join(makeOutput, ""))
  181. }
  182. func TestGetDistForGoals(t *testing.T) {
  183. bp := `
  184. custom {
  185. name: "foo",
  186. dist: {
  187. targets: ["my_goal", "my_other_goal"],
  188. tag: ".multiple",
  189. },
  190. dists: [
  191. {
  192. targets: ["my_second_goal"],
  193. tag: ".multiple",
  194. },
  195. {
  196. targets: ["my_third_goal"],
  197. dir: "test/dir",
  198. },
  199. {
  200. targets: ["my_fourth_goal"],
  201. suffix: ".suffix",
  202. },
  203. {
  204. targets: ["my_fifth_goal"],
  205. dest: "new-name",
  206. },
  207. {
  208. targets: ["my_sixth_goal"],
  209. dest: "new-name",
  210. dir: "some/dir",
  211. suffix: ".suffix",
  212. },
  213. ],
  214. }
  215. `
  216. expectedAndroidMkLines := []string{
  217. ".PHONY: my_second_goal\n",
  218. "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n",
  219. "$(call dist-for-goals,my_second_goal,two.out:two.out)\n",
  220. "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n",
  221. "$(call dist-for-goals,my_second_goal,three/four.out:four.out)\n",
  222. ".PHONY: my_third_goal\n",
  223. "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
  224. "$(call dist-for-goals,my_third_goal,one.out:test/dir/one.out)\n",
  225. ".PHONY: my_fourth_goal\n",
  226. "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
  227. "$(call dist-for-goals,my_fourth_goal,one.out:one.suffix.out)\n",
  228. ".PHONY: my_fifth_goal\n",
  229. "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
  230. "$(call dist-for-goals,my_fifth_goal,one.out:new-name)\n",
  231. ".PHONY: my_sixth_goal\n",
  232. "$(if $(strip $(ALL_TARGETS.one.out.META_LIC)),,$(eval ALL_TARGETS.one.out.META_LIC := meta_lic))\n",
  233. "$(call dist-for-goals,my_sixth_goal,one.out:some/dir/new-name.suffix)\n",
  234. ".PHONY: my_goal my_other_goal\n",
  235. "$(if $(strip $(ALL_TARGETS.two.out.META_LIC)),,$(eval ALL_TARGETS.two.out.META_LIC := meta_lic))\n",
  236. "$(call dist-for-goals,my_goal my_other_goal,two.out:two.out)\n",
  237. "$(if $(strip $(ALL_TARGETS.three/four.out.META_LIC)),,$(eval ALL_TARGETS.three/four.out.META_LIC := meta_lic))\n",
  238. "$(call dist-for-goals,my_goal my_other_goal,three/four.out:four.out)\n",
  239. }
  240. ctx, module := buildContextAndCustomModuleFoo(t, bp)
  241. entries := AndroidMkEntriesForTest(t, ctx, module)
  242. if len(entries) != 1 {
  243. t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))
  244. }
  245. androidMkLines := entries[0].GetDistForGoals(module)
  246. if len(androidMkLines) != len(expectedAndroidMkLines) {
  247. t.Errorf(
  248. "Expected %d AndroidMk lines, got %d:\n%v",
  249. len(expectedAndroidMkLines),
  250. len(androidMkLines),
  251. androidMkLines,
  252. )
  253. }
  254. for idx, line := range androidMkLines {
  255. expectedLine := strings.ReplaceAll(expectedAndroidMkLines[idx], "meta_lic", module.base().licenseMetadataFile.String())
  256. if line != expectedLine {
  257. t.Errorf(
  258. "Expected AndroidMk line to be '%s', got '%s'",
  259. expectedLine,
  260. line,
  261. )
  262. }
  263. }
  264. }
  265. func distCopyForTest(from, to string) distCopy {
  266. return distCopy{PathForTesting(from), to}
  267. }
  268. func TestGetDistContributions(t *testing.T) {
  269. compareContributions := func(d1 *distContributions, d2 *distContributions) error {
  270. if d1 == nil || d2 == nil {
  271. if d1 != d2 {
  272. return fmt.Errorf("pointer mismatch, expected both to be nil but they were %p and %p", d1, d2)
  273. } else {
  274. return nil
  275. }
  276. }
  277. if expected, actual := len(d1.copiesForGoals), len(d2.copiesForGoals); expected != actual {
  278. return fmt.Errorf("length mismatch, expected %d found %d", expected, actual)
  279. }
  280. for i, copies1 := range d1.copiesForGoals {
  281. copies2 := d2.copiesForGoals[i]
  282. if expected, actual := copies1.goals, copies2.goals; expected != actual {
  283. return fmt.Errorf("goals mismatch at position %d: expected %q found %q", i, expected, actual)
  284. }
  285. if expected, actual := len(copies1.copies), len(copies2.copies); expected != actual {
  286. return fmt.Errorf("length mismatch in copy instructions at position %d, expected %d found %d", i, expected, actual)
  287. }
  288. for j, c1 := range copies1.copies {
  289. c2 := copies2.copies[j]
  290. if expected, actual := NormalizePathForTesting(c1.from), NormalizePathForTesting(c2.from); expected != actual {
  291. return fmt.Errorf("paths mismatch at position %d.%d: expected %q found %q", i, j, expected, actual)
  292. }
  293. if expected, actual := c1.dest, c2.dest; expected != actual {
  294. return fmt.Errorf("dest mismatch at position %d.%d: expected %q found %q", i, j, expected, actual)
  295. }
  296. }
  297. }
  298. return nil
  299. }
  300. formatContributions := func(d *distContributions) string {
  301. buf := &strings.Builder{}
  302. if d == nil {
  303. fmt.Fprint(buf, "nil")
  304. } else {
  305. for _, copiesForGoals := range d.copiesForGoals {
  306. fmt.Fprintf(buf, " Goals: %q {\n", copiesForGoals.goals)
  307. for _, c := range copiesForGoals.copies {
  308. fmt.Fprintf(buf, " %s -> %s\n", NormalizePathForTesting(c.from), c.dest)
  309. }
  310. fmt.Fprint(buf, " }\n")
  311. }
  312. }
  313. return buf.String()
  314. }
  315. testHelper := func(t *testing.T, name, bp string, expectedContributions *distContributions) {
  316. t.Helper()
  317. t.Run(name, func(t *testing.T) {
  318. t.Helper()
  319. ctx, module := buildContextAndCustomModuleFoo(t, bp)
  320. entries := AndroidMkEntriesForTest(t, ctx, module)
  321. if len(entries) != 1 {
  322. t.Errorf("Expected a single AndroidMk entry, got %d", len(entries))
  323. }
  324. distContributions := entries[0].getDistContributions(module)
  325. if err := compareContributions(expectedContributions, distContributions); err != nil {
  326. t.Errorf("%s\nExpected Contributions\n%sActualContributions\n%s",
  327. err,
  328. formatContributions(expectedContributions),
  329. formatContributions(distContributions))
  330. }
  331. })
  332. }
  333. testHelper(t, "dist-without-tag", `
  334. custom {
  335. name: "foo",
  336. dist: {
  337. targets: ["my_goal"]
  338. }
  339. }
  340. `,
  341. &distContributions{
  342. copiesForGoals: []*copiesForGoals{
  343. {
  344. goals: "my_goal",
  345. copies: []distCopy{
  346. distCopyForTest("one.out", "one.out"),
  347. },
  348. },
  349. },
  350. })
  351. testHelper(t, "dist-with-tag", `
  352. custom {
  353. name: "foo",
  354. dist: {
  355. targets: ["my_goal"],
  356. tag: ".another-tag",
  357. }
  358. }
  359. `,
  360. &distContributions{
  361. copiesForGoals: []*copiesForGoals{
  362. {
  363. goals: "my_goal",
  364. copies: []distCopy{
  365. distCopyForTest("another.out", "another.out"),
  366. },
  367. },
  368. },
  369. })
  370. testHelper(t, "append-artifact-with-product", `
  371. custom {
  372. name: "foo",
  373. dist: {
  374. targets: ["my_goal"],
  375. append_artifact_with_product: true,
  376. }
  377. }
  378. `, &distContributions{
  379. copiesForGoals: []*copiesForGoals{
  380. {
  381. goals: "my_goal",
  382. copies: []distCopy{
  383. distCopyForTest("one.out", "one_bar.out"),
  384. },
  385. },
  386. },
  387. })
  388. testHelper(t, "dists-with-tag", `
  389. custom {
  390. name: "foo",
  391. dists: [
  392. {
  393. targets: ["my_goal"],
  394. tag: ".another-tag",
  395. },
  396. ],
  397. }
  398. `,
  399. &distContributions{
  400. copiesForGoals: []*copiesForGoals{
  401. {
  402. goals: "my_goal",
  403. copies: []distCopy{
  404. distCopyForTest("another.out", "another.out"),
  405. },
  406. },
  407. },
  408. })
  409. testHelper(t, "multiple-dists-with-and-without-tag", `
  410. custom {
  411. name: "foo",
  412. dists: [
  413. {
  414. targets: ["my_goal"],
  415. },
  416. {
  417. targets: ["my_second_goal", "my_third_goal"],
  418. },
  419. ],
  420. }
  421. `,
  422. &distContributions{
  423. copiesForGoals: []*copiesForGoals{
  424. {
  425. goals: "my_goal",
  426. copies: []distCopy{
  427. distCopyForTest("one.out", "one.out"),
  428. },
  429. },
  430. {
  431. goals: "my_second_goal my_third_goal",
  432. copies: []distCopy{
  433. distCopyForTest("one.out", "one.out"),
  434. },
  435. },
  436. },
  437. })
  438. testHelper(t, "dist-plus-dists-without-tags", `
  439. custom {
  440. name: "foo",
  441. dist: {
  442. targets: ["my_goal"],
  443. },
  444. dists: [
  445. {
  446. targets: ["my_second_goal", "my_third_goal"],
  447. },
  448. ],
  449. }
  450. `,
  451. &distContributions{
  452. copiesForGoals: []*copiesForGoals{
  453. {
  454. goals: "my_second_goal my_third_goal",
  455. copies: []distCopy{
  456. distCopyForTest("one.out", "one.out"),
  457. },
  458. },
  459. {
  460. goals: "my_goal",
  461. copies: []distCopy{
  462. distCopyForTest("one.out", "one.out"),
  463. },
  464. },
  465. },
  466. })
  467. testHelper(t, "dist-plus-dists-with-tags", `
  468. custom {
  469. name: "foo",
  470. dist: {
  471. targets: ["my_goal", "my_other_goal"],
  472. tag: ".multiple",
  473. },
  474. dists: [
  475. {
  476. targets: ["my_second_goal"],
  477. tag: ".multiple",
  478. },
  479. {
  480. targets: ["my_third_goal"],
  481. dir: "test/dir",
  482. },
  483. {
  484. targets: ["my_fourth_goal"],
  485. suffix: ".suffix",
  486. },
  487. {
  488. targets: ["my_fifth_goal"],
  489. dest: "new-name",
  490. },
  491. {
  492. targets: ["my_sixth_goal"],
  493. dest: "new-name",
  494. dir: "some/dir",
  495. suffix: ".suffix",
  496. },
  497. ],
  498. }
  499. `,
  500. &distContributions{
  501. copiesForGoals: []*copiesForGoals{
  502. {
  503. goals: "my_second_goal",
  504. copies: []distCopy{
  505. distCopyForTest("two.out", "two.out"),
  506. distCopyForTest("three/four.out", "four.out"),
  507. },
  508. },
  509. {
  510. goals: "my_third_goal",
  511. copies: []distCopy{
  512. distCopyForTest("one.out", "test/dir/one.out"),
  513. },
  514. },
  515. {
  516. goals: "my_fourth_goal",
  517. copies: []distCopy{
  518. distCopyForTest("one.out", "one.suffix.out"),
  519. },
  520. },
  521. {
  522. goals: "my_fifth_goal",
  523. copies: []distCopy{
  524. distCopyForTest("one.out", "new-name"),
  525. },
  526. },
  527. {
  528. goals: "my_sixth_goal",
  529. copies: []distCopy{
  530. distCopyForTest("one.out", "some/dir/new-name.suffix"),
  531. },
  532. },
  533. {
  534. goals: "my_goal my_other_goal",
  535. copies: []distCopy{
  536. distCopyForTest("two.out", "two.out"),
  537. distCopyForTest("three/four.out", "four.out"),
  538. },
  539. },
  540. },
  541. })
  542. // The above test the default values of default_dist_files and use_output_file.
  543. // The following tests explicitly test the different combinations of those settings.
  544. testHelper(t, "tagged-dist-files-no-output", `
  545. custom {
  546. name: "foo",
  547. default_dist_files: "tagged",
  548. dist_output_file: false,
  549. dists: [
  550. {
  551. targets: ["my_goal"],
  552. },
  553. {
  554. targets: ["my_goal"],
  555. tag: ".multiple",
  556. },
  557. ],
  558. }
  559. `, &distContributions{
  560. copiesForGoals: []*copiesForGoals{
  561. {
  562. goals: "my_goal",
  563. copies: []distCopy{
  564. distCopyForTest("one.out", "one.out"),
  565. },
  566. },
  567. {
  568. goals: "my_goal",
  569. copies: []distCopy{
  570. distCopyForTest("two.out", "two.out"),
  571. distCopyForTest("three/four.out", "four.out"),
  572. },
  573. },
  574. },
  575. })
  576. testHelper(t, "default-dist-files-no-output", `
  577. custom {
  578. name: "foo",
  579. default_dist_files: "default",
  580. dist_output_file: false,
  581. dists: [
  582. {
  583. targets: ["my_goal"],
  584. },
  585. {
  586. targets: ["my_goal"],
  587. tag: ".multiple",
  588. },
  589. ],
  590. }
  591. `, &distContributions{
  592. copiesForGoals: []*copiesForGoals{
  593. {
  594. goals: "my_goal",
  595. copies: []distCopy{
  596. distCopyForTest("default-dist.out", "default-dist.out"),
  597. },
  598. },
  599. {
  600. goals: "my_goal",
  601. copies: []distCopy{
  602. distCopyForTest("two.out", "two.out"),
  603. distCopyForTest("three/four.out", "four.out"),
  604. },
  605. },
  606. },
  607. })
  608. testHelper(t, "no-dist-files-no-output", `
  609. custom {
  610. name: "foo",
  611. default_dist_files: "none",
  612. dist_output_file: false,
  613. dists: [
  614. // The following is silently ignored because there is not default file
  615. // in either the dist files or the output file.
  616. {
  617. targets: ["my_goal"],
  618. },
  619. {
  620. targets: ["my_goal"],
  621. tag: ".multiple",
  622. },
  623. ],
  624. }
  625. `, &distContributions{
  626. copiesForGoals: []*copiesForGoals{
  627. {
  628. goals: "my_goal",
  629. copies: []distCopy{
  630. distCopyForTest("two.out", "two.out"),
  631. distCopyForTest("three/four.out", "four.out"),
  632. },
  633. },
  634. },
  635. })
  636. testHelper(t, "tagged-dist-files-default-output", `
  637. custom {
  638. name: "foo",
  639. default_dist_files: "tagged",
  640. dist_output_file: true,
  641. dists: [
  642. {
  643. targets: ["my_goal"],
  644. },
  645. {
  646. targets: ["my_goal"],
  647. tag: ".multiple",
  648. },
  649. ],
  650. }
  651. `, &distContributions{
  652. copiesForGoals: []*copiesForGoals{
  653. {
  654. goals: "my_goal",
  655. copies: []distCopy{
  656. distCopyForTest("one.out", "one.out"),
  657. },
  658. },
  659. {
  660. goals: "my_goal",
  661. copies: []distCopy{
  662. distCopyForTest("two.out", "two.out"),
  663. distCopyForTest("three/four.out", "four.out"),
  664. },
  665. },
  666. },
  667. })
  668. testHelper(t, "default-dist-files-default-output", `
  669. custom {
  670. name: "foo",
  671. default_dist_files: "default",
  672. dist_output_file: true,
  673. dists: [
  674. {
  675. targets: ["my_goal"],
  676. },
  677. {
  678. targets: ["my_goal"],
  679. tag: ".multiple",
  680. },
  681. ],
  682. }
  683. `, &distContributions{
  684. copiesForGoals: []*copiesForGoals{
  685. {
  686. goals: "my_goal",
  687. copies: []distCopy{
  688. distCopyForTest("default-dist.out", "default-dist.out"),
  689. },
  690. },
  691. {
  692. goals: "my_goal",
  693. copies: []distCopy{
  694. distCopyForTest("two.out", "two.out"),
  695. distCopyForTest("three/four.out", "four.out"),
  696. },
  697. },
  698. },
  699. })
  700. testHelper(t, "no-dist-files-default-output", `
  701. custom {
  702. name: "foo",
  703. default_dist_files: "none",
  704. dist_output_file: true,
  705. dists: [
  706. {
  707. targets: ["my_goal"],
  708. },
  709. {
  710. targets: ["my_goal"],
  711. tag: ".multiple",
  712. },
  713. ],
  714. }
  715. `, &distContributions{
  716. copiesForGoals: []*copiesForGoals{
  717. {
  718. goals: "my_goal",
  719. copies: []distCopy{
  720. distCopyForTest("dist-output-file.out", "dist-output-file.out"),
  721. },
  722. },
  723. {
  724. goals: "my_goal",
  725. copies: []distCopy{
  726. distCopyForTest("two.out", "two.out"),
  727. distCopyForTest("three/four.out", "four.out"),
  728. },
  729. },
  730. },
  731. })
  732. }