File: include-tree-with-pch.c

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (112 lines) | stat: -rw-r--r-- 3,355 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json

// RUN: %clang -x c-header %t/prefix.h -target x86_64-apple-macos12 -o %t/prefix.pch -fdepscan=inline -fdepscan-include-tree -Xclang -fcas-path -Xclang %t/cas
// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree -cas-path %t/cas > %t/result.txt
// RUN: FileCheck %s -input-file %t/result.txt -DPREFIX=%/t

// CHECK:      {{.*}} - [[PREFIX]]/t.c
// CHECK-NEXT: (PCH)
// CHECK-NEXT: [[PREFIX]]/t.c
// CHECK-NEXT: 1:1 <built-in>
// CHECK-NEXT: [[PREFIX]]/t.h
// CHECK-NEXT: Files:
// CHECK-NEXT: [[PREFIX]]/t.c
// CHECK-NEXT: [[PREFIX]]/t.h
// CHECK-NEXT: [[PREFIX]]/prefix.h
// CHECK-NEXT: [[PREFIX]]/n1.h
// CHECK-NEXT: [[PREFIX]]/n2.h
// CHECK-NEXT: [[PREFIX]]/n3.h
// CHECK-NOT: [[PREFIX]]

// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-include-tree-full -cas-path %t/cas > %t/deps.json

// RUN: cat %t/result.txt > %t/full.txt
// RUN: echo "FULL DEPS START" >> %t/full.txt
// RUN: cat %t/deps.json | sed 's:\\\\\?:/:g' >> %t/full.txt

// RUN: FileCheck %s -DPREFIX=%/t -check-prefix=FULL -input-file %t/full.txt

// Capture the tree id from experimental-include-tree ; ensure that it matches
// the result from experimental-full.
// FULL: [[TREE_ID:llvmcas://[[:xdigit:]]+]] - [[PREFIX]]/t.c
// FULL: FULL DEPS START

// FULL-NEXT: {
// FULL-NEXT:   "modules": []
// FULL-NEXT:   "translation-units": [
// FULL-NEXT:     {
// FULL-NEXT:       "commands": [
// FULL-NEXT:         {
// FULL:                "clang-module-deps": []
// FULL:                "command-line": [
// FULL-NEXT:             "-cc1"
// FULL:                  "-fcas-path"
// FULL-NEXT:             "[[PREFIX]]/cas"
// FULL:                  "-disable-free"
// FULL:                  "-fcas-include-tree"
// FULL-NEXT:             "[[TREE_ID]]"
// FULL:                  "-fcache-compile-job"
// FULL:                  "-fsyntax-only"
// FULL:                  "-x"
// FULL-NEXT:             "c"
// FULL-NOT:              "t.c"
// FULL:                  "-main-file-name"
// FULL-NEXT:             "t.c"
// FULL-NOT:              "t.c"
// FULL:                ]
// FULL:                "executable": "clang"
// FULL:                "file-deps": [
// FULL-NEXT:             "[[PREFIX]]/t.c"
// FULL-NEXT:             "[[PREFIX]]/t.h"
// FULL-NEXT:             "[[PREFIX]]/prefix.pch"
// FULL-NEXT:           ]
// FULL:                "input-file": "[[PREFIX]]/t.c"
// FULL:              }
// FULL:            ]
// FULL:          }
// FULL:        ]
// FULL:      }

// Build the include-tree command
// RUN: %deps-to-rsp %t/deps.json --tu-index 0 > %t/tu.rsp
// RUN: %clang @%t/tu.rsp

//--- prefix.h
#include "n1.h"
#import "n2.h"
#include "n3.h"

//--- n1.h
#ifndef _N1_H_
#define _N1_H_

int n1 = 0;

#endif

//--- n2.h
int n2 = 0;

//--- n3.h
#pragma once
int n3 = 0;

//--- cdb.json.template
[{
  "directory" : "DIR",
  "command" : "clang -fsyntax-only DIR/t.c -target x86_64-apple-macos12 -isysroot DIR -Xclang -include-pch -Xclang DIR/prefix.pch",
  "file" : "DIR/t.c"
}]

//--- t.c
#include "t.h"
// Should not include due to macro guard.
#include "n1.h"
// Should not include due to #import from 'prefix.h'.
#include "n2.h"
// Should not include due to '#pragma once'
#include "n3.h"

//--- t.h