Skip to content

Commit a61a9a3

Browse files
Audran Doubletsylvestre
Audran Doublet
authored andcommitted
msvc: #1687: handle case where output file is a directory
1 parent 92038f4 commit a61a9a3

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
@@ -788,7 +788,20 @@ pub fn parse_arguments(
788788
);
789789
}
790790
Some(o) => {
791-
if o.extension().is_none() && compilation {
791+
if o.as_os_str()
792+
.to_string_lossy()
793+
.ends_with(std::path::MAIN_SEPARATOR) {
794+
match Path::new(&input).file_name() {
795+
Some(i) => outputs.insert(
796+
"obj",
797+
ArtifactDescriptor {
798+
path: o.join(Path::new(i)).with_extension("obj"),
799+
optional: false,
800+
},
801+
),
802+
None => cannot_cache!("invalid input file"),
803+
};
804+
} else if o.extension().is_none() {
792805
outputs.insert(
793806
"obj",
794807
ArtifactDescriptor {
@@ -1795,6 +1808,38 @@ mod test {
17951808
assert!(msvc_show_includes);
17961809
}
17971810

1811+
#[test]
1812+
fn parse_argument_output_file_trailing_backslash() {
1813+
let args = ovec!["-c", "foo.c", "/Fomyrelease\\folder\\"];
1814+
let ParsedArguments {
1815+
input,
1816+
language,
1817+
outputs,
1818+
preprocessor_args,
1819+
msvc_show_includes,
1820+
common_args,
1821+
..
1822+
} = match parse_arguments(args) {
1823+
CompilerArguments::Ok(args) => args,
1824+
o => panic!("Got unexpected parse result: {:?}", o),
1825+
};
1826+
assert_eq!(Some("foo.c"), input.to_str());
1827+
assert_eq!(Language::C, language);
1828+
assert_map_contains!(
1829+
outputs,
1830+
(
1831+
"obj",
1832+
ArtifactDescriptor {
1833+
path: PathBuf::from("myrelease/folder/foo.obj"),
1834+
optional: false
1835+
}
1836+
)
1837+
);
1838+
assert!(preprocessor_args.is_empty());
1839+
assert!(common_args.is_empty());
1840+
assert!(!msvc_show_includes);
1841+
}
1842+
17981843
#[test]
17991844
fn test_parse_arguments_pdb() {
18001845
let args = ovec!["-c", "foo.c", "-Zi", "-Fdfoo.pdb", "-Fofoo.obj"];

0 commit comments

Comments
 (0)