Bug 1779992 - mach subcommand to upgrade Glean across all files. r=chutten DONTBUILD

This only modifies the files and prints the steps to be done manually.

Differential Revision: https://phabricator.services.mozilla.com/D152627
This commit is contained in:
Jan-Erik Rediger 2022-07-26 13:51:31 +00:00
Родитель 55d622a34d
Коммит 21fd159579
2 изменённых файлов: 108 добавлений и 0 удалений

Просмотреть файл

@ -339,6 +339,9 @@ def initialize(topsrcdir):
"update-glean-tags": MachCommandReference(
"toolkit/components/glean/build_scripts/mach_commands.py"
),
"update-glean": MachCommandReference(
"toolkit/components/glean/build_scripts/mach_commands.py"
),
"browsertime": MachCommandReference("tools/browsertime/mach_commands.py"),
"compare-locales": MachCommandReference(
"tools/compare-locales/mach_commands.py"

Просмотреть файл

@ -99,3 +99,108 @@ def update_glean_tags(command_context):
"{}\n{}\n\n".format(LICENSE_HEADER, GENERATED_HEADER)
+ yaml.dump(tags, width=78, explicit_start=True)
)
def replace_in_file(path, pattern, replace):
"""
Replace `pattern` with `replace` in the file `path`.
The file is modified on disk.
Returns `True` if exactly one replacement happened.
`False` otherwise.
"""
import re
with open(path, "r+") as file:
data = file.read()
data, subs_made = re.subn(pattern, replace, data, flags=re.MULTILINE)
file.seek(0)
file.write(data)
file.truncate()
if subs_made != 1:
return False
return True
def replace_in_file_or_die(path, pattern, replace):
"""
Replace `pattern` with `replace` in the file `path`.
The file is modified on disk.
If not exactly one occurrence of `pattern` was replaced it will exit with exit code 1.
"""
import sys
success = replace_in_file(path, pattern, replace)
if not success:
print(f"ERROR: Failed to replace one occurrence in {path}")
print(f" Pattern: {pattern}")
print(f" Replace: {replace}")
print("File was modified. Check the diff.")
sys.exit(1)
@Command(
"update-glean",
category="misc",
description="Update Glean to the given version",
)
@CommandArgument("version", help="Glean version to upgrade to")
def update_glean(command_context, version):
from pathlib import Path
import textwrap
topsrcdir = Path(command_context.topsrcdir)
replace_in_file_or_die(
topsrcdir / "build.gradle",
r'gleanVersion = "[0-9.]+"',
f'gleanVersion = "{version}"',
)
replace_in_file_or_die(
topsrcdir / "toolkit" / "components" / "glean" / "Cargo.toml",
r'^glean = "[0-9.]+"',
f'glean = "{version}"',
)
replace_in_file_or_die(
topsrcdir / "toolkit" / "components" / "glean" / "api" / "Cargo.toml",
r'^glean = "[0-9.]+"',
f'glean = "{version}"',
)
replace_in_file_or_die(
topsrcdir / "gfx" / "wr" / "webrender" / "Cargo.toml",
r'^glean = "[0-9.]+"',
f'glean = "{version}"',
)
replace_in_file_or_die(
topsrcdir / "python" / "sites" / "mach.txt",
r"glean-sdk==[0-9.]+",
f"glean-sdk=={version}",
)
instructions = f"""
Version in files modified. Please run the following commands:
cargo update -p glean
mach vendor rust
Vendoring will require re-certification of crates.
To do that run
mach cargo vet certify glean {version}
mach cargo vet certify glean-core {version}
This will require you to rerun `mach vendor rust` afterwards.
Then run:
cd gfx/wr
cargo update -p glean
"""
print(textwrap.dedent(instructions))