Warn when a duplicate CLI argument overrides a previous one (#1053)

Fixes #1050
This commit is contained in:
Rangi
2022-09-25 04:04:30 -04:00
committed by GitHub
parent 2827374505
commit 5ad8a8c958
5 changed files with 44 additions and 19 deletions

View File

@@ -19,6 +19,7 @@
#include "asm/main.h"
#include "asm/symbol.h"
#include "asm/warning.h"
#include "error.h"
#include "platform.h" // S_ISDIR (stat macro)
#define MAXINCPATHS 128
@@ -137,7 +138,11 @@ void fstk_AddIncludePath(char const *path)
void fstk_SetPreIncludeFile(char const *path)
{
if (preIncludeName)
warnx("Overriding pre-included filename %s", preIncludeName);
preIncludeName = path;
if (verbose)
printf("Pre-included filename %s\n", preIncludeName);
}
static void printDep(char const *path)

View File

@@ -53,11 +53,11 @@ char const *__asan_default_options(void) { return "detect_leaks=0"; }
// Unfortunately, macOS still ships 2.3, which is from 2008...
int yyparse(void);
FILE * dependfile;
bool generatedMissingIncludes;
bool failedOnMissingInclude;
bool generatePhonyDeps;
char *targetFileName;
FILE *dependfile = NULL;
bool generatedMissingIncludes = false;
bool failedOnMissingInclude = false;
bool generatePhonyDeps = false;
char *targetFileName = NULL;
bool haltnop;
bool warnOnHaltNop;
@@ -148,9 +148,6 @@ static void print_usage(void)
int main(int argc, char *argv[])
{
int ch;
char *ep;
time_t now = time(NULL);
char const *sourceDateEpoch = getenv("SOURCE_DATE_EPOCH");
@@ -159,18 +156,11 @@ int main(int argc, char *argv[])
if (sourceDateEpoch)
now = (time_t)strtoul(sourceDateEpoch, NULL, 0);
dependfile = NULL;
// Perform some init for below
sym_Init(now);
// Set defaults
generatePhonyDeps = false;
generatedMissingIncludes = false;
failedOnMissingInclude = false;
targetFileName = NULL;
opt_B("01");
opt_G("0123");
opt_P(0);
@@ -183,8 +173,11 @@ int main(int argc, char *argv[])
warnings = true;
sym_SetExportAll(false);
uint32_t maxDepth = DEFAULT_MAX_DEPTH;
char *dependFileName = NULL;
size_t targetFileNameLen = 0;
int ch;
char *ep;
while ((ch = musl_getopt_long_only(argc, argv, optstring, longopts, NULL)) != -1) {
switch (ch) {
case 'b':
@@ -243,12 +236,17 @@ int main(int argc, char *argv[])
break;
case 'M':
if (!strcmp("-", musl_optarg))
if (dependfile)
warnx("Overriding dependfile %s", dependFileName);
if (!strcmp("-", musl_optarg)) {
dependfile = stdout;
else
dependFileName = "<stdout>";
} else {
dependfile = fopen(musl_optarg, "w");
dependFileName = musl_optarg;
}
if (dependfile == NULL)
err("Could not open dependfile %s", musl_optarg);
err("Could not open dependfile %s", dependFileName);
break;
case 'o':

View File

@@ -540,7 +540,9 @@ void out_WriteObject(void)
// Set the objectfilename
void out_SetFileName(char *s)
{
if (objectName)
warnx("Overriding output filename %s", objectName);
objectName = s;
if (verbose)
printf("Output filename %s\n", s);
printf("Output filename %s\n", objectName);
}

View File

@@ -337,6 +337,8 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
break;
case 'a':
autoAttrmap = false;
if (!options.attrmap.empty())
warning("Overriding attrmap file %s", options.attrmap.c_str());
options.attrmap = musl_optarg;
break;
case 'b':
@@ -479,6 +481,8 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
}
break;
case 'o':
if (!options.output.empty())
warning("Overriding tile data file %s", options.output.c_str());
options.output = musl_optarg;
break;
case 'P':
@@ -486,6 +490,8 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
break;
case 'p':
autoPalettes = false;
if (!options.palettes.empty())
warning("Overriding palettes file %s", options.palettes.c_str());
options.palettes = musl_optarg;
break;
case 'Q':
@@ -493,6 +499,8 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
break;
case 'q':
autoPalmap = false;
if (!options.palmap.empty())
warning("Overriding palette map file %s", options.palmap.c_str());
options.palmap = musl_optarg;
break;
case 'r':
@@ -520,6 +528,8 @@ static char *parseArgv(int argc, char **argv, bool &autoAttrmap, bool &autoTilem
break;
case 't':
autoTilemap = false;
if (!options.tilemap.empty())
warning("Overriding tilemap file %s", options.tilemap.c_str());
options.tilemap = musl_optarg;
break;
case 'V':

View File

@@ -369,21 +369,31 @@ int main(int argc, char *argv[])
isWRA0Mode = true;
break;
case 'l':
if (linkerScriptName)
warnx("Overriding linkerscript %s", musl_optarg);
linkerScriptName = musl_optarg;
break;
case 'M':
noSymInMap = true;
break;
case 'm':
if (mapFileName)
warnx("Overriding mapfile %s", musl_optarg);
mapFileName = musl_optarg;
break;
case 'n':
if (symFileName)
warnx("Overriding symfile %s", musl_optarg);
symFileName = musl_optarg;
break;
case 'O':
if (overlayFileName)
warnx("Overriding overlay file %s", musl_optarg);
overlayFileName = musl_optarg;
break;
case 'o':
if (outputFileName)
warnx("Overriding output file %s", musl_optarg);
outputFileName = musl_optarg;
break;
case 'p':