Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 77 additions & 16 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,23 +699,27 @@ where
);
profile_generate = true;
}
if need_explicit_dep_target {
dependency_args.push(dep_flag);
dependency_args.push(dep_target.unwrap_or_else(|| output.clone().into_os_string()));
}
if let DepArgumentRequirePath::Missing = need_explicit_dep_argument_path {
dependency_args.push(OsString::from("-MF"));
dependency_args.push(Path::new(&output).with_extension("d").into_os_string());
}

if let Some(path) = dep_path {
outputs.insert(
"d",
ArtifactDescriptor {
path: path.clone(),
optional: false,
},
);
// If the language doesn't need preprocessing, it doesn't generate a dependency file. See issue #2664
if language.needs_c_preprocessing() {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot do it without explicit external if, because clippy is not happy with if let ... && ... and with if ... && let ...

See rust-lang/rust#53667 for more details

if need_explicit_dep_target {
dependency_args.push(dep_flag);
dependency_args.push(dep_target.unwrap_or_else(|| output.clone().into_os_string()));
}
if let DepArgumentRequirePath::Missing = need_explicit_dep_argument_path {
dependency_args.push(OsString::from("-MF"));
dependency_args.push(Path::new(&output).with_extension("d").into_os_string());
}

if let Some(path) = dep_path {
outputs.insert(
"d",
ArtifactDescriptor {
path: path.clone(),
optional: false,
},
);
}
}

if let Some(path) = serialize_diagnostics {
Expand Down Expand Up @@ -1122,6 +1126,7 @@ impl Iterator for ExpandIncludeFile<'_> {
#[cfg(test)]
mod test {
use fs::File;
use itertools::assert_equal;
use std::io::Write;

use super::*;
Expand Down Expand Up @@ -1404,6 +1409,62 @@ mod test {
assert!(profile_generate);
}

#[test]
fn test_parse_arguments_depfile_for_raw_assembly_gcc() {
let args = stringvec!["-c", "foo.s", "-o", "foo.o", "-MD", "-MF", "foo.d"];
let ParsedArguments {
input,
language,
outputs,
preprocessor_args,
..
} = match parse_arguments_(args, false) {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert_eq!(Some("foo.s"), input.to_str());
assert_eq!(Language::Assembler, language);
assert_equal(
outputs,
vec![(
"obj",
ArtifactDescriptor {
path: "foo.o".into(),
optional: false,
},
)],
);
assert!(preprocessor_args.is_empty());
}

#[test]
fn test_parse_arguments_depfile_for_preprocessed_c_clang() {
let args = stringvec!["-c", "foo.i", "-o", "foo.o", "-MD", "-MF", "foo.d"];
let ParsedArguments {
input,
language,
outputs,
preprocessor_args,
..
} = match parse_arguments_clang(args, false) {
CompilerArguments::Ok(args) => args,
o => panic!("Got unexpected parse result: {:?}", o),
};
assert_eq!(Some("foo.i"), input.to_str());
assert_eq!(Language::CPreprocessed, language);
assert_equal(
outputs,
vec![(
"obj",
ArtifactDescriptor {
path: "foo.o".into(),
optional: false,
},
)],
);
assert!(preprocessor_args.is_empty());
}

#[test]
fn test_parse_arguments_test_coverage_outputs_gcno() {
let args = stringvec!["-ftest-coverage", "-c", "foo.cpp", "-o", "foo.o"];
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/scripts/test-clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,24 @@ echo "Test 3: Test ASM"
ASM="$SCCACHE clang++"
$ASM -c /sccache/tests/integration/test_intel_asm.s

DEPFILE="/tmp/test.o.d"
rm -f $DEPFILE
$ASM -c /sccache/tests/integration/test_intel_asm.s -MD -MF $DEPFILE
test ! -f $DEPFILE || { echo "ERROR: Dependency file found"; exit 1; }

echo "Test 4: Test ASM with preprocessor"
$ASM -c /sccache/tests/integration/test_intel_asm_to_preproc.S

$ASM -c /sccache/tests/integration/test_intel_asm_to_preproc.S -MD -MF $DEPFILE
test -f $DEPFILE || { echo "ERROR: Dependency file not found"; exit 1; }
rm -f $DEPFILE

echo "Test 5: Test preprocessed C++ file with dependency arguments (cache miss)"
$CXX -c /sccache/tests/integration/test_preprocessed.ii -o /tmp/test.o -MD -MF $DEPFILE
test -f /tmp/test.o || { echo "ERROR: No compiler output found"; exit 1; }
test ! -f $DEPFILE || { echo "ERROR: Dependency file found"; exit 1; }

echo "Test 6: Test preprocessed C++ file with dependency arguments (cache hit expected)"
$CXX -c /sccache/tests/integration/test_preprocessed.ii -o /tmp/test.o -MD -MF $DEPFILE
test -f /tmp/test.o || { echo "ERROR: No compiler output found"; exit 1; }
test ! -f $DEPFILE || { echo "ERROR: Dependency file found"; exit 1; }
19 changes: 19 additions & 0 deletions tests/integration/scripts/test-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,24 @@ echo "Test 3: Test ASM"
ASM="$SCCACHE gcc"
$ASM -c /sccache/tests/integration/test_intel_asm.s

DEPFILE="/tmp/test.o.d"
rm -f $DEPFILE
$ASM -c /sccache/tests/integration/test_intel_asm.s -MD -MF $DEPFILE
test ! -f $DEPFILE || { echo "ERROR: Dependency file found"; exit 1; }

echo "Test 4: Test ASM with preprocessor"
$ASM -c /sccache/tests/integration/test_intel_asm_to_preproc.S

$ASM -c /sccache/tests/integration/test_intel_asm_to_preproc.S -MD -MF $DEPFILE
test -f $DEPFILE || { echo "ERROR: Dependency file not found"; exit 1; }
rm -f $DEPFILE

echo "Test 5: Test preprocessed C++ file with dependency arguments (cache miss)"
$CXX -c /sccache/tests/integration/test_preprocessed.ii -o /tmp/test.o -MD -MF $DEPFILE
test -f /tmp/test.o || { echo "ERROR: No compiler output found"; exit 1; }
test ! -f $DEPFILE || { echo "ERROR: Dependency file found"; exit 1; }

echo "Test 6: Test preprocessed C++ file with dependency arguments (cache hit expected)"
$CXX -c /sccache/tests/integration/test_preprocessed.ii -o /tmp/test.o -MD -MF $DEPFILE
test -f /tmp/test.o || { echo "ERROR: No compiler output found"; exit 1; }
test ! -f $DEPFILE || { echo "ERROR: Dependency file found"; exit 1; }
3 changes: 3 additions & 0 deletions tests/integration/test_preprocessed.ii
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}
Loading