rust_unit_tests_group.gni 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # Copyright 2021 The Chromium Authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # Defines a Rust unit tests group.
  5. #
  6. # This generates a script that wraps 1 or more Rust unit test executables.
  7. # Such script would typically wrap all Rust unit tests from a set of related
  8. # crates (e.g. all crates under //base).
  9. #
  10. # The script is primarily useful to enable running the tests on Chromium bots,
  11. # but it is also a convenience for having a single entry point for running
  12. # the tests locally (without having to manually fan out to all the individual
  13. # executables).
  14. #
  15. # Parameters:
  16. #
  17. # deps - Will be recursively traversed to discover all the Rust unit test
  18. # executables.
  19. #
  20. # Example usage:
  21. #
  22. # # This will generate a script at out/Default/bin/run_foo_tests that wraps
  23. # # out/Default/foo_crate1_unittests,
  24. # # out/Default/foo_mixed_source_set2_rs_unittests,
  25. # # and out/Default/foo_mixed_source_set3_rs_unittests executables containing
  26. # # native Rust unit tests.
  27. # rust_unit_tests_group("foo_tests") {
  28. # deps = [
  29. # "foo_crate1",
  30. # "foo_mixed_source_set2",
  31. # "foo_mixed_source_set3",
  32. # ]
  33. # }
  34. # # TODO(https://crbug.com/1271215): Mention .bat generation once implemented.
  35. template("rust_unit_tests_group") {
  36. assert(defined(invoker.deps), "deps must be listed")
  37. # As noted in the top-level comment of //testing/buildbot/gn_isolate_map.pyl
  38. # the script *must* be in output_dir/bin/run_$target (or
  39. # output_dir\bin\run_$target.bat on Windows).
  40. _script_filepath = "$root_out_dir/bin/run_${target_name}"
  41. # Gathering metadata provided by the rust_unit_test gni template from all of
  42. # our dependencies.
  43. _metadata_target_name = "${target_name}_metadata"
  44. _metadata_filepath = "$root_build_dir/${target_name}__rust_unittest_exes.txt"
  45. generated_file(_metadata_target_name) {
  46. forward_variables_from(invoker, [ "deps" ], [])
  47. testonly = true
  48. outputs = [ _metadata_filepath ]
  49. data_keys = [ "rust_unit_test_executables" ]
  50. }
  51. # Generating a script that can run all of the wrapped Rust unit test
  52. # executables.
  53. #
  54. # TODO(https://crbug.com/1271215): Also generate: bin/run_${target_name}.bat
  55. # when *targeting* Windows: if (is_win) { ... }. (The "targeting" part means
  56. # that we can't just detect whether the build is *hosted* on Windows.)
  57. action(target_name) {
  58. forward_variables_from(invoker, "*", [])
  59. testonly = true
  60. script = "//testing/scripts/rust/generate_bash_script.py"
  61. inputs = [ _metadata_filepath ]
  62. outputs = [ _script_filepath ]
  63. data = [ _script_filepath ]
  64. if (!defined(data_deps)) {
  65. data_deps = []
  66. }
  67. data_deps += [ "//testing/scripts/rust" ]
  68. data_deps += deps
  69. deps += [ ":$_metadata_target_name" ]
  70. args = [
  71. "--rust-test-executables",
  72. rebase_path(_metadata_filepath, root_build_dir),
  73. "--exe-dir",
  74. rebase_path(root_out_dir, root_build_dir),
  75. "--script-path",
  76. rebase_path(_script_filepath, root_build_dir),
  77. ]
  78. }
  79. }