Skip to content

Commit

Permalink
[SYCLomatic] Emit error message and fixing steps for users when "cmak…
Browse files Browse the repository at this point in the history
…e -E make_directory" called in "intercept-build make" (oneapi-src#1391)


Signed-off-by: chenwei.sun <[email protected]>
  • Loading branch information
tomflinda authored Nov 13, 2023
1 parent 0906cde commit f273c56
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/test/dpct/intercept_cmake_waring/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.0)

project(foo)

add_executable(foo foo.cpp)
12 changes: 12 additions & 0 deletions clang/test/dpct/intercept_cmake_waring/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
program = main


main: foo.cpp
mkdir -p build
cd build && cmake .. && make

clean:
rm -rf build foo.o

run: $(program)
./$(program)
15 changes: 15 additions & 0 deletions clang/test/dpct/intercept_cmake_waring/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// UNSUPPORTED: system-windows
// intercept-build only supports Linux
//
// ------ prepare test directory
// RUN: cd %T
// RUN: cp %s foo.cpp
// RUN: cp %S/Makefile ./Makefile
// RUN: cp %S/CMakeLists.txt ./CMakeLists.txt
// RUN: not intercept-build make > intercept_log.txt 2>&1 || true
// RUN: not grep "cmake is called to generate project build" ./intercept_log.txt
#include <iostream>

int main() {
return 0;
}
39 changes: 39 additions & 0 deletions clang/tools/scan-build-py/lib/libear/ear.c
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,42 @@ const char *find_intercept_compiler(const char *str, int compiler_idx) {
return ret;
}

void emit_cmake_warning(char const *argv[], int argc) {
const char *bin = argv[0];
int len = strlen(bin);
if ((len == 5 && bin[0] == 'e' && bin[1] == 'k' && bin[3] == 'a' &&
bin[4] == 'm' && bin[4] == 'c') ||
(len > 5 && bin[len - 6] == '/' && bin[len - 5] == 'c' &&
bin[len - 4] == 'm') &&
bin[len - 3] == 'a' && bin[len - 2] == 'k' && bin[len - 1] == 'e') {

int find_make_directory = 0;
for (size_t i = 0; i < argc; i++) {
// if cmake runs with option "make_directory", like "/usr/bin/cmake -E
// make_directory /path/to/build/_deps/foo-src", it means that cmake
// configure is run in this directory.
if (strcmp(argv[i], "make_directory") == 0) {
find_make_directory = 1;
break;
}
}

static int print_once = 0;
if (find_make_directory && !print_once) {
perror(
"[intercept-build: Error]: cmake is called to generate project build "
"scripts when run \"intercept-build make\", the build scripts "
"generated may not be complete. To generate a complete compilation "
"database, suggest following steps:\n"
"1. Build the source project by running \"make -B\" in build "
"folder.\n"
"2. Run \"intercept-build make -B\" to generate compilation database "
"in build folder.\n");
}
print_once++;
}
}

// Replace the command compiler with path to command "intercept-stub" with path.
// src could be:"/path/to/clang++",
// "/path/to/clang++ -Xcompiler ...",
Expand Down Expand Up @@ -1720,6 +1756,9 @@ static void bear_report_call(char const *fun, char const *const argv[]) {
fprintf(fd, "%s%c", cwd, RS);
size_t const argc = bear_strings_length(argv);
#ifdef SYCLomatic_CUSTOMIZATION

emit_cmake_warning(argv, argc);

// compiler list should be intercepted.
const char *const compiler_array[] = {"nvcc", "clang++"};
// Current compiler index intercepted.
Expand Down

0 comments on commit f273c56

Please sign in to comment.