diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 0292a6b74..ddb11c662 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -732,7 +732,20 @@ pub fn parse_arguments( ); } Some(o) => { - if o.extension().is_none() && compilation { + if o.as_os_str() + .to_string_lossy() + .ends_with(std::path::MAIN_SEPARATOR) { + match Path::new(&input).file_name() { + Some(i) => outputs.insert( + "obj", + ArtifactDescriptor { + path: o.join(Path::new(i)).with_extension("obj"), + optional: false, + }, + ), + None => cannot_cache!("invalid input file"), + }; + } else if o.extension().is_none() { outputs.insert( "obj", ArtifactDescriptor { @@ -1833,6 +1846,38 @@ mod test { assert!(msvc_show_includes); } + #[test] + fn parse_argument_output_file_trailing_backslash() { + let args = ovec!["-c", "foo.c", "/Fomyrelease\\folder\\"]; + let ParsedArguments { + input, + language, + outputs, + preprocessor_args, + msvc_show_includes, + common_args, + .. + } = match parse_arguments(args) { + CompilerArguments::Ok(args) => args, + o => panic!("Got unexpected parse result: {:?}", o), + }; + assert_eq!(Some("foo.c"), input.to_str()); + assert_eq!(Language::C, language); + assert_map_contains!( + outputs, + ( + "obj", + ArtifactDescriptor { + path: PathBuf::from("myrelease/folder/foo.obj"), + optional: false + } + ) + ); + assert!(preprocessor_args.is_empty()); + assert!(common_args.is_empty()); + assert!(!msvc_show_includes); + } + #[test] fn test_parse_arguments_pdb() { let args = ovec!["-c", "foo.c", "-Zi", "-Fdfoo.pdb", "-Fofoo.obj"];