* [Buildroot] [PATCH] toolchain/toolchain-wrapper.c: set CCACHE env variables only when ccache is enabled
@ 2022-08-06 19:58 Thomas Petazzoni via buildroot
2023-02-07 11:29 ` Yann E. MORIN
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Petazzoni via buildroot @ 2022-08-06 19:58 UTC (permalink / raw)
To: buildroot
Cc: Thomas De Schampheleire, Giulio Benetti, Romain Naour,
Yann E. MORIN, Thomas Petazzoni
This commit modifies the toolchain-wrapper to make sure that the
CCACHE_COMPILERCHECK and CCACHE_BASEDIR are only set if ccache support
is enabled. Indeed, when BR2_USE_CCACHE is not set (or to a value
different than 1), we don't call the compiler with ccache, so there is
no reason to set those ccache environment variables, and they could
potentially conflict with a separate usage of ccache, outside of
Buildroot, for example when using the Buildroot SDK.
In particular, the value of CCACHE_BASEDIR doesn't not make any sense
when the Buildroot toolchain is not used during the Buildroot build,
as it points to the output directory $(BASE_DIR).
We pay attention to also not show those variables as being set in the
BR2_DEBUG_WRAPPER dump.
To help a little bit with this, a ccache_enabled boolean is introduced
to indicate when ccache is being used.
There is still quite a bit of #ifdef-ery involved, but it's not easy
to find a simpler way to organize the code.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
toolchain/toolchain-wrapper.c | 49 +++++++++++++++++++----------------
1 file changed, 27 insertions(+), 22 deletions(-)
diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c
index 37b24dd24a..ee1fdf3c71 100644
--- a/toolchain/toolchain-wrapper.c
+++ b/toolchain/toolchain-wrapper.c
@@ -507,10 +507,28 @@ int main(int argc, char **argv)
exec_args = args;
#ifdef BR_CCACHE
- /* If BR2_USE_CCACHE is not defined, or its value is not 1,
- * skip the ccache call */
+ /* If BR2_USE_CCACHE is set and its value is 1, enable ccache
+ * usage */
char *br_use_ccache = getenv("BR2_USE_CCACHE");
- if (!br_use_ccache || strncmp(br_use_ccache, "1", strlen("1")))
+ bool ccache_enabled = br_use_ccache && !strncmp(br_use_ccache, "1", strlen("1"));
+
+ if (ccache_enabled) {
+#ifdef BR_CCACHE_HASH
+ /* Allow compilercheck to be overridden through the environment */
+ if (setenv("CCACHE_COMPILERCHECK", "string:" BR_CCACHE_HASH, 0)) {
+ perror(__FILE__ ": Failed to set CCACHE_COMPILERCHECK");
+ return 3;
+ }
+#endif
+#ifdef BR_CCACHE_BASEDIR
+ /* Allow compilercheck to be overridden through the environment */
+ if (setenv("CCACHE_BASEDIR", BR_CCACHE_BASEDIR, 0)) {
+ perror(__FILE__ ": Failed to set CCACHE_BASEDIR");
+ return 3;
+ }
+#endif
+ } else
+ /* ccache is disabled, skip it */
exec_args++;
#endif
@@ -518,12 +536,14 @@ int main(int argc, char **argv)
if (debug > 0) {
fprintf(stderr, "Toolchain wrapper executing:");
#ifdef BR_CCACHE_HASH
- fprintf(stderr, "%sCCACHE_COMPILERCHECK='string:" BR_CCACHE_HASH "'",
- (debug == 2) ? "\n " : " ");
+ if (ccache_enabled)
+ fprintf(stderr, "%sCCACHE_COMPILERCHECK='string:" BR_CCACHE_HASH "'",
+ (debug == 2) ? "\n " : " ");
#endif
#ifdef BR_CCACHE_BASEDIR
- fprintf(stderr, "%sCCACHE_BASEDIR='" BR_CCACHE_BASEDIR "'",
- (debug == 2) ? "\n " : " ");
+ if (ccache_enabled)
+ fprintf(stderr, "%sCCACHE_BASEDIR='" BR_CCACHE_BASEDIR "'",
+ (debug == 2) ? "\n " : " ");
#endif
for (i = 0; exec_args[i]; i++)
fprintf(stderr, "%s'%s'",
@@ -531,21 +551,6 @@ int main(int argc, char **argv)
fprintf(stderr, "\n");
}
-#ifdef BR_CCACHE_HASH
- /* Allow compilercheck to be overridden through the environment */
- if (setenv("CCACHE_COMPILERCHECK", "string:" BR_CCACHE_HASH, 0)) {
- perror(__FILE__ ": Failed to set CCACHE_COMPILERCHECK");
- return 3;
- }
-#endif
-#ifdef BR_CCACHE_BASEDIR
- /* Allow compilercheck to be overridden through the environment */
- if (setenv("CCACHE_BASEDIR", BR_CCACHE_BASEDIR, 0)) {
- perror(__FILE__ ": Failed to set CCACHE_BASEDIR");
- return 3;
- }
-#endif
-
if (execv(exec_args[0], exec_args))
perror(path);
--
2.37.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Buildroot] [PATCH] toolchain/toolchain-wrapper.c: set CCACHE env variables only when ccache is enabled
2022-08-06 19:58 [Buildroot] [PATCH] toolchain/toolchain-wrapper.c: set CCACHE env variables only when ccache is enabled Thomas Petazzoni via buildroot
@ 2023-02-07 11:29 ` Yann E. MORIN
0 siblings, 0 replies; 2+ messages in thread
From: Yann E. MORIN @ 2023-02-07 11:29 UTC (permalink / raw)
To: Thomas Petazzoni
Cc: Giulio Benetti, Romain Naour, Thomas De Schampheleire, buildroot
Thomas, All,
On 2022-08-06 21:58 +0200, Thomas Petazzoni via buildroot spake thusly:
> This commit modifies the toolchain-wrapper to make sure that the
> CCACHE_COMPILERCHECK and CCACHE_BASEDIR are only set if ccache support
> is enabled. Indeed, when BR2_USE_CCACHE is not set (or to a value
> different than 1), we don't call the compiler with ccache, so there is
> no reason to set those ccache environment variables, and they could
> potentially conflict with a separate usage of ccache, outside of
> Buildroot, for example when using the Buildroot SDK.
>
> In particular, the value of CCACHE_BASEDIR doesn't not make any sense
> when the Buildroot toolchain is not used during the Buildroot build,
> as it points to the output directory $(BASE_DIR).
>
> We pay attention to also not show those variables as being set in the
> BR2_DEBUG_WRAPPER dump.
>
> To help a little bit with this, a ccache_enabled boolean is introduced
> to indicate when ccache is being used.
>
> There is still quite a bit of #ifdef-ery involved, but it's not easy
> to find a simpler way to organize the code.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Applied to master, thanks.
Regards,
Yann E. MORIN.
> ---
> toolchain/toolchain-wrapper.c | 49 +++++++++++++++++++----------------
> 1 file changed, 27 insertions(+), 22 deletions(-)
>
> diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c
> index 37b24dd24a..ee1fdf3c71 100644
> --- a/toolchain/toolchain-wrapper.c
> +++ b/toolchain/toolchain-wrapper.c
> @@ -507,10 +507,28 @@ int main(int argc, char **argv)
>
> exec_args = args;
> #ifdef BR_CCACHE
> - /* If BR2_USE_CCACHE is not defined, or its value is not 1,
> - * skip the ccache call */
> + /* If BR2_USE_CCACHE is set and its value is 1, enable ccache
> + * usage */
> char *br_use_ccache = getenv("BR2_USE_CCACHE");
> - if (!br_use_ccache || strncmp(br_use_ccache, "1", strlen("1")))
> + bool ccache_enabled = br_use_ccache && !strncmp(br_use_ccache, "1", strlen("1"));
> +
> + if (ccache_enabled) {
> +#ifdef BR_CCACHE_HASH
> + /* Allow compilercheck to be overridden through the environment */
> + if (setenv("CCACHE_COMPILERCHECK", "string:" BR_CCACHE_HASH, 0)) {
> + perror(__FILE__ ": Failed to set CCACHE_COMPILERCHECK");
> + return 3;
> + }
> +#endif
> +#ifdef BR_CCACHE_BASEDIR
> + /* Allow compilercheck to be overridden through the environment */
> + if (setenv("CCACHE_BASEDIR", BR_CCACHE_BASEDIR, 0)) {
> + perror(__FILE__ ": Failed to set CCACHE_BASEDIR");
> + return 3;
> + }
> +#endif
> + } else
> + /* ccache is disabled, skip it */
> exec_args++;
> #endif
>
> @@ -518,12 +536,14 @@ int main(int argc, char **argv)
> if (debug > 0) {
> fprintf(stderr, "Toolchain wrapper executing:");
> #ifdef BR_CCACHE_HASH
> - fprintf(stderr, "%sCCACHE_COMPILERCHECK='string:" BR_CCACHE_HASH "'",
> - (debug == 2) ? "\n " : " ");
> + if (ccache_enabled)
> + fprintf(stderr, "%sCCACHE_COMPILERCHECK='string:" BR_CCACHE_HASH "'",
> + (debug == 2) ? "\n " : " ");
> #endif
> #ifdef BR_CCACHE_BASEDIR
> - fprintf(stderr, "%sCCACHE_BASEDIR='" BR_CCACHE_BASEDIR "'",
> - (debug == 2) ? "\n " : " ");
> + if (ccache_enabled)
> + fprintf(stderr, "%sCCACHE_BASEDIR='" BR_CCACHE_BASEDIR "'",
> + (debug == 2) ? "\n " : " ");
> #endif
> for (i = 0; exec_args[i]; i++)
> fprintf(stderr, "%s'%s'",
> @@ -531,21 +551,6 @@ int main(int argc, char **argv)
> fprintf(stderr, "\n");
> }
>
> -#ifdef BR_CCACHE_HASH
> - /* Allow compilercheck to be overridden through the environment */
> - if (setenv("CCACHE_COMPILERCHECK", "string:" BR_CCACHE_HASH, 0)) {
> - perror(__FILE__ ": Failed to set CCACHE_COMPILERCHECK");
> - return 3;
> - }
> -#endif
> -#ifdef BR_CCACHE_BASEDIR
> - /* Allow compilercheck to be overridden through the environment */
> - if (setenv("CCACHE_BASEDIR", BR_CCACHE_BASEDIR, 0)) {
> - perror(__FILE__ ": Failed to set CCACHE_BASEDIR");
> - return 3;
> - }
> -#endif
> -
> if (execv(exec_args[0], exec_args))
> perror(path);
>
> --
> 2.37.1
>
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-02-07 11:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-06 19:58 [Buildroot] [PATCH] toolchain/toolchain-wrapper.c: set CCACHE env variables only when ccache is enabled Thomas Petazzoni via buildroot
2023-02-07 11:29 ` Yann E. MORIN
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox