consts.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # python3
  2. # Copyright 2021 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. import os
  6. import re
  7. CRATES_IO_VIEW = "https://crates.io/crates/{crate}"
  8. CRATES_IO_DOWNLOAD = "https://static.crates.io/crates/{crate}/{crate}-{version}.crate"
  9. # Allowed licenses, in the format they are specified in Cargo.toml files from
  10. # crates.io, and the format to write to README.chromium.
  11. ALLOWED_LICENSES = [
  12. # ("Cargo.toml string", "License for README.chromium")
  13. ("Apache-2.0", "Apache 2.0"),
  14. ("MIT OR Apache-2.0", "Apache 2.0"),
  15. ("MIT/Apache-2.0", "Apache 2.0"),
  16. ("Apache-2.0 / MIT", "Apache 2.0"),
  17. ("Apache-2.0 OR MIT", "Apache 2.0"),
  18. ("Apache-2.0/MIT", "Apache 2.0"),
  19. ("MIT", "MIT"),
  20. ("Unlicense OR MIT", "MIT"),
  21. ("Unlicense/MIT", "MIT"),
  22. ("Apache-2.0 OR BSL-1.0", "Apache 2.0"),
  23. ("BSD-3-Clause", "BSD 3-Clause"),
  24. ("ISC", "ISC"),
  25. ("MIT OR Zlib OR Apache-2.0", "Apache 2.0"),
  26. ("0BSD OR MIT OR Apache-2.0", "Apache 2.0"),
  27. ]
  28. # The subdirectory where crates are found, relative to the current working
  29. # directory where the tool is run (i.e. `os.getcwd()`).
  30. THIRD_PARTY = ["third_party", "rust"]
  31. # Path to a patch file, relative to third_party/rust, that will be applied to
  32. # the entire third_party/rust directory after generating BUILD.gn files. The
  33. # patch should only contain changes to BUILD.gn files.
  34. BUILD_PATCH_FILE = ["crates_py_build_patch"]
  35. # Where to place the extracted crate inside the version epoch directory. If
  36. # empty, it will be extracted directly to the epoch directory.
  37. CRATE_INNER_DIR = ["crate"]
  38. # Template for generating README.chromium files.
  39. README_CHROMIUM = """Name: {crate_name}
  40. URL: {url}
  41. Description: {description}
  42. Version: {version}
  43. Security Critical: {security}
  44. License: {license}
  45. """
  46. # Crates that can not be depended one. Dependencies should be removed from
  47. # Cargo.toml files. Each one comes with a reason.
  48. BLOCKED_CRATES = {
  49. "cc":
  50. "C/C++ code should be build by a GN rule, not from Rust code directly. See "
  51. + os.path.join(*(THIRD_PARTY + ["cc", "README.md"])),
  52. }
  53. # A Regex for parsing the output of `cargo tree`. This matches the dependencies
  54. # and reports their name, version, if they are a proc macro, and their enabled
  55. # features.
  56. _CARGO_DEPS = \
  57. r"(?:├──|└──) (?P<name>.*?) v(?P<version>[0-9]+.[0-9]+.[0-9]+)" \
  58. r"(?P<isprocmacro> \(proc-macro\))?" \
  59. r"(?: \((?P<path>[\/].*?)\))?" \
  60. r"(?: (?P<features>[^( ][^ ]*))?(?: \(\*\))?"
  61. CARGO_DEPS_REGEX = re.compile(_CARGO_DEPS)
  62. FAKE_EMPTY_CARGO_TOML = """[package]
  63. name = "fake"
  64. version = "0.0.0"
  65. """
  66. # Header at the top of BUILD.gn files. The {year} is substituted with the
  67. # appropriate year.
  68. GN_HEADER = \
  69. """# Copyright {year} The Chromium Authors. All rights reserved.
  70. # Use of this source code is governed by a BSD-style license that can be
  71. # found in the LICENSE file.
  72. import("//build/rust/cargo_crate.gni")
  73. """
  74. _GN_HEADER_YEAR = r"^# Copyright( \(c\))? (?P<year>[0-9]+) " \
  75. r"The Chromium Authors\. All rights reserved\."
  76. GN_HEADER_YEAR_REGEX = re.compile(_GN_HEADER_YEAR)
  77. # Comment on the build_native_rust_unit_tests field in BUILD.gn file output.
  78. GN_TESTS_COMMENT = \
  79. """# Unit tests skipped. Generate with --with-tests to include them."""
  80. # Comment on the visibility field in BUILD.gn file output.
  81. GN_VISIBILITY_COMMENT = \
  82. """# Only for usage from third-party crates. Add the crate to
  83. # third_party.toml to use it from first-party code."""