-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCLomatc][Intercept-build] Refine intercept-build to work as normal compilation if the toolchain is available #2386
Open
tomflinda
wants to merge
5
commits into
oneapi-src:SYCLomatic
Choose a base branch
from
tomflinda:refine_intercept_build
base: SYCLomatic
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+80
−25
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
61ea4fb
[SYCLomatc][Intercept-build] Refine intercept-build to work as normal…
tomflinda ab7740a
Further refined
tomflinda a7102ca
Fix CI test case failure
tomflinda 4721319
Address review comments
tomflinda ae8b036
Refine implementation
tomflinda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
/* -*- coding: utf-8 -*- | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
|
@@ -53,6 +54,7 @@ extern char **environ; | |
|
||
#ifdef SYCLomatic_CUSTOMIZATION | ||
#include <ctype.h> | ||
#include <sys/stat.h> | ||
#define PATH_MAX 4096 | ||
#endif // SYCLomatic_CUSTOMIZATION | ||
|
||
|
@@ -492,35 +494,14 @@ int eaccess(const char *pathname, int mode) { | |
pathname[1] == 'v' && pathname[0] == 'n') { | ||
// To handle case like "nvcc foo.cu ..." | ||
return 0; | ||
} else if (len > 4 && pathname[len - 1] == 'c' && pathname[len - 2] == 'c' && | ||
pathname[len - 3] == 'v' && pathname[len - 4] == 'n' && | ||
pathname[len - 5] == '/') { | ||
// To handle case like "/path/to/nvcc foo.cu ..." | ||
return 0; | ||
} | ||
return call_eaccess(pathname, mode); | ||
} | ||
|
||
static int call_stat(const char *pathname, struct stat *statbuf) { | ||
typedef int (*func)(const char *, struct statbuf *); | ||
DLSYM(func, fp, "stat"); | ||
int const result = (*fp)(pathname, statbuf); | ||
return result; | ||
} | ||
|
||
int stat(const char *pathname, struct stat *statbuf) { | ||
int len = strlen(pathname); | ||
if (len == 4 && pathname[3] == 'c' && pathname[2] == 'c' && | ||
pathname[1] == 'v' && pathname[0] == 'n') { | ||
// To handle case like "nvcc foo.cu ..." | ||
return 0; | ||
} else if (len > 4 && pathname[len - 1] == 'c' && pathname[len - 2] == 'c' && | ||
pathname[len - 3] == 'v' && pathname[len - 4] == 'n' && | ||
pathname[len - 5] == '/') { | ||
if (len > 4 && pathname[len - 1] == 'c' && pathname[len - 2] == 'c' && | ||
pathname[len - 3] == 'v' && pathname[len - 4] == 'n' && | ||
pathname[len - 5] == '/') { | ||
// To handle case like "/path/to/nvcc foo.cu ..." | ||
return 0; | ||
} | ||
return call_stat(pathname, statbuf); | ||
return call_eaccess(pathname, mode); | ||
} | ||
|
||
/* | ||
|
@@ -1706,6 +1687,60 @@ char *replace_binary_name(const char *src, const char *pos, int compiler_idx, | |
/* this method is to write log about the process creation. */ | ||
|
||
#ifdef SYCLomatic_CUSTOMIZATION | ||
int file_exists(const char *pathname) { | ||
|
||
int len = strlen(pathname); | ||
int is_nvcc = 0; | ||
if (len == 4 && pathname[3] == 'c' && pathname[2] == 'c' && | ||
pathname[1] == 'v' && pathname[0] == 'n') { | ||
// To handle case like "nvcc" | ||
is_nvcc = 1; | ||
} | ||
|
||
if (len > 4 && pathname[len - 1] == 'c' && pathname[len - 2] == 'c' && | ||
pathname[len - 3] == 'v' && pathname[len - 4] == 'n' && | ||
pathname[len - 5] == '/') { | ||
// To handle case like "/path/to/nvcc" | ||
is_nvcc = 0; | ||
} | ||
|
||
if (is_nvcc) { | ||
int idx = len - 4; | ||
for (; idx > 0 && !isspace(pathname[idx]); idx--) | ||
; | ||
struct stat buffer; | ||
if (stat(pathname + idx, &buffer) == 0){ | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
int is_ld = 0; | ||
if (len == 2 && pathname[1] == 'd' && pathname[0] == 'l') { | ||
// To handle case like "ld" | ||
is_ld = 1; | ||
} | ||
|
||
if (len > 2 && pathname[len - 1] == 'd' && pathname[len - 2] == 'l' && | ||
pathname[len - 3] == '/') { | ||
// To handle case like "/path/to/ld" | ||
is_ld = 0; | ||
} | ||
|
||
if (is_ld) { | ||
int idx = len - 2; | ||
for (; idx > 0 && !isspace(pathname[idx]); idx--) | ||
; | ||
struct stat buffer; | ||
if (stat(pathname + idx, &buffer) == 0){ | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
// This method parses the command execution issued by the build tool make to | ||
// write log for the compile options and fake the expecting outcome for the | ||
// command. It returns whether intercept-stub is used to take over the command | ||
|
@@ -1759,6 +1794,26 @@ static void bear_report_call(char const *fun, char const *const argv[]) { | |
|
||
emit_cmake_warning(argv, argc); | ||
|
||
int is_tool_available = 0; | ||
if (file_exists(argv[0])) { | ||
is_tool_available = 1; | ||
} | ||
|
||
if(is_tool_available) { | ||
for (size_t it = 0; it < argc; ++it) { | ||
fprintf(fd, "%s%c", argv[it], US); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. debug purpose printf? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it is used to collect options for current command. |
||
} | ||
fprintf(fd, "%c", GS); | ||
if (fclose(fd)) { | ||
perror("bear: fclose"); | ||
pthread_mutex_unlock(&mutex); | ||
exit(EXIT_FAILURE); | ||
} | ||
free((void *)cwd); | ||
pthread_mutex_unlock(&mutex); | ||
return 0; | ||
} | ||
|
||
// compiler list should be intercepted. | ||
const char *const compiler_array[] = {"nvcc", "clang++"}; | ||
// Current compiler index intercepted. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should keep this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we keep it, just do a little refinement.