version.gni 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Copyright 2015 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. # This exposes the Chrome version as GN variables for use in build files.
  5. # This also generates the various version codes used for builds of chrome for
  6. # android.
  7. #
  8. # PREFER NOT TO USE THESE. The GYP build uses this kind of thing extensively.
  9. # However, it is far better to write an action (or use
  10. # //build/util/process_version.gni) to generate a file at build-time with the
  11. # information you need. This allows better dependency checking and GN will
  12. # run faster.
  13. #
  14. # These values should only be used if you REALLY need to depend on them at
  15. # build-time, for example, in the computation of output file names.
  16. # Give version.py a pattern that will expand to a GN scope consisting of
  17. # all values we need at once.
  18. _version_dictionary_template = "full = \"@MAJOR@.@MINOR@.@BUILD@.@PATCH@\" " +
  19. "major = \"@MAJOR@\" minor = \"@MINOR@\" " +
  20. "build = \"@BUILD@\" patch = \"@PATCH@\" "
  21. # The file containing the Chrome version number.
  22. chrome_version_file = "//chrome/VERSION"
  23. _script_arguments = []
  24. if (is_mac) {
  25. _version_dictionary_template += "patch_hi = @PATCH_HI@ patch_lo = @PATCH_LO@ "
  26. _script_arguments += [
  27. "-e",
  28. "PATCH_HI=int(PATCH)//256",
  29. "-e",
  30. "PATCH_LO=int(PATCH)%256",
  31. ]
  32. } else if (target_os == "android") {
  33. import("//build/config/android/config.gni")
  34. _version_dictionary_template +=
  35. "chrome_version_code = " + "\"@CHROME_VERSION_CODE@\" " +
  36. "chrome_modern_version_code = \"@CHROME_MODERN_VERSION_CODE@\" " +
  37. "monochrome_version_code = \"@MONOCHROME_VERSION_CODE@\" " +
  38. "trichrome_version_code = \"@TRICHROME_VERSION_CODE@\" " +
  39. "webview_stable_version_code = \"@WEBVIEW_STABLE_VERSION_CODE@\" " +
  40. "webview_beta_version_code = \"@WEBVIEW_BETA_VERSION_CODE@\" " +
  41. "webview_dev_version_code = \"@WEBVIEW_DEV_VERSION_CODE@\" "
  42. if (target_cpu == "arm64" || target_cpu == "x64") {
  43. _version_dictionary_template += "monochrome_32_version_code = \"@MONOCHROME_32_VERSION_CODE@\" " + "monochrome_32_64_version_code = \"@MONOCHROME_32_64_VERSION_CODE@\" " + "monochrome_64_32_version_code = \"@MONOCHROME_64_32_VERSION_CODE@\" " + "monochrome_64_version_code = \"@MONOCHROME_64_VERSION_CODE@\" " + "trichrome_32_version_code = \"@TRICHROME_32_VERSION_CODE@\" " + "trichrome_32_64_version_code = \"@TRICHROME_32_64_VERSION_CODE@\" " + "trichrome_64_32_version_code = \"@TRICHROME_64_32_VERSION_CODE@\" " + "trichrome_64_version_code = \"@TRICHROME_64_VERSION_CODE@\" " + "webview_32_stable_version_code = \"@WEBVIEW_32_STABLE_VERSION_CODE@\" " + "webview_32_beta_version_code = \"@WEBVIEW_32_BETA_VERSION_CODE@\" " + "webview_32_dev_version_code = \"@WEBVIEW_32_DEV_VERSION_CODE@\" " + "webview_64_stable_version_code = \"@WEBVIEW_64_STABLE_VERSION_CODE@\" " + "webview_64_beta_version_code = \"@WEBVIEW_64_BETA_VERSION_CODE@\" " + "webview_64_dev_version_code = \"@WEBVIEW_64_DEV_VERSION_CODE@\" "
  44. }
  45. _script_arguments += [
  46. "-a",
  47. target_cpu,
  48. ]
  49. if (defined(final_android_sdk) && !final_android_sdk) {
  50. _script_arguments += [ "--next" ]
  51. }
  52. }
  53. _script_arguments += [
  54. "-f",
  55. rebase_path(chrome_version_file, root_build_dir),
  56. "-t",
  57. _version_dictionary_template,
  58. "--os",
  59. target_os,
  60. ]
  61. _result = exec_script("//build/util/version.py",
  62. _script_arguments,
  63. "scope",
  64. [
  65. chrome_version_file,
  66. "//build/util/android_chrome_version.py",
  67. ])
  68. # Full version. For example "45.0.12321.0"
  69. chrome_version_full = _result.full
  70. # The constituent parts of the full version.
  71. chrome_version_major = _result.major
  72. chrome_version_minor = _result.minor
  73. chrome_version_build = _result.build
  74. chrome_version_patch = _result.patch
  75. if (is_mac) {
  76. chrome_version_patch_hi = _result.patch_hi
  77. chrome_version_patch_lo = _result.patch_lo
  78. chrome_dylib_version = "$chrome_version_build.$chrome_version_patch_hi" +
  79. ".$chrome_version_patch_lo"
  80. } else if (target_os == "android") {
  81. forward_variables_from(_result,
  82. [
  83. "chrome_modern_version_code",
  84. "chrome_version_code",
  85. "monochrome_version_code",
  86. "monochrome_32_version_code",
  87. "monochrome_32_64_version_code",
  88. "monochrome_64_32_version_code",
  89. "monochrome_64_version_code",
  90. "trichrome_version_code",
  91. "trichrome_32_version_code",
  92. "trichrome_32_64_version_code",
  93. "trichrome_64_32_version_code",
  94. "trichrome_64_version_code",
  95. "webview_beta_version_code",
  96. "webview_dev_version_code",
  97. "webview_stable_version_code",
  98. "webview_32_beta_version_code",
  99. "webview_32_dev_version_code",
  100. "webview_32_stable_version_code",
  101. "webview_64_beta_version_code",
  102. "webview_64_dev_version_code",
  103. "webview_64_stable_version_code",
  104. ])
  105. chrome_version_name = chrome_version_full
  106. lines_to_write = [
  107. "VersionName: $chrome_version_name",
  108. "Chrome: $chrome_version_code",
  109. "ChromeModern: $chrome_modern_version_code",
  110. "Monochrome: $monochrome_version_code",
  111. "TrichromeChrome: $trichrome_version_code",
  112. "AndroidWebviewStable: $webview_stable_version_code",
  113. "AndroidWebviewBeta: $webview_beta_version_code",
  114. "AndroidWebviewDev: $webview_dev_version_code",
  115. ]
  116. if (target_cpu == "arm64" || target_cpu == "x64") {
  117. lines_to_write += [
  118. "Monochrome32: $monochrome_32_version_code",
  119. "Monochrome3264: $monochrome_32_64_version_code",
  120. "Monochrome6432: $monochrome_64_32_version_code",
  121. "Monochrome64: $monochrome_64_version_code",
  122. "TrichromeChrome32: $trichrome_32_version_code",
  123. "TrichromeChrome3264: $trichrome_32_64_version_code",
  124. "TrichromeChrome6432: $trichrome_64_32_version_code",
  125. "TrichromeChrome64: $trichrome_64_version_code",
  126. "AndroidWebview32Stable: $webview_32_stable_version_code",
  127. "AndroidWebview32Beta: $webview_32_beta_version_code",
  128. "AndroidWebview32Dev: $webview_32_dev_version_code",
  129. "AndroidWebview64Stable: $webview_64_stable_version_code",
  130. "AndroidWebview64Beta: $webview_64_beta_version_code",
  131. "AndroidWebview64Dev: $webview_64_dev_version_code",
  132. ]
  133. }
  134. write_file("$root_out_dir/android_chrome_versions.txt", lines_to_write)
  135. }