Skip to content

Commit 8254df9

Browse files
committed
Add support for building only on a single system
1 parent 0f34038 commit 8254df9

File tree

4 files changed

+127
-18
lines changed

4 files changed

+127
-18
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ the Nixpkgs checkout (see also "[How does ofborg call
8181
Builds will run on all allowed machines. For more information, see the "[Trusted
8282
Users](#trusted-users)" section.
8383

84+
### build_system
85+
86+
```
87+
@ofborg build_system SYSTEM list of attrs
88+
```
89+
90+
Same as [build](#build), but restricts building to only one platform specification
91+
instead of attempting to build on all allowed and supported systems.
92+
This can be helpful to reduce needless builds and noise when debugging a platform-specific issue.
93+
94+
Only the currently supported Nixpkgs systems can be passed to `build_system`:
95+
`x86_64-linux`, `aarch64-linux`, `x86_64-darwin`, and `aarch64-darwin`.
96+
8497
## Multiple Commands
8598

8699
You can use multiple commands in a variety ways. Here are some valid

ofborg/src/commentparser.rs

Lines changed: 83 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::systems::System;
12
use nom::types::CompleteStr;
23
use tracing::warn;
34

@@ -24,32 +25,79 @@ named!(
2425
|s: CompleteStr| !s.0.eq_ignore_ascii_case("@grahamcofborg")
2526
)
2627
);
28+
2729
named!(
28-
parse_line_impl(CompleteStr) -> Option<Vec<Instruction>>,
30+
system(CompleteStr) -> System,
2931
alt!(
30-
do_parse!(
31-
res: ws!(many1!(ws!(preceded!(
32-
alt!(tag_no_case!("@grahamcofborg") | tag_no_case!("@ofborg")),
33-
alt!(
34-
ws!(do_parse!(
35-
tag!("build") >>
32+
value!(System::X8664Linux, tag!("x86_64-linux")) |
33+
value!(System::Aarch64Linux, tag!("aarch64-linux")) |
34+
value!(System::X8664Darwin, tag!("x86_64-darwin")) |
35+
value!(System::Aarch64Darwin, tag!("aarch64-darwin"))
36+
)
37+
);
38+
39+
named!(
40+
invocation_prefix(CompleteStr) -> CompleteStr,
41+
alt!(tag_no_case!("@ofborg") | tag_no_case!("@grahamcofborg"))
42+
);
43+
44+
enum Command {
45+
Eval,
46+
Build,
47+
BuildSystem,
48+
Test,
49+
}
50+
51+
named!(
52+
command_str(CompleteStr) -> Option<Command>,
53+
alt!(
54+
value!(Some(Command::Eval), tag!("eval")) |
55+
value!(Some(Command::BuildSystem), tag!("build_system")) |
56+
value!(Some(Command::Build), tag!("build")) |
57+
value!(Some(Command::Test), tag!("test")) |
58+
59+
// TODO: Currently keeping previous behaviour of ignoring unknown commands. Maybe
60+
// it would be better to return an error so that the caller would know one of the
61+
// commands couldn't be handled?
62+
value!(None, many_till!(take!(1), invocation_prefix))
63+
)
64+
);
65+
66+
named!(
67+
command(CompleteStr) -> Option<Instruction>,
68+
preceded!(
69+
ws!(invocation_prefix),
70+
switch!( ws!(command_str),
71+
Some(Command::Build) =>
72+
ws!(do_parse!(
3673
pkgs: ws!(many1!(map!(normal_token, |s| s.0.to_owned()))) >>
3774
(Some(Instruction::Build(Subset::Nixpkgs, pkgs)))
3875
)) |
76+
Some(Command::BuildSystem) =>
77+
ws!(do_parse!(
78+
system: ws!(system) >>
79+
pkgs: ws!(many1!(map!(normal_token, |s| s.0.to_owned()))) >>
80+
(Some(Instruction::BuildOnSystem(system, Subset::Nixpkgs, pkgs)))
81+
)) |
82+
Some(Command::Test) =>
3983
ws!(do_parse!(
40-
tag!("test") >>
4184
tests: ws!(many1!(map!(normal_token, |s| format!("nixosTests.{}", s.0)))) >>
4285
(Some(Instruction::Build(Subset::Nixpkgs, tests)))
4386
)) |
44-
value!(Some(Instruction::Eval), tag!("eval")) |
45-
// TODO: Currently keeping previous behaviour of ignoring unknown commands. Maybe
46-
// it would be better to return an error so that the caller would know one of the
47-
// commands couldn't be handled?
48-
value!(None, many_till!(take!(1), tag_no_case!("@grahamcofborg")))
49-
)
50-
)))) >> eof!()
51-
>> (Some(res.into_iter().flatten().collect()))
52-
) | value!(None)
87+
Some(Command::Eval) => ws!(do_parse!( (Some(Instruction::Eval)) )) |
88+
None => do_parse!( (None) )
89+
)
90+
)
91+
);
92+
93+
named!(
94+
parse_line_impl(CompleteStr) -> Option<Vec<Instruction>>,
95+
opt!(
96+
do_parse!(
97+
res: ws!(many1!(ws!(command)))
98+
>> eof!()
99+
>> (res.into_iter().flatten().collect())
100+
)
53101
)
54102
);
55103

@@ -68,6 +116,7 @@ pub fn parse_line(text: &str) -> Option<Vec<Instruction>> {
68116
pub enum Instruction {
69117
Build(Subset, Vec<String>),
70118
Eval,
119+
BuildOnSystem(System, Subset, Vec<String>),
71120
}
72121

73122
#[allow(clippy::upper_case_acronyms)]
@@ -108,6 +157,23 @@ mod tests {
108157
assert_eq!(None, parse("@grahamcofborg build"));
109158
}
110159

160+
#[test]
161+
fn build_system_comment() {
162+
assert_eq!(
163+
Some(vec![Instruction::BuildOnSystem(
164+
System::X8664Linux,
165+
Subset::Nixpkgs,
166+
vec![String::from("foo")]
167+
),]),
168+
parse("@ofborg build_system x86_64-linux foo")
169+
);
170+
}
171+
172+
#[test]
173+
fn unknown_system_comment() {
174+
assert_eq!(None, parse("@ofborg build_system x86_64-foolinux foo"));
175+
}
176+
111177
#[test]
112178
fn eval_comment() {
113179
assert_eq!(Some(vec![Instruction::Eval]), parse("@grahamcofborg eval"));

ofborg/src/systems.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[derive(Clone, Debug)]
1+
#[derive(Clone, Debug, PartialEq, Eq)]
22
pub enum System {
33
X8664Linux,
44
Aarch64Linux,

ofborg/src/tasks/githubcommentfilter.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,36 @@ impl worker::SimpleWorker for GitHubCommentWorker {
141141
},
142142
));
143143
}
144+
commentparser::Instruction::BuildOnSystem(system, subset, attrs) => {
145+
if !build_destinations.contains(&system) {
146+
continue;
147+
};
148+
if subset == commentparser::Subset::NixOS && !system.can_run_nixos_tests() {
149+
continue;
150+
};
151+
152+
let msg = buildjob::BuildJob::new(
153+
repo_msg.clone(),
154+
pr_msg.clone(),
155+
subset,
156+
attrs,
157+
None,
158+
None,
159+
format!("{}", Uuid::new_v4()),
160+
);
161+
162+
let (exchange, routingkey) = system.as_build_destination();
163+
response.push(worker::publish_serde_action(exchange, routingkey, &msg));
164+
165+
response.push(worker::publish_serde_action(
166+
Some("build-results".to_string()),
167+
None,
168+
&buildjob::QueuedBuildJobs {
169+
job: msg,
170+
architectures: vec![system.to_string()],
171+
},
172+
));
173+
}
144174
commentparser::Instruction::Eval => {
145175
let msg = evaluationjob::EvaluationJob {
146176
repo: repo_msg.clone(),

0 commit comments

Comments
 (0)