Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 83908 Details for
Bug 128810
Moving handling of ccache, distcc and GCC_SPECS into the gcc wrapper.
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch against CVS compiler-wrapper.c v1.8
compiler-wrapper.diff (text/plain), 9.29 KB, created by
Kevin F. Quinn (RETIRED)
on 2006-04-04 12:45:10 UTC
(
hide
)
Description:
Patch against CVS compiler-wrapper.c v1.8
Filename:
MIME Type:
Creator:
Kevin F. Quinn (RETIRED)
Created:
2006-04-04 12:45:10 UTC
Size:
9.29 KB
patch
obsolete
>Index: compiler-wrapper.c >=================================================================== >RCS file: /var/cvsroot/gentoo/src/toolchain/gcc-config/src/compiler-wrapper/compiler-wrapper.c,v >retrieving revision 1.8 >diff -u -b -B -r1.8 compiler-wrapper.c >--- compiler-wrapper.c 7 Oct 2005 01:24:19 -0000 1.8 >+++ compiler-wrapper.c 4 Apr 2006 19:23:02 -0000 >@@ -94,6 +94,13 @@ > #define MAXPATHLEN 1023 > #endif > >+#ifndef FALSE >+#define FALSE 0 >+#endif >+#ifndef TRUE >+#define TRUE 1 >+#endif >+ > typedef struct { > /* The CHOST being compiled for. This is determined by $ABI (deprecated), > * the prefix of the executable, the environment ($CHOST), or the default >@@ -136,19 +143,17 @@ > "-m32", "-m64", "-mabi", NULL > }; > >- retargv = argv; >- > /* make sure user hasn't specified any ABI flags already ... > * if they have, lets just get out of here */ > for (argc = 0; argv[argc]; ++argc) > for (i = 0; abiFlags[i]; ++i) > if (!strncmp(argv[argc], abiFlags[i], strlen(abiFlags[i]))) >- return retargv; >+ return argv; > > /* Tokenize the flag list and put it into newflags array */ > flagsTokenized = strdup(newFlagsStr); > if (flagsTokenized == NULL) >- return retargv; >+ return argv; > i = 0; > newFlags[i] = strtok_r(flagsTokenized, " \t\n", &state); > while (newFlags[i] != NULL && i < MAX_NEWFLAGS-1) >@@ -156,6 +161,10 @@ > > /* allocate memory for our spiffy new argv */ > retargv = (char**)calloc(argc + i + 1, sizeof(char*)); >+ if (retargv == NULL) { >+ free(flagsTokenized); >+ return argv; >+ } > /* start building retargv */ > retargv[0] = argv[0]; > /* insert the ABI flags first so cmdline always overrides ABI flags */ >@@ -164,9 +173,153 @@ > if (argc > 1) > memcpy(retargv+1+i, argv+1, (argc-1) * sizeof(char*)); > >+ free(flagsTokenized); >+ > return retargv; > } > >+/** Prepend SPECS to the argv list */ >+static char **buildNewArgvSpecs(char **argv, const char *newSpecsStr) { >+#define MAX_NEWSPECS 32 >+ char *newSpecs[MAX_NEWSPECS]; >+ char **retargv; >+ unsigned int argc; >+ size_t nspecs; >+ char *state, *flagsTokenized; >+ char *spec; >+ >+ for (argc = 0; argv[argc]; ++argc); >+ >+ /* Tokenize the flag list and put it into newflags array */ >+ flagsTokenized = strdup(newSpecsStr); >+ if (flagsTokenized == NULL) >+ return argv; >+ nspecs = 0; >+ for (spec = strtok_r(flagsTokenized, ":", &state); >+ spec != NULL & nspecs < MAX_NEWSPECS; >+ spec = strtok_r(NULL, ":", &state)) { >+ newSpecs[nspecs] = (char *)malloc((strlen(spec)+8) * sizeof(char)); >+ if (newSpecs[nspecs] == NULL) { >+ free(flagsTokenized); >+ return argv; >+ } >+ snprintf(newSpecs[nspecs], strlen(spec)+8, "-specs=%s", spec); >+ nspecs++; >+ } >+ >+ /* allocate memory for our spiffy new argv */ >+ retargv = (char**)calloc(argc + nspecs + 1, sizeof(char*)); >+ if (retargv == NULL) { >+ free(flagsTokenized); >+ return argv; >+ } >+ /* start building retargv */ >+ retargv[0] = argv[0]; >+ /* insert the ABI flags first so cmdline always overrides ABI flags */ >+ memcpy(retargv+1, newSpecs, nspecs * sizeof(char*)); >+ /* copy over the old argv */ >+ if (argc > 1) >+ memcpy(retargv+1+nspecs, argv+1, (argc-1) * sizeof(char*)); >+ >+ free(flagsTokenized); >+ >+ return retargv; >+} >+ >+/** Add path to the environment variable envVar */ >+static int addPathToEnv(char *envVar, char *path) { >+ char *envVal; >+ char *newEnvVal; >+ >+ envVal = getenv(envVar); >+ if (envVal == NULL) { >+ newEnvVal=strdup(path); >+ if (newEnvVal == NULL) >+ return FALSE; >+ } else { >+ newEnvVal = (char *)malloc((strlen(envVal)+1+strlen(path)+1)*sizeof(char)); >+ if (newEnvVal == NULL) >+ return FALSE; >+ snprintf(newEnvVal, strlen(envVal)+1+strlen(path)+1, "%s:%s", envVal,path); >+ } >+ setenv(envVar,newEnvVal,TRUE); >+ return TRUE; >+} >+ >+/** Put bin as argv[0], shuffling argv up one place */ >+static char **prependArgv(char **argv, char *bin) { >+ int argc; >+ char **newArgv; >+ for (argc=0; argv[argc]; argc++); >+ newArgv = (char**)calloc(argc + 1, sizeof(char*)); >+ if (newArgv == NULL) >+ return argv; >+ newArgv[0]=bin; >+ memcpy(newArgv+1,argv,argc * sizeof(char *)); >+ return newArgv; >+} >+ >+/** Return TRUE iff word is in COMPILER_FEATURES and -word is not (last wins) */ >+static int inFeatures(char *word) { >+ char *features, *feature; >+ char *state, *featuresTokenised; >+ int on; >+ >+ features = getenv("COMPILER_FEATURES"); >+ if (features==NULL) >+ return FALSE; >+ featuresTokenised = strdup(features); >+ if (featuresTokenised == NULL) >+ return FALSE; >+ on = FALSE; >+ for (feature = strtok_r(featuresTokenised, " \t\n", &state); >+ feature != NULL; >+ feature = strtok_r(NULL, " \t\n", &state)) { >+ if (strcmp(feature,word)==0) { >+ on = TRUE; >+ } else if (word[0]=='-' && strcmp(feature,word+1)==0) { >+ on = FALSE; >+ } >+ } >+ return on; >+} >+ >+/** Return TRUE iff distcc is wanted */ >+static int distccRequired(void) { >+ return inFeatures("distcc"); >+} >+ >+/** Return TRUE iff distcc is wanted */ >+static int ccacheRequired(void) { >+ return inFeatures("ccache"); >+} >+ >+/** Set environment variable envVar to environment variable envDir >+ * suffixed with , provided envVar is empty or not defined. >+ * Returns TRUE if the envVar is already set, or if it is >+ * successfully set. */ >+static int appendEnv(char *envVar, char *envDir, char *suffix) { >+ char *envVarVal; >+ char *envDirVal; >+ envVarVal = getenv (envVar); >+ if (envVarVal == NULL || strlen(envVarVal)==0) { >+ if (envDir == NULL) { >+ setenv(envVar,suffix,TRUE); >+ } else { >+ envDirVal = getenv(envDir); >+ if (envDirVal == NULL) >+ return FALSE; >+ envVarVal = (char *)malloc((strlen(envDirVal)+strlen(suffix)+1)*sizeof(char)); >+ if (envVarVal == NULL) >+ return FALSE; >+ if (snprintf(envVarVal, strlen(envDirVal)+strlen(suffix)+1,"%s%s",envDirVal,suffix) < 0) >+ return FALSE; >+ setenv(envVar,envVarVal,TRUE); >+ } >+ } >+ return TRUE; >+} >+ > /** Set the ctarget and profile */ > static void setCtargetAndProfile(WrapperData *data) { > char tmp[MAXPATHLEN + 1]; >@@ -265,29 +418,26 @@ > } > > int main(int argc, char *argv[]) { >- WrapperData *data; >+ WrapperData data; > char *extraCflags = NULL; >- >- data = (WrapperData *)alloca(sizeof(WrapperData)); >- if(data == NULL) >- die("Memory allocation failure."); >+ char *gcc_specs; > > /* Load the config file */ >- data->selectionConf = loadSelectionConf(CONFIGURATION_DIR, 1); >- if(data->selectionConf == NULL) >+ data.selectionConf = loadSelectionConf(CONFIGURATION_DIR, 1); >+ if(data.selectionConf == NULL) > die("Memory allocation failure."); > > /* The argv to pass to the forked process. Defaults to be the same */ >- data->argv = argv; >+ data.argv = argv; > > /* Figure out out CTARGET and our Profile */ >- setCtargetAndProfile(data); >+ setCtargetAndProfile(&data); > > /* Determine what binary we will be executing */ >- setExecBinary(data); >+ setExecBinary(&data); > > /* Do we need to set any additional CFLAGS? */ >- if(data->selectionConf->useABI && getenv("ABI")) { >+ if(data.selectionConf->useABI && getenv("ABI")) { > /* This functionality is deprecated and subject to be removed > * once all profiles in portage nolonger depend on it. > */ >@@ -297,29 +447,60 @@ > if (getenv(envvar)) > extraCflags = getenv(envvar); > } else { >- extraCflags = ((Profile *)hashGet(data->selectionConf->selectionHash, data->ctarget))->cflags; >+ extraCflags = ((Profile *)hashGet(data.selectionConf->selectionHash, data.ctarget))->cflags; > } > > if(extraCflags) { >- data->argv = buildNewArgv(data->argv, extraCflags); >- if(data->argv == NULL) >+ data.argv = buildNewArgv(data.argv, extraCflags); >+ if(data.argv == NULL) > die("Memory allocation failure."); > } > >- /* Select the appropriate GCC specs file */ >- if(data->profile->specs && getenv("GCC_SPECS") == NULL) >- setenv("GCC_SPECS", data->profile->specs, 1); >+ /* Convert env specs or config specs into arguments >+ * Env GCC_SPECS is honoured for native compiler only >+ */ >+ gcc_specs = getenv("GCC_SPECS"); >+ if (gcc_specs && >+ strcmp(data.ctarget, data.selectionConf->defaultCtarget) == 0) { >+ data.argv = buildNewArgvSpecs(data.argv, gcc_specs); >+ } else if (data.profile->specs) { >+ data.argv = buildNewArgvSpecs(data.argv, data.profile->specs); >+ } >+ unsetenv("GCC_SPECS"); > > /* Set argv[0] to the correct binary (the full path > * of the binary we are executing), else gcc can't > * find internal headers > * http://bugs.gentoo.org/show_bug.cgi?id=8132 > */ >- data->argv[0] = data->execBinary; >+ data.argv[0] = data.execBinary; >+ >+ /* Prepend distcc, if enabled. >+ * Set DISTCC_DIR to PORTAGE_TMPDIR/.distcc if not already set >+ * Append DISTCC_DIR to SANDBOX_WRITE >+ * Shuffle argv and set argv[0] to /usr/bin/distcc >+ */ >+ if (distccRequired() && >+ appendEnv("DISTCC_DIR", "PORTAGE_TMPDIR", "/.distcc") && >+ addPathToEnv("SANDBOX_WRITE",getenv("DISTCC_DIR"))) { >+ data.argv = prependArgv(data.argv, "/usr/bin/distcc"); >+ } >+ >+ /* Prepend ccache, if enabled. >+ * Set CCACHE_DIR to /var/tmp/ccache if not already set >+ * Append CCACHE_DIR to SANDBOX_WRITE, SANDBOX_READ >+ * Shuffle argv and set argv[0] to /usr/bin/ccache >+ */ >+ if (ccacheRequired() && >+ appendEnv("CCACHE_DIR", NULL, "/var/tmp/ccache") && >+ addPathToEnv("SANDBOX_READ",getenv("CCACHE_DIR")) && >+ addPathToEnv("SANDBOX_WRITE",getenv("CCACHE_DIR"))) { >+ data.argv = prependArgv(data.argv, "/usr/bin/ccache"); >+ } > > /* Ok, lets exec it. */ >- if (execv(data->execBinary, data->argv) < 0) >- die("Could not run/locate \"%s\"", data->execBinary); >+ if (execv(data.argv[0], data.argv) < 0) >+ die("Could not run/locate \"%s\"", data.argv[0]); > > return 0; > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 128810
:
83908
|
83909
|
84032
|
84033
|
86738