roll.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env 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 shlex
  7. import shutil
  8. import subprocess
  9. import tempfile
  10. _REPO_URL = "https://gitlab.freedesktop.org/xdg/xdgmime.git"
  11. _FILES_TO_COPY = (
  12. "README",
  13. "src/xdgmimealias.c",
  14. "src/xdgmime.c",
  15. "src/xdgmimecache.h",
  16. "src/xdgmimeglob.h",
  17. "src/xdgmimeicon.c",
  18. "src/xdgmimeint.c",
  19. "src/xdgmimemagic.c",
  20. "src/xdgmimeparent.c",
  21. "src/xdgmimealias.h",
  22. "src/xdgmimecache.c",
  23. "src/xdgmimeglob.c",
  24. "src/xdgmime.h",
  25. "src/xdgmimeicon.h",
  26. "src/xdgmimeint.h",
  27. "src/xdgmimemagic.h",
  28. "src/xdgmimeparent.h",
  29. )
  30. _PATCHES = ("000-have-mmap.patch",)
  31. def main():
  32. out_dir = os.path.dirname(os.path.realpath(__file__))
  33. with open(os.path.join(out_dir, "README.chromium")) as readme_file:
  34. _VERSION_PREFIX = "Version: "
  35. for line in readme_file:
  36. if not line.startswith(_VERSION_PREFIX):
  37. continue
  38. old_commit = line[len(_VERSION_PREFIX):].strip()
  39. with tempfile.TemporaryDirectory() as staging_dir:
  40. os.chdir(staging_dir)
  41. print(f"Cloning from {_REPO_URL}...")
  42. subprocess.check_call([
  43. "git",
  44. "clone",
  45. _REPO_URL,
  46. ".",
  47. ])
  48. for f in _FILES_TO_COPY:
  49. shutil.copy(os.path.join(staging_dir, f), out_dir)
  50. new_commit = subprocess.check_output([
  51. "git",
  52. "rev-parse",
  53. "HEAD",
  54. ]).decode("ascii").strip()
  55. # This is cargo-culted from depot_tool's roll_dep.py
  56. log_command = (
  57. "git",
  58. "log",
  59. f"{old_commit}..{new_commit}",
  60. "--date=short",
  61. "--no-merges",
  62. "--format=%ad %ae %s",
  63. )
  64. diffs = subprocess.check_output(log_command).decode("utf-8")
  65. os.chdir(os.path.join(out_dir, "..", "..", ".."))
  66. for p in _PATCHES:
  67. print(f"Applying patch {p}...")
  68. with open(os.path.join(out_dir, "patches", p)) as patch_file:
  69. subprocess.check_call(["patch", "-p1"], stdin=patch_file)
  70. print(f"Done! Updated from {old_commit} to {new_commit}")
  71. print("Changes:")
  72. print(
  73. f"$ git log {old_commit[:9]}..{new_commit[:9]} "
  74. f"--date=short --no-merges --format='%ad %ae %s'"
  75. )
  76. print(diffs)
  77. if __name__ == "__main__":
  78. main()