Author: Chuanqi Xu
Date: 2023-08-11T14:57:32+08:00
New Revision: f6b94e0026e27dd0603e5ba39886920c02ad79f0
URL: 
https://github.com/llvm/llvm-project/commit/f6b94e0026e27dd0603e5ba39886920c02ad79f0
DIFF: 
https://github.com/llvm/llvm-project/commit/f6b94e0026e27dd0603e5ba39886920c02ad79f0.diff

LOG: [NFC] Document the solution to pr61006 and a test for it

Address https://github.com/llvm/llvm-project/issues/61006.

The actual reason for the issue is about the usage of clang-scan-deps
instead of its functionalities since clang-scan-deps has
already considered the problem before for clang modules.

So this patch tries to document the corresponding solution
and add a test case for it to address the issue.

Added: 
    clang/test/ClangScanDeps/pr61006.cppm

Modified: 
    clang/docs/StandardCPlusPlusModules.rst

Removed: 
    


################################################################################
diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 06609063c61c96..3aeb55d8f4dad4 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -1072,12 +1072,6 @@ the user can choose to get the dependency information 
per file. For example:
 
   $ clang-scan-deps -format=p1689 -- <path-to-compiler-executable>/clang++ 
-std=c++20 impl_part.cppm -c -o impl_part.o
 
-.. warning::
-
-   The ``<path-to-compiler-executable>/clang++`` should point to the real
-   binary and not to a symlink. If it points to a symlink the include paths
-   will not be correctly resolved.
-
 And we'll get:
 
 .. code-block:: text
@@ -1134,6 +1128,32 @@ We will get:
 When clang-scan-deps detects ``-MF`` option, clang-scan-deps will try to write 
the
 dependency information for headers to the file specified by ``-MF``.
 
+Possible Issues: Failed to find system headers
+----------------------------------------------
+
+In case the users encounter errors like ``fatal error: 'stddef.h' file not 
found``,
+probably the specified ``<path-to-compiler-executable>/clang++`` refers to a 
symlink
+instead a real binary. There are 4 potential solutions to the problem:
+
+* (1) End users can resolve the issue by pointing the specified compiler 
executable to
+  the real binary instead of the symlink.
+* (2) End users can invoke ``<path-to-compiler-executable>/clang++ 
-print-resource-dir``
+  to get the corresponding resource directory for your compiler and add that 
directory
+  to the include search paths manually in the build scripts.
+* (3) Build systems that use a compilation database as the input for 
clang-scan-deps
+  scanner, the build system can add the flag ``--resource-dir-recipe 
invoke-compiler`` to
+  the clang-scan-deps scanner to calculate the resources directory dynamically.
+  The calculation happens only once for a unique 
``<path-to-compiler-executable>/clang++``.
+* (4) For build systems that invokes the clang-scan-deps scanner per file, 
repeatedly
+  calculating the resource directory may be inefficient. In such cases, the 
build
+  system can cache the resource directory by itself and pass ``-resource-dir 
<resource-dir>``
+  explicitly in the command line options:
+
+.. code-block:: console
+
+  $ clang-scan-deps -format=p1689 -- <path-to-compiler-executable>/clang++ 
-std=c++20 -resource-dir <resource-dir> mod.cppm -c -o mod.o
+
+
 Possible Questions
 ==================
 

diff  --git a/clang/test/ClangScanDeps/pr61006.cppm 
b/clang/test/ClangScanDeps/pr61006.cppm
new file mode 100644
index 00000000000000..13cfe385be2e2d
--- /dev/null
+++ b/clang/test/ClangScanDeps/pr61006.cppm
@@ -0,0 +1,44 @@
+// The slash direction in linux and windows are 
diff erent.
+// Also the command to create symbolic link is 
diff erent.
+// UNSUPPORTED: system-windows
+//
+// RUN: rm -fr %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+//
+// RUN: EXPECTED_RESOURCE_DIR=`%clang -print-resource-dir`
+// RUN: ln -s %clang++ %t/clang++
+// RUN: sed "s|EXPECTED_RESOURCE_DIR|$EXPECTED_RESOURCE_DIR|g; s|DIR|%/t|g" 
%t/P1689.json.in > %t/P1689.json
+// RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | 
FileCheck %t/a.cpp -DPREFIX=%/t
+// RUN: clang-scan-deps -format=p1689 \
+// RUN:   -- %t/clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/a.cpp -o 
%t/a.o \
+// RUN:      -resource-dir $EXPECTED_RESOURCE_DIR | FileCheck %t/a.cpp 
-DPREFIX=%/t
+
+//--- P1689.json.in
+[
+{
+  "directory": "DIR",
+  "command": "DIR/clang++ -std=c++20 -c -fprebuilt-module-path=DIR DIR/a.cpp 
-o DIR/a.o -resource-dir EXPECTED_RESOURCE_DIR",
+  "file": "DIR/a.cpp",
+  "output": "DIR/a.o"
+}
+]
+
+//--- a.cpp
+#include <stddef.h>
+import b;
+
+// CHECK: {
+// CHECK-NEXT:   "revision": 0,
+// CHECK-NEXT:   "rules": [
+// CHECK-NEXT:     {
+// CHECK-NEXT:       "primary-output": "[[PREFIX]]/a.o",
+// CHECK-NEXT:       "requires": [
+// CHECK-NEXT:         {
+// CHECK-NEXT:           "logical-name": "b"
+// CHECK-NEXT:         }
+// CHECK-NEXT:       ]
+// CHECK-NEXT:     }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "version": 1
+// CHECK-NEXT: }


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to