Skip to content

Commit 5e579f4

Browse files
committed
refactor resource script creation into a separate function
1 parent a299d5f commit 5e579f4

File tree

1 file changed

+28
-17
lines changed
  • compiler/rustc_windows_rc/src

1 file changed

+28
-17
lines changed

compiler/rustc_windows_rc/src/lib.rs

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,34 @@ pub fn compile_windows_resource_file(
3838
let resource_compiler =
3939
find_resource_compiler(&env::var("CARGO_CFG_TARGET_ARCH").unwrap()).expect("found rc.exe");
4040

41+
let rc_path = resources_dir.join(file_stem.with_extension("rc"));
42+
43+
write_resource_script_file(&rc_path, file_description, filetype);
44+
45+
let res_path = resources_dir.join(file_stem.with_extension("res"));
46+
47+
let status = process::Command::new(resource_compiler)
48+
.arg("/fo")
49+
.arg(&res_path)
50+
.arg(&rc_path)
51+
.status()
52+
.expect("can execute resource compiler");
53+
assert!(status.success(), "rc.exe failed with status {}", status);
54+
assert!(
55+
res_path.try_exists().unwrap_or(false),
56+
"resource file {} was not created",
57+
res_path.display()
58+
);
59+
res_path
60+
}
61+
62+
/// Writes a Windows resource script file for the rust compiler with the product and file version information
63+
/// into `rc_path`
64+
fn write_resource_script_file(
65+
rc_path: &path::Path,
66+
file_description: &str,
67+
filetype: VersionInfoFileType,
68+
) {
4169
let mut resource_script = RESOURCE_TEMPLATE.to_string();
4270

4371
// Set the string product and file version to the same thing as `rustc --version`
@@ -62,25 +90,8 @@ pub fn compile_windows_resource_file(
6290
.replace("@RUSTC_PRODUCTVERSION_QUAD@", &version.to_quad_string())
6391
.replace("@RUSTC_PRODUCTVERSION_STR@", &descriptive_version);
6492

65-
let rc_path = resources_dir.join(file_stem.with_extension("rc"));
6693
fs::write(&rc_path, resource_script)
6794
.unwrap_or_else(|_| panic!("failed to write resource file {}", rc_path.display()));
68-
69-
let res_path = resources_dir.join(file_stem.with_extension("res"));
70-
71-
let status = process::Command::new(resource_compiler)
72-
.arg("/fo")
73-
.arg(&res_path)
74-
.arg(&rc_path)
75-
.status()
76-
.expect("can execute resource compiler");
77-
assert!(status.success(), "rc.exe failed with status {}", status);
78-
assert!(
79-
res_path.try_exists().unwrap_or(false),
80-
"resource file {} was not created",
81-
res_path.display()
82-
);
83-
res_path
8495
}
8596

8697
fn product_name(channel: String) -> String {

0 commit comments

Comments
 (0)