This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] add support for dependency scanning with cc1 command line
ClosedPublic

Authored by cpsughrue on Jul 25 2023, 5:44 AM.

Details

Summary

Allow users to run a dependency scan with a cc1 command line in addition to a driver command line. DependencyScanningAction was already being run with a cc1 command line, but DependencyScanningWorker::computeDependencies assumed that it was always provided a driver command line. Now DependencyScanningWorker::computeDependencies can handle cc1 command lines too.

Diff Detail

Event Timeline

cpsughrue created this revision.Jul 25 2023, 5:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 5:44 AM
cpsughrue requested review of this revision.Jul 25 2023, 5:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 25 2023, 5:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cpsughrue added a project: Restricted Project.Jul 25 2023, 8:20 AM
cpsughrue updated this revision to Diff 544127.Jul 25 2023, 3:44 PM
cpsughrue edited the summary of this revision. (Show Details)

Fixed formatting issues

This looks pretty good!

I'm not sure unit testing is the best choice here, since we're not checking for low-level properties or hard-to-observe behavior. In general LIT tests are easier to write/maintain/understand and don't require recompiling, so I'd suggest to transform the existing unit test into something similar to tests in clang/test/ClangScanDeps/.

clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
414
507
cpsughrue updated this revision to Diff 545910.Jul 31 2023, 8:53 PM
cpsughrue retitled this revision from [clang][deps] provide support for cc1 command line scanning to [clang][deps] add support for dependency scanning with cc1 command line.
cpsughrue edited the summary of this revision. (Show Details)

Added llvm-lit test for commit and removed previously created unit test

cpsughrue marked 2 inline comments as done.Aug 1 2023, 6:58 AM
cpsughrue added inline comments.Aug 1 2023, 7:02 AM
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
482

Is there a good way to validate cc1 command lines?

Bigcheese added inline comments.Aug 1 2023, 10:22 AM
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
482

Not really, you just have to parse it. Was there a particular reason you wanted to validate here?

jansvoboda11 added inline comments.Aug 1 2023, 10:25 AM
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
482

I think that happens in ToolInvocation::run() that's called by createAndRunToolInvocation. Are you seeing cases where we don't emit a diagnostic for an invalid -cc1 command line?

clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json
1 ↗(On Diff #545910)

I assume this was cargo-culted from clang/test/ClangScanDeps/Inputs/modules_cdb.json. I don't think we need multiple entries here and lots of the flags are unnecessary for just testing out -cc1 command lines work. I suggest having just one minimal -cc1 command line here.

clang/test/ClangScanDeps/modules-cc1.cpp
11

Recently, we've been using split-file to set up the file system for our tests. It's much easier to see what's going on in a glance. Can you transform the test into that format? You can take inspiration from clang/test/ClangScanDeps/modules-transitive.c for example.

19

Yeah, this is already covered by the other test, I suggest dropping this comment and the -j flag in the clang-scan-deps invocation below.

cpsughrue added inline comments.Aug 1 2023, 11:49 AM
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
482

@jansvoboda11 You're right, ToolInvocation::run() fails if there are any issues when the function creates the compiler invocation - I missed that. I've not seen any cases where diagnostics aren't outputted.

482

@Bigcheese No, I just wanted to make sure some sort of validation was happening and missed the work being done in ToolInvocation::run().

clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json
1 ↗(On Diff #545910)

That is an accurate assumption. Are you good with the following command line clang -cc1 DIR/modules_cdb_input.cpp -IInputs -fimplicit-module-maps -o modules_cdb_input.o?

cpsughrue updated this revision to Diff 546182.Aug 1 2023, 12:24 PM

Update llvm-lit test to use split-file

cpsughrue marked an inline comment as done.Aug 1 2023, 12:25 PM
jansvoboda11 accepted this revision.Aug 2 2023, 2:11 PM

LGTM after Windows CI gets fixed.

This revision is now accepted and ready to land.Aug 2 2023, 2:11 PM
cpsughrue updated this revision to Diff 546861.Aug 3 2023, 7:38 AM

Fixing failed test on Windows CI