Skip to content

Commit

Permalink
Add compiler_is_msvc() and MSVC specific option table.
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-gascuel committed Mar 10, 2017
1 parent 4227fa0 commit 375fe24
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
55 changes: 32 additions & 23 deletions ccache.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,36 @@ static sigset_t fatal_signal_set;
static pid_t compiler_pid = 0;
#endif

// Note that these compiler checks are unreliable, so nothing should
// hard-depend on them.

static bool
compiler_is_clang(struct args *args)
{
char *name = basename(args->argv[0]);
bool result = strstr(name, "clang") != NULL;
free(name);
return result;
}

static bool
compiler_is_gcc(struct args *args)
{
char *name = basename(args->argv[0]);
bool result = strstr(name, "gcc") || strstr(name, "g++");
free(name);
return result;
}

static bool
compiler_is_msvc(struct args *args)
{
char *name = basename(args->argv[0]);
bool result = strstr(name, "cl") != NULL;
free(name);
return result;
}

// This is a string that identifies the current "version" of the hash sum
// computed by ccache. If, for any reason, we want to force the hash sum to be
// different for the same input in a new ccache version, we can just change
Expand Down Expand Up @@ -1563,27 +1593,6 @@ hash_compiler(struct mdfour *hash, struct stat *st, const char *path,
}
}

// Note that these compiler checks are unreliable, so nothing should
// hard-depend on them.

static bool
compiler_is_clang(struct args *args)
{
char *name = basename(args->argv[0]);
bool result = strstr(name, "clang") != NULL;
free(name);
return result;
}

static bool
compiler_is_gcc(struct args *args)
{
char *name = basename(args->argv[0]);
bool result = strstr(name, "gcc") || strstr(name, "g++");
free(name);
return result;
}

// Update a hash sum with information common for the direct and preprocessor
// modes.
static void
Expand Down Expand Up @@ -2734,7 +2743,7 @@ cc_process_args(struct args *args, struct args **preprocessor_args,

// Same as above but options with concatenated argument beginning with a
// slash.
if (argv[i][0] == '-') {
if (argv[i][0] == '-' || compiler_is_msvc(args) && argv[i][0] == '/') {
char *slash_pos = strchr(argv[i], '/');
if (slash_pos) {
char *option = x_strndup(argv[i], slash_pos - argv[i]);
Expand Down Expand Up @@ -2778,7 +2787,7 @@ cc_process_args(struct args *args, struct args **preprocessor_args,
}

// Other options.
if (argv[i][0] == '-') {
if (argv[i][0] == '-' || compiler_is_msvc(args) && argv[i][0] == '/') {
if (compopt_affects_cpp(argv[i])
|| compopt_prefix_affects_cpp(argv[i])) {
args_add(cpp_args, argv[i]);
Expand Down
28 changes: 27 additions & 1 deletion compopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ static const struct compopt compopts[] = {
{"-u", TAKES_ARG | TAKES_CONCAT_ARG},
};

// MSVC Specific options
static const struct compopt compopts_msvc[] = {
{"/AI", TAKES_ARG| TAKES_CONCAT_ARG | TAKES_PATH},
{"/D", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG},
{"/E", TOO_HARD},
{"/EP", TOO_HARD},
{"/FI", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"/FU", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"/I", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG | TAKES_PATH},
{"/L", TAKES_ARG},
{"/P", TOO_HARD},
{"/U", AFFECTS_CPP | TAKES_ARG | TAKES_CONCAT_ARG},
{"/u", AFFECTS_CPP},
};

static int
compare_compopts(const void *key1, const void *key2)
Expand All @@ -106,19 +120,31 @@ find(const char *option)
{
struct compopt key;
key.name = option;
if( option[0] == '-' )
return bsearch(
&key, compopts, sizeof(compopts) / sizeof(compopts[0]),
sizeof(compopts[0]), compare_compopts);
sizeof(compopts[0]),
compare_compopts);
else
return bsearch(
&key, compopts_msvc, sizeof(compopts_msvc) / sizeof(compopts_msvc[0]),
sizeof(compopts[0]),
compare_compopts);
}

static const struct compopt *
find_prefix(const char *option)
{
struct compopt key;
key.name = option;
if( option[0] == '-' )
return bsearch(
&key, compopts, sizeof(compopts) / sizeof(compopts[0]),
sizeof(compopts[0]), compare_prefix_compopts);
else
return bsearch(
&key, compopts_msvc, sizeof(compopts_msvc) / sizeof(compopts_msvc[0]),
sizeof(compopts[0]), compare_prefix_compopts);
}

// Runs fn on the first two characters of option.
Expand Down

0 comments on commit 375fe24

Please sign in to comment.