resource_sizes.gni 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright 2019 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. import("//build/config/android/internal_rules.gni")
  5. # Generates a script in the bin directory that runs
  6. # //build/android/resource_sizes.py against the provided apk.
  7. #
  8. # Only one of apk_name or file_path should be provided.
  9. #
  10. # Variables:
  11. # apk_name: The name of the apk, without the extension.
  12. # file_path: The path to the apk or .minimal.apks.
  13. # trichrome_chrome_path: The path to chrome apk or .minimal.apks.
  14. # trichrome_webview_path: The path to webview apk or .minimal.apks.
  15. # trichrome_library_path: The path to library apk or .minimal.apks.
  16. template("android_resource_sizes_test") {
  17. generate_android_wrapper(target_name) {
  18. forward_variables_from(invoker, [ "data_deps" ])
  19. executable = "//build/android/resource_sizes.py"
  20. wrapper_script = "$root_out_dir/bin/run_${target_name}"
  21. assert(defined(invoker.apk_name) != defined(invoker.file_path),
  22. "Exactly one of apk_name or file_path should be provided.")
  23. deps = [ "//build/android:resource_sizes_py" ]
  24. executable_args = [
  25. "--output-format",
  26. "histograms",
  27. "--chromium-output-directory",
  28. "@WrappedPath(.)",
  29. ]
  30. data = []
  31. if (defined(invoker.trichrome_chrome_path)) {
  32. data += [
  33. invoker.trichrome_chrome_path,
  34. invoker.trichrome_webview_path,
  35. invoker.trichrome_library_path,
  36. ]
  37. _rebased_chrome =
  38. rebase_path(invoker.trichrome_chrome_path, root_build_dir)
  39. _rebased_webview =
  40. rebase_path(invoker.trichrome_webview_path, root_build_dir)
  41. _rebased_library =
  42. rebase_path(invoker.trichrome_library_path, root_build_dir)
  43. # apk_name used only as test suite name. Not a path in this case.
  44. executable_args += [
  45. "--trichrome-chrome",
  46. "@WrappedPath(${_rebased_chrome})",
  47. "--trichrome-webview",
  48. "@WrappedPath(${_rebased_webview})",
  49. "--trichrome-library",
  50. "@WrappedPath(${_rebased_library})",
  51. "${invoker.apk_name}",
  52. ]
  53. } else {
  54. if (defined(invoker.apk_name)) {
  55. _file_path = "$root_out_dir/apks/${invoker.apk_name}.apk"
  56. data += [ "$root_out_dir/arsc/apks/${invoker.apk_name}.ap_" ]
  57. } else if (defined(invoker.file_path)) {
  58. _file_path = invoker.file_path
  59. }
  60. data += [ _file_path ]
  61. _rebased_file_path = rebase_path(_file_path, root_build_dir)
  62. executable_args += [ "@WrappedPath(${_rebased_file_path})" ]
  63. }
  64. }
  65. }
  66. # Generates a "size config JSON file" to specify data to be passed from recipes
  67. # to Python scripts for binary size measurement on bots. All filenames are
  68. # relative to $root_build_dir. The resulting JSON file is written to
  69. # "$root_build_dir/config/${invoker.name}_size_config.json".
  70. #
  71. # Refer to tools/binary_size/generate_commit_size_analysis.py for JSON schema.
  72. #
  73. template("android_size_bot_config") {
  74. _full_target_name = get_label_info(target_name, "label_no_toolchain")
  75. _out_json = {
  76. _HEADER = "Written by build target '${_full_target_name}'"
  77. forward_variables_from(invoker,
  78. [
  79. "archive_files",
  80. "mapping_files",
  81. "to_resource_sizes_py",
  82. "supersize_input_file",
  83. ])
  84. }
  85. _output_json_path = "$root_build_dir/config/${invoker.name}_size_config.json"
  86. write_file(_output_json_path, _out_json, "json")
  87. }