Skip to content
This repository was archived by the owner on Mar 14, 2023. It is now read-only.

Commit 2d25939

Browse files
authored
Merge pull request #313 from jhwgh1968/warn_compiler_targets
Warn on updates to compiler targets
2 parents abe01ef + 65439ab commit 2d25939

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

highfive/newpr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929

3030
warning_summary = ':warning: **Warning** :warning:\n\n%s'
3131
submodule_warning_msg = 'These commits modify **submodules**.'
32+
targets_warning_msg = 'These commits modify **compiler targets**. (See the [Target Tier Policy](https://doc.rust-lang.org/nightly/rustc/target-tier-policy.html).)'
3233
surprise_branch_warning = "Pull requests are usually filed against the %s branch for this repo, but this one is against %s. Please double check that you specified the right target!"
3334

3435
review_with_reviewer = 'r? @%s\n\n(rust-highfive has picked a reviewer for you, use r? to override)'
3536
review_without_reviewer = '@%s: no appropriate reviewer found, use r? to override'
3637

3738
reviewer_re = re.compile("\\b[rR]\?[:\- ]*@([a-zA-Z0-9\-]+)")
3839
submodule_re = re.compile(".*\+Subproject\scommit\s.*", re.DOTALL | re.MULTILINE)
40+
target_re = re.compile("^[+-]{3} [ab]/compiler/rustc_target/src/spec/", re.MULTILINE)
3941

4042
rustaceans_api_url = "http://www.ncameron.org/rustaceans/user?username={username}"
4143

@@ -85,6 +87,9 @@ def _load_json_file(self, name):
8587
def modifies_submodule(self, diff):
8688
return submodule_re.match(diff)
8789

90+
def modifies_targets(self, diff):
91+
return target_re.search(diff)
92+
8893
def api_req(self, method, url, data=None, media_type=None):
8994
data = None if not data else json.dumps(data).encode("utf-8")
9095
headers = {} if not data else {'Content-Type': 'application/json'}
@@ -164,6 +169,9 @@ def post_warnings(self, diff, owner, repo, issue):
164169
if self.modifies_submodule(diff):
165170
warnings.append(submodule_warning_msg)
166171

172+
if self.modifies_targets(diff):
173+
warnings.append(targets_warning_msg)
174+
167175
if warnings:
168176
self.post_comment(warning_summary % '\n'.join(map(lambda x: '* ' + x, warnings)), owner, repo, issue)
169177

highfive/tests/fakes/target.diff

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
2+
index 039e9a8b274..43a8c5e415d 100644
3+
--- a/compiler/rustc_target/src/spec/mod.rs
4+
+++ b/compiler/rustc_target/src/spec/mod.rs
5+
@@ -680,6 +680,7 @@ fn to_json(&self) -> Json {
6+
("aarch64-linux-android", aarch64_linux_android),
7+
8+
("x86_64-linux-kernel", x86_64_linux_kernel),
9+
+ ("x86_64-freebsd-kernel", x86_64_freebsd_kernel),
10+
11+
("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
12+
("armv6-unknown-freebsd", armv6_unknown_freebsd),

highfive/tests/test_newpr.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,20 @@ def test_submodule(self):
284284
normal_diff = load_fake('normal.diff')
285285
assert not handler.modifies_submodule(normal_diff)
286286

287+
targets_diff = load_fake('target.diff')
288+
assert not handler.modifies_submodule(targets_diff)
289+
290+
def test_targets(self):
291+
handler = HighfiveHandlerMock(Payload({})).handler
292+
targets_diff = load_fake('target.diff')
293+
assert handler.modifies_targets(targets_diff)
294+
295+
normal_diff = load_fake('normal.diff')
296+
assert not handler.modifies_targets(normal_diff)
297+
298+
submodule_diff = load_fake('submodule.diff')
299+
assert not handler.modifies_targets(submodule_diff)
300+
287301
def test_expected_branch_default_expected_no_match(self):
288302
payload = Payload(
289303
{'pull_request': {'base': {'label': 'repo-owner:dev'}}}
@@ -631,6 +645,7 @@ def tpw_defaults(cls, patcherize):
631645
cls.mocks = patcherize((
632646
('unexpected_branch', 'highfive.newpr.HighfiveHandler.unexpected_branch'),
633647
('modifies_submodule', 'highfive.newpr.HighfiveHandler.modifies_submodule'),
648+
('modifies_targets', 'highfive.newpr.HighfiveHandler.modifies_targets'),
634649
('post_comment', 'highfive.newpr.HighfiveHandler.post_comment'),
635650
))
636651

@@ -654,23 +669,27 @@ def post_warnings(self):
654669
def test_no_warnings(self):
655670
self.mocks['unexpected_branch'].return_value = False
656671
self.mocks['modifies_submodule'].return_value = False
672+
self.mocks['modifies_targets'].return_value = False
657673

658674
self.post_warnings()
659675

660676
self.mocks['unexpected_branch'].assert_called_once_with()
661677
self.mocks['modifies_submodule'].assert_called_with(self.diff)
678+
self.mocks['modifies_targets'].assert_called_with(self.diff)
662679
self.mocks['post_comment'].assert_not_called()
663680

664681
def test_unexpected_branch(self):
665682
self.mocks['unexpected_branch'].return_value = (
666683
'master', 'something-else'
667684
)
668685
self.mocks['modifies_submodule'].return_value = False
686+
self.mocks['modifies_targets'].return_value = False
669687

670688
self.post_warnings()
671689

672690
self.mocks['unexpected_branch'].assert_called_once_with()
673691
self.mocks['modifies_submodule'].assert_called_with(self.diff)
692+
self.mocks['modifies_targets'].assert_called_with(self.diff)
674693

675694
expected_warning = """:warning: **Warning** :warning:
676695
@@ -682,11 +701,13 @@ def test_unexpected_branch(self):
682701
def test_modifies_submodule(self):
683702
self.mocks['unexpected_branch'].return_value = False
684703
self.mocks['modifies_submodule'].return_value = True
704+
self.mocks['modifies_targets'].return_value = False
685705

686706
self.post_warnings()
687707

688708
self.mocks['unexpected_branch'].assert_called_once_with()
689709
self.mocks['modifies_submodule'].assert_called_with(self.diff)
710+
self.mocks['modifies_targets'].assert_called_with(self.diff)
690711

691712
expected_warning = """:warning: **Warning** :warning:
692713
@@ -700,11 +721,13 @@ def test_unexpected_branch_modifies_submodule(self):
700721
'master', 'something-else'
701722
)
702723
self.mocks['modifies_submodule'].return_value = True
724+
self.mocks['modifies_targets'].return_value = False
703725

704726
self.post_warnings()
705727

706728
self.mocks['unexpected_branch'].assert_called_once_with()
707729
self.mocks['modifies_submodule'].assert_called_with(self.diff)
730+
self.mocks['modifies_targets'].assert_called_with(self.diff)
708731

709732
expected_warning = """:warning: **Warning** :warning:
710733
@@ -714,6 +737,28 @@ def test_unexpected_branch_modifies_submodule(self):
714737
expected_warning, self.owner, self.repo, self.issue
715738
)
716739

740+
def test_unexpected_branch_modifies_submodule_and_targets(self):
741+
self.mocks['unexpected_branch'].return_value = (
742+
'master', 'something-else'
743+
)
744+
self.mocks['modifies_submodule'].return_value = True
745+
self.mocks['modifies_targets'].return_value = True
746+
747+
self.post_warnings()
748+
749+
self.mocks['unexpected_branch'].assert_called_once_with()
750+
self.mocks['modifies_submodule'].assert_called_with(self.diff)
751+
self.mocks['modifies_targets'].assert_called_with(self.diff)
752+
753+
expected_warning = """:warning: **Warning** :warning:
754+
755+
* Pull requests are usually filed against the master branch for this repo, but this one is against something-else. Please double check that you specified the right target!
756+
* These commits modify **submodules**.
757+
* These commits modify **compiler targets**. (See the [Target Tier Policy](https://doc.rust-lang.org/nightly/rustc/target-tier-policy.html).)"""
758+
self.mocks['post_comment'].assert_called_with(
759+
expected_warning, self.owner, self.repo, self.issue
760+
)
761+
717762

718763
class TestNewPrFunction(TestNewPR):
719764
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)