llvm-project/clang/test/ClangScanDeps/deprecated-driver-api.c
Ben Langmuir 83902c4036 Reapply "[clang][deps] Split translation units into individual -cc1 or other commands"
Attempt to fix the test failures observed in CI:
* Add Option dependency, which caused BUILD_SHARED_LIBS builds to fail
* Adapt tests that accidentally depended on the host platform: platforms
  that don't use an integrated assembler (e.g. AIX) get a different set
  of commands from the driver. Most dependency scanner tests can use
  -fsyntax-only or -E instead of -c to avoid this, and in the rare case
  we want to check -c specifically, set an explicit target so the
  behaviour is independent of the host.

Original commit message follows.

---

Instead of trying to "fix" the original driver invocation by appending
arguments to it, split it into multiple commands, and for each -cc1
command use a CompilerInvocation to give precise control over the
invocation.

This change should make it easier to (in the future) canonicalize the
command-line (e.g. to improve hits in something like ccache), apply
optimizations, or start supporting multi-arch builds, which would
require different modules for each arch.

In the long run it may make sense to treat the TU commands as a
dependency graph, each with their own dependencies on modules or earlier
TU commands, but for now they are simply a list that is executed in
order, and the dependencies are simply duplicated. Since we currently
only support single-arch builds, there is no parallelism available in
the execution.

Differential Revision: https://reviews.llvm.org/D132405
2022-08-31 09:45:11 -07:00

39 lines
856 B
C

// Test the deprecated version of the API that returns a driver command instead
// of multiple -cc1 commands.
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.in > %t/cdb.json
// RUN: clang-scan-deps -compilation-database=%t/cdb.json -format experimental-full \
// RUN: -deprecated-driver-command | sed 's:\\\\\?:/:g' | FileCheck %s
// CHECK: "command-line": [
// CHECK: "-c"
// CHECK: "{{.*}}tu.c"
// CHECK: "-save-temps"
// CHECK: "-fno-implicit-modules"
// CHECK: "-fno-implicit-module-maps"
// CHECK: ]
// CHECK: "file-deps": [
// CHECK: "{{.*}}tu.c",
// CHECK: "{{.*}}header.h"
// CHECK: ]
//--- cdb.json.in
[{
"directory": "DIR",
"command": "clang -c DIR/tu.c -save-temps",
"file": "DIR/tu.c"
}]
//--- header.h
void bar(void);
//--- tu.c
#include "header.h"
void foo(void) {
bar();
}