Repository navigation
Automate use of V8's version for crates shared by workerd and V8 #8058
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
npaun
wants to merge
1
commit into
main
Choose a base branch
from
npaun/v8-rust-icu-auto/1-sync-chromium-crates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+308
−2
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| load("@rules_python//python:defs.bzl", "py_test") | ||
|
|
||
| py_test( | ||
| name = "v8_update_test", | ||
| size = "small", | ||
| srcs = [ | ||
| "jsonc.py", | ||
| "v8_update.py", | ||
| "v8_update_test.py", | ||
| ], | ||
| # v8_update.py imports jsonc.py, and the test imports v8_update.py, as top-level modules. | ||
| imports = ["."], | ||
| main = "v8_update_test.py", | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| """Tests for the Chromium Rust crate alignment in v8_update.py. | ||
|
|
||
| Cargo, Bazel and the Chromium lockfile are mocked, so the tests check which | ||
| versions the helper asks Cargo for, and when it fails. | ||
| """ | ||
|
|
||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
| from unittest import mock | ||
|
|
||
| import v8_update | ||
|
|
||
| V8_DEPS = ( | ||
| "'third_party/rust': Var('chromium_url') + '/chromium/src/third_party/rust.git' + '@' + " | ||
| f"'{'0' * 40}'," | ||
| ) | ||
|
|
||
| CARGO_TOML = """\ | ||
| [package] | ||
| name = "direct-cargo-bazel-deps" | ||
|
|
||
| [dependencies] | ||
| icu_calendar = { version = "=2.3.0", default-features = false } | ||
| temporal_rs = { version = "=0.2.6", default-features = false, features = ["float64_representable_durations"] } | ||
| tinystr = "0.8" | ||
| writeable = "=0.6.2" | ||
| """ | ||
|
|
||
| # Chromium locks two versions of icu_calendar and of zerovec. | ||
| CHROMIUM = { | ||
| "icu_calendar": ["1.5.2", "2.2.1"], | ||
| "temporal_rs": ["0.2.6"], | ||
| "tinystr": ["0.8.2"], | ||
| "writeable": ["0.6.2"], | ||
| "zerovec": ["0.10.4", "0.11.5"], | ||
| } | ||
|
|
||
|
|
||
| class UpdateChromiumCratesTest(unittest.TestCase): | ||
| def setUp(self): | ||
| directory = tempfile.TemporaryDirectory() | ||
| self.addCleanup(directory.cleanup) | ||
| cargo_toml = Path(directory.name) / "Cargo.toml" | ||
| cargo_toml.write_text(CARGO_TOML) | ||
| for target, value in ( | ||
| ("CARGO_TOML", cargo_toml), | ||
| ("_chromium_crate_versions", mock.Mock(return_value=CHROMIUM)), | ||
| ): | ||
| patcher = mock.patch.object(v8_update, target, value) | ||
| patcher.start() | ||
| self.addCleanup(patcher.stop) | ||
| self.cargo = self._patch("_cargo") | ||
| self.run_command = self._patch("run") | ||
| self.tree = self._patch("_chromium_crate_tree") | ||
|
|
||
| def _patch(self, name): | ||
| patcher = mock.patch.object(v8_update, name) | ||
| self.addCleanup(patcher.stop) | ||
| return patcher.start() | ||
|
|
||
| def test_aligned_tree_changes_nothing(self): | ||
| self.tree.return_value = { | ||
| ("icu_calendar", "2.2.1"), | ||
| ("temporal_rs", "0.2.6"), | ||
| ("zerovec", "0.11.5"), | ||
| } | ||
| v8_update._update_chromium_crates(V8_DEPS) | ||
| self.cargo.assert_not_called() | ||
| self._assert_repinned_bazel_lockfile() | ||
|
|
||
| def test_moves_exact_pins_with_cargo_add(self): | ||
| # The pin moves to the Chromium version in the same semver range, not to 1.5.2. | ||
| aligned = {("icu_calendar", "2.2.1"), ("temporal_rs", "0.2.6")} | ||
| self.tree.side_effect = [ | ||
| {("icu_calendar", "2.3.0"), ("temporal_rs", "0.2.6")}, | ||
| aligned, | ||
| aligned, | ||
| ] | ||
| v8_update._update_chromium_crates(V8_DEPS) | ||
| self.cargo.assert_called_once_with("add", "icu_calendar@=2.2.1") | ||
| self._assert_repinned_bazel_lockfile() | ||
|
|
||
| def test_moves_unpinned_crates_with_cargo_update(self): | ||
| self.tree.side_effect = [ | ||
| {("tinystr", "0.8.3"), ("zerovec", "0.11.6")}, | ||
| {("tinystr", "0.8.3"), ("zerovec", "0.11.6")}, | ||
| {("tinystr", "0.8.2"), ("zerovec", "0.11.5")}, | ||
| ] | ||
| v8_update._update_chromium_crates(V8_DEPS) | ||
| self.assertCountEqual( | ||
| self.cargo.call_args_list, | ||
| [ | ||
| mock.call("update", "tinystr@0.8.3", "--precise", "0.8.2", check=False), | ||
| mock.call( | ||
| "update", "zerovec@0.11.6", "--precise", "0.11.5", check=False | ||
| ), | ||
| ], | ||
| ) | ||
| self._assert_repinned_bazel_lockfile() | ||
|
|
||
| def test_fails_when_cargo_refuses_a_version(self): | ||
| # Cargo refuses to downgrade zerovec, and Chromium doesn't lock unicode-ident. | ||
| tree = {("zerovec", "0.11.6"), ("unicode-ident", "1.0.0")} | ||
| self.tree.side_effect = [tree, tree, tree] | ||
| with self.assertRaisesRegex( | ||
| ValueError, | ||
| r"unicode-ident 1\.0\.0 \(Chromium: none\), " | ||
| r"zerovec 0\.11\.6 \(Chromium: 0\.10\.4, 0\.11\.5\)", | ||
| ): | ||
| v8_update._update_chromium_crates(V8_DEPS) | ||
| self.cargo.assert_called_once_with( | ||
| "update", "zerovec@0.11.6", "--precise", "0.11.5", check=False | ||
| ) | ||
| self.run_command.assert_not_called() | ||
|
|
||
| def _assert_repinned_bazel_lockfile(self): | ||
| self.run_command.assert_called_once_with( | ||
| [ | ||
| "bazel", | ||
| "fetch", | ||
| "--repo_env=CARGO_BAZEL_REPIN=1", | ||
| "--repo=@crates_vendor", | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| class ChromiumVersionTest(unittest.TestCase): | ||
|
npaun marked this conversation as resolved.
|
||
| def test_single_version_is_chosen_across_semver_ranges(self): | ||
| # An exact pin can follow Chromium to a new semver range. | ||
| self.assertEqual( | ||
| v8_update._chromium_version( | ||
| {"temporal_rs": ["0.3.0"]}, "temporal_rs", "0.2.6" | ||
| ), | ||
| "0.3.0", | ||
| ) | ||
|
|
||
| def test_duplicate_versions_are_matched_by_semver_range(self): | ||
| chromium = { | ||
| "a": ["0.0.3", "0.0.4"], | ||
| "b": ["0.1.0", "0.2.0"], | ||
| "c": ["1.0.0", "2.1.0"], | ||
| } | ||
| self.assertEqual(v8_update._chromium_version(chromium, "a", "0.0.4"), "0.0.4") | ||
| self.assertEqual(v8_update._chromium_version(chromium, "b", "0.2.5"), "0.2.0") | ||
| self.assertEqual(v8_update._chromium_version(chromium, "c", "2.0.0"), "2.1.0") | ||
| self.assertIsNone(v8_update._chromium_version(chromium, "c", "3.0.0")) | ||
| self.assertIsNone(v8_update._chromium_version(chromium, "d", "1.0.0")) | ||
|
|
||
|
npaun marked this conversation as resolved.
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.