Skip to content

Commit a645d9d

Browse files
committed
fix: build
1 parent 8f447a5 commit a645d9d

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

build.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ use std::{
66
};
77

88
fn main() -> Result<(), Box<dyn Error>> {
9-
// Skip building from docs.rs.
9+
// Skip building online from docs.rs
1010
if std::env::var_os("DOCS_RS").is_some() {
11-
return Ok(());
12-
}
13-
// Retrieve a live version of the reports.proto file
14-
let proto_url = "https://usage-reporting.api.apollographql.com/proto/reports.proto";
15-
let response = reqwest::blocking::get(proto_url)?;
16-
let mut content = response.text()?;
11+
} else {
12+
// Retrieve a live version of the reports.proto file
13+
let proto_url = "https://usage-reporting.api.apollographql.com/proto/reports.proto";
14+
let response = reqwest::blocking::get(proto_url)?;
15+
let mut content = response.text()?;
1716

18-
// Process the retrieved content to:
19-
// - Insert a package Report; line after the import lines (currently only one) and before the first message definition
20-
// - Remove the Apollo TS extensions [(js_use_toArray)=true] and [(js_preEncoded)=true] from the file
21-
// Note: Only two in use at the moment. This may fail in future if new extensions are
22-
// added to the source, so be aware future self. It will manifest as a protobuf compile
23-
// error.
24-
let message = "\nmessage";
25-
let msg_index = content.find(message).ok_or("cannot find message string")?;
26-
content.insert_str(msg_index, "\npackage Report;\n");
17+
// Process the retrieved content to:
18+
// - Insert a package Report; line after the import lines (currently only one) and before the first message definition
19+
// - Remove the Apollo TS extensions [(js_use_toArray)=true] and [(js_preEncoded)=true] from the file
20+
// Note: Only two in use at the moment. This may fail in future if new extensions are
21+
// added to the source, so be aware future self. It will manifest as a protobuf compile
22+
// error.
23+
let message = "\nmessage";
24+
let msg_index = content.find(message).ok_or("cannot find message string")?;
25+
content.insert_str(msg_index, "\npackage Report;\n");
2726

28-
content = content.replace("[(js_use_toArray) = true]", "");
29-
content = content.replace("[(js_preEncoded) = true]", "");
27+
content = content.replace("[(js_use_toArray) = true]", "");
28+
content = content.replace("[(js_preEncoded) = true]", "");
3029

31-
// Try to avoid writing out the same content since it will trigger unnecessary re-builds, which wastes time
32-
let write_content = match File::open("proto/reports.proto") {
33-
Ok(mut existing) => {
34-
let mut existing_content = String::new();
35-
existing.read_to_string(&mut existing_content)?;
36-
content != existing_content
37-
}
38-
Err(_) => true,
39-
};
30+
// Try to avoid writing out the same content since it will trigger unnecessary re-builds, which wastes time
31+
let write_content = match File::open("proto/reports.proto") {
32+
Ok(mut existing) => {
33+
let mut existing_content = String::new();
34+
existing.read_to_string(&mut existing_content)?;
35+
content != existing_content
36+
}
37+
Err(_) => true,
38+
};
4039

41-
// Write the content out if they differ or an error occured trying to open proto file
42-
if write_content {
43-
let mut dest = File::create("proto/reports.proto")?;
44-
copy(&mut content.as_bytes(), &mut dest)?;
40+
// Write the content out if they differ or an error occured trying to open proto file
41+
if write_content {
42+
let mut dest = File::create("proto/reports.proto")?;
43+
copy(&mut content.as_bytes(), &mut dest)?;
44+
}
4545
}
4646

4747
// Process the proto files

0 commit comments

Comments
 (0)