summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2021-04-03 20:07:59 +0000
committermidipix <writeonce@midipix.org>2021-04-03 20:12:42 +0000
commitd4c3e3af3e27781da414714e63ef52c9c711e1b6 (patch)
tree6c2cb063231de6fe0dddef535b801b672de62cfa /src
parent0a81a1d1581dc298ac913e6e706a3ded57b77da9 (diff)
downloadslibtool-d4c3e3af3e27781da414714e63ef52c9c711e1b6.tar.bz2
slibtool-d4c3e3af3e27781da414714e63ef52c9c711e1b6.tar.xz
driver: always respect the NO_COLOR envvar & SLBT_DRIVER_ANNOTATE_NEVER flag.
Diffstat (limited to 'src')
-rw-r--r--src/driver/slbt_amain.c11
-rw-r--r--src/driver/slbt_driver_ctx.c38
2 files changed, 37 insertions, 12 deletions
diff --git a/src/driver/slbt_amain.c b/src/driver/slbt_amain.c
index 0e6456e..78a0973 100644
--- a/src/driver/slbt_amain.c
+++ b/src/driver/slbt_amain.c
@@ -5,9 +5,11 @@
/*******************************************************************/
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <stdbool.h>
#include <slibtool/slibtool.h>
#include "slibtool_driver_impl.h"
#include "slibtool_dprintf_impl.h"
@@ -43,6 +45,9 @@ static ssize_t slbt_version(struct slbt_driver_ctx * dctx, int fdout)
verclr = isatty(fdout) ? slbt_ver_color : slbt_ver_plain;
gitver = strcmp(verinfo->commit,"unknown");
+ if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
+ verclr = slbt_ver_plain;
+
return slbt_dprintf(fdout,vermsg,
verclr[0],dctx->program,verclr[1],
verclr[2],verinfo->major,verinfo->minor,
@@ -89,6 +94,7 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
const char * harg;
int fdout;
uint64_t flags;
+ uint64_t noclr;
struct slbt_driver_ctx * dctx;
char * program;
char * dash;
@@ -96,6 +102,7 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
flags = SLBT_DRIVER_FLAGS;
fdout = fdctx ? fdctx->fdout : STDOUT_FILENO;
+ noclr = getenv("NO_COLOR") ? SLBT_DRIVER_ANNOTATE_NEVER : 0;
/* harg */
harg = (!argv || !argv[0] || !argv[1] || argv[2])
@@ -112,7 +119,7 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
sargv[3] = "<compiler>";
sargv[4] = 0;
- return (slbt_get_driver_ctx(sargv,envp,flags,fdctx,&dctx))
+ return (slbt_get_driver_ctx(sargv,envp,flags|noclr,fdctx,&dctx))
? SLBT_ERROR : (slbt_version(dctx,fdout) < 0)
? slbt_exit(dctx,SLBT_ERROR)
: slbt_exit(dctx,SLBT_OK);
@@ -175,7 +182,7 @@ int slbt_main(char ** argv, char ** envp, const struct slbt_fd_ctx * fdctx)
| SLBT_DRIVER_LEGABITS);
/* driver context */
- if ((ret = slbt_get_driver_ctx(argv,envp,flags,fdctx,&dctx)))
+ if ((ret = slbt_get_driver_ctx(argv,envp,flags|noclr,fdctx,&dctx)))
return (ret == SLBT_USAGE)
? !argv || !argv[0] || !argv[1] || !argv[2]
: SLBT_ERROR;
diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c
index 7e170d2..7ce2c92 100644
--- a/src/driver/slbt_driver_ctx.c
+++ b/src/driver/slbt_driver_ctx.c
@@ -122,16 +122,15 @@ struct slbt_driver_ctx_alloc {
uint64_t guard;
};
-static void slbt_output_raw_vector(int fderr, char ** argv, char ** envp)
+static void slbt_output_raw_vector(int fderr, char ** argv, char ** envp, bool fcolor)
{
char ** parg;
char * dot;
const char * color;
- bool fcolor;
(void)envp;
- if ((fcolor = isatty(fderr)))
+ if (fcolor)
slbt_dprintf(fderr,"%s%s",aclr_bold,aclr_red);
slbt_dprintf(fderr,"\n\n\n%s",argv[0]);
@@ -192,7 +191,8 @@ static int slbt_driver_usage(
const char * arg,
const struct argv_option ** optv,
struct argv_meta * meta,
- struct slbt_split_vector * sargv)
+ struct slbt_split_vector * sargv,
+ int noclr)
{
char header[512];
@@ -200,7 +200,16 @@ static int slbt_driver_usage(
"Usage: %s [options] <file>...\n" "Options:\n",
program);
- argv_usage(fdout,header,optv,arg);
+ switch (noclr) {
+ case 0:
+ argv_usage(fdout,header,optv,arg);
+ break;
+
+ default:
+ argv_usage_plain(fdout,header,optv,arg);
+ break;
+ }
+
argv_free(meta);
slbt_free_argv_buffer(sargv);
@@ -296,7 +305,8 @@ static int slbt_split_argv(
if (!argv[1] && (flags & SLBT_DRIVER_VERBOSITY_USAGE))
return slbt_driver_usage(
fderr,program,
- 0,optv,0,sargv);
+ 0,optv,0,sargv,
+ !!getenv("NO_COLOR"));
/* initial argv scan: ... --mode=xxx ... <compiler> ... */
argv_scan(argv,optv,&ctx,0);
@@ -1244,8 +1254,11 @@ static int slbt_driver_fail_incompatible_args(
{
int fcolor;
+ fcolor = (drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
+ ? 0 : isatty(fderr);
+
if (drvflags & SLBT_DRIVER_VERBOSITY_ERRORS){
- if ((fcolor = isatty(fderr)))
+ if (fcolor)
slbt_dprintf(
fderr,"%s%s",
aclr_bold,aclr_red);
@@ -1314,7 +1327,8 @@ int slbt_get_driver_ctx(
cctx.drvflags = flags | SLBT_DRIVER_SHARED | SLBT_DRIVER_STATIC;
/* full annotation when annotation is on; */
- cctx.drvflags |= SLBT_DRIVER_ANNOTATE_FULL;
+ if (!(cctx.drvflags & SLBT_DRIVER_ANNOTATE_NEVER))
+ cctx.drvflags |= SLBT_DRIVER_ANNOTATE_FULL;
/* track incompatible command-line arguments */
cmdstatic = 0;
@@ -1332,7 +1346,8 @@ int slbt_get_driver_ctx(
? slbt_driver_usage(
fdctx->fdout,program,
entry->arg,optv,
- meta,&sargv)
+ meta,&sargv,
+ (cctx.drvflags & SLBT_DRIVER_ANNOTATE_NEVER))
: SLBT_USAGE;
case TAG_VERSION:
@@ -1661,7 +1676,10 @@ int slbt_get_driver_ctx(
/* debug: raw argument vector */
if (cctx.drvflags & SLBT_DRIVER_DEBUG)
- slbt_output_raw_vector(fdctx->fderr,argv,envp);
+ slbt_output_raw_vector(
+ fdctx->fderr,argv,envp,
+ (cctx.drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
+ ? 0 : isatty(fdctx->fderr));
/* -o in install mode means USER */
if ((cctx.mode == SLBT_MODE_INSTALL) && cctx.output) {