Skip to content

Commit d511d09

Browse files
Audran Doubletsylvestre
Audran Doublet
authored andcommitted
msvc: mozilla#1687: handle case where output file is a directory
1 parent 6ebc516 commit d511d09

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/compiler/msvc.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,20 @@ pub fn parse_arguments(
732732
);
733733
}
734734
Some(o) => {
735-
if o.extension().is_none() && compilation {
735+
if o.as_os_str()
736+
.to_string_lossy()
737+
.ends_with(std::path::MAIN_SEPARATOR) {
738+
match Path::new(&input).file_name() {
739+
Some(i) => outputs.insert(
740+
"obj",
741+
ArtifactDescriptor {
742+
path: o.join(Path::new(i)).with_extension("obj"),
743+
optional: false,
744+
},
745+
),
746+
None => cannot_cache!("invalid input file"),
747+
};
748+
} else if o.extension().is_none() {
736749
outputs.insert(
737750
"obj",
738751
ArtifactDescriptor {
@@ -1833,6 +1846,38 @@ mod test {
18331846
assert!(msvc_show_includes);
18341847
}
18351848

1849+
#[test]
1850+
fn parse_argument_output_file_trailing_backslash() {
1851+
let args = ovec!["-c", "foo.c", "/Fomyrelease\\folder\\"];
1852+
let ParsedArguments {
1853+
input,
1854+
language,
1855+
outputs,
1856+
preprocessor_args,
1857+
msvc_show_includes,
1858+
common_args,
1859+
..
1860+
} = match parse_arguments(args) {
1861+
CompilerArguments::Ok(args) => args,
1862+
o => panic!("Got unexpected parse result: {:?}", o),
1863+
};
1864+
assert_eq!(Some("foo.c"), input.to_str());
1865+
assert_eq!(Language::C, language);
1866+
assert_map_contains!(
1867+
outputs,
1868+
(
1869+
"obj",
1870+
ArtifactDescriptor {
1871+
path: PathBuf::from("myrelease/folder/foo.obj"),
1872+
optional: false
1873+
}
1874+
)
1875+
);
1876+
assert!(preprocessor_args.is_empty());
1877+
assert!(common_args.is_empty());
1878+
assert!(!msvc_show_includes);
1879+
}
1880+
18361881
#[test]
18371882
fn test_parse_arguments_pdb() {
18381883
let args = ovec!["-c", "foo.c", "-Zi", "-Fdfoo.pdb", "-Fofoo.obj"];

0 commit comments

Comments
 (0)