Skip to content

Commit

Permalink
Merge pull request #4256 from MartinNowak/dmdConfSearchOrder
Browse files Browse the repository at this point in the history
add -conf=path compiler switch
  • Loading branch information
andralex committed Jan 7, 2015
2 parents 81673a6 + b6515ed commit 3a0637a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 28 deletions.
37 changes: 31 additions & 6 deletions src/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ void error(const char *filename, unsigned linnum, unsigned charnum, const char *
va_end( ap );
}

void errorSupplemental(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verrorSupplemental(loc, format, ap);
va_end( ap );
}

void warning(Loc loc, const char *format, ...)
{
va_list ap;
Expand All @@ -136,15 +144,11 @@ void warning(Loc loc, const char *format, ...)
va_end( ap );
}

/**************************************
* Print supplementary message about the last error
* Used for backtraces, etc
*/
void errorSupplemental(Loc loc, const char *format, ...)
void warningSupplemental(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
verrorSupplemental(loc, format, ap);
vwarningSupplemental(loc, format, ap);
va_end( ap );
}

Expand All @@ -153,7 +157,14 @@ void deprecation(Loc loc, const char *format, ...)
va_list ap;
va_start(ap, format);
vdeprecation(loc, format, ap);
va_end( ap );
}

void deprecationSupplemental(Loc loc, const char *format, ...)
{
va_list ap;
va_start(ap, format);
vdeprecation(loc, format, ap);
va_end( ap );
}

Expand Down Expand Up @@ -221,6 +232,12 @@ void vwarning(Loc loc, const char *format, va_list ap)
}
}

void vwarningSupplemental(Loc loc, const char *format, va_list ap)
{
if (global.params.warnings && !global.gag)
verrorPrint(loc, COLOR_YELLOW, " ", format, ap);
}

void vdeprecation(Loc loc, const char *format, va_list ap,
const char *p1, const char *p2)
{
Expand All @@ -231,6 +248,14 @@ void vdeprecation(Loc loc, const char *format, va_list ap,
verrorPrint(loc, COLOR_BLUE, header, format, ap, p1, p2);
}

void vdeprecationSupplemental(Loc loc, const char *format, va_list ap)
{
if (global.params.useDeprecated == 0)
verrorSupplemental(loc, format, ap);
else if (global.params.useDeprecated == 2 && !global.gag)
verrorPrint(loc, COLOR_BLUE, " ", format, ap);
}

/***************************************
* Call this after printing out fatal error messages to clean up and exit
* the compiler.
Expand Down
6 changes: 5 additions & 1 deletion src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
bool isConsoleColorSupported();

void warning(Loc loc, const char *format, ...);
void warningSupplemental(Loc loc, const char *format, ...);
void deprecation(Loc loc, const char *format, ...);
void deprecationSupplemental(Loc loc, const char *format, ...);
void error(Loc loc, const char *format, ...);
void errorSupplemental(Loc loc, const char *format, ...);
void verror(Loc loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL, const char *header = "Error: ");
void vwarning(Loc loc, const char *format, va_list);
void verrorSupplemental(Loc loc, const char *format, va_list ap);
void vwarning(Loc loc, const char *format, va_list);
void vwarningSupplemental(Loc loc, const char *format, va_list ap);
void vdeprecation(Loc loc, const char *format, va_list ap, const char *p1 = NULL, const char *p2 = NULL);
void vdeprecationSupplemental(Loc loc, const char *format, va_list ap);

#if defined(__GNUC__) || defined(__clang__)
__attribute__((noreturn))
Expand Down
2 changes: 1 addition & 1 deletion src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct Param
bool useScope; // diagnose 'scope' errors
bool release; // build release version
bool preservePaths; // true means don't strip path from source file
char warnings; // 0: enable warnings
char warnings; // 0: disable warnings
// 1: warnings as errors
// 2: informational warnings (no errors)
bool pic; // generate position-independent-code for shared libs
Expand Down
25 changes: 14 additions & 11 deletions src/inifile.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@

char *skipspace(char *p);

const char *findinifile(const char *argv0, const char *inifile)
/*****************************
* Find the config file
* Input:
* argv0 program name (argv[0])
* inifile .ini file name
* Returns:
* file path of the config file or NULL
* Note: this is a memory leak
*/
const char *findConfFile(const char *argv0, const char *inifile)
{
#if LOG
printf("findinifile(argv0 = '%s', inifile = '%s')\n", argv0, inifile);
Expand Down Expand Up @@ -111,17 +120,11 @@ const char *findinifile(const char *argv0, const char *inifile)
* Read and analyze .ini file, i.e. write the entries of the specified section
* into the process environment
* Input:
* argv0 program name (argv[0])
* inifile .ini file name
* filename path to config file
* envsectionname name of the section to process
* Returns:
* file name of ini file
* Note: this is a memory leak
*/

const char *inifile(const char *argv0, const char *inifile, const char *envsectionname)
void parseConfFile(const char *filename, const char *envsectionname)
{
const char *filename = findinifile(argv0, inifile);
const char *path = FileName::path(filename); // need path for @P macro
#if LOG
printf("\tpath = '%s', filename = '%s'\n", path, filename);
Expand All @@ -130,7 +133,7 @@ const char *inifile(const char *argv0, const char *inifile, const char *envsecti
File file(filename);

if (file.read())
return filename; // error reading file
return; // error reading file

// Parse into lines
bool envsection = true;
Expand Down Expand Up @@ -296,7 +299,7 @@ const char *inifile(const char *argv0, const char *inifile, const char *envsecti
break;
}
}
return filename;
return;
}

/********************
Expand Down
58 changes: 49 additions & 9 deletions src/mars.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ void getenv_setargv(const char *envvar, size_t *pargc, const char** *pargv);

void printCtfePerformanceStats();

static const char* parse_arch(size_t argc, const char** argv, const char* arch);
static const char* parse_arch_arg(size_t argc, const char** argv, const char* arch);
static const char* parse_conf_arg(size_t argc, const char** argv);

void inlineScan(Module *m);

Expand All @@ -57,7 +58,8 @@ void initTraitsStringTable();
int runLINK();
void deleteExeFile();
int runProgram();
const char *inifile(const char *argv0, const char *inifile, const char* envsectionname);
const char *findConfFile(const char *argv0, const char *inifile);
void parseConfFile(const char *filename, const char* envsectionname);

/** Normalize path by turning forward slashes into backslashes */
const char * toWinPath(const char *src)
Expand Down Expand Up @@ -139,6 +141,7 @@ Usage:\n\
-allinst generate code for all template instantiations\n\
-c do not link\n\
-color[=on|off] force colored console output on or off\n\
-conf=path use config file at path\n\
-cov do code coverage analysis\n\
-cov=nnn require at least nnn%% code coverage\n\
-D generate documentation\n\
Expand Down Expand Up @@ -369,26 +372,37 @@ int tryMain(size_t argc, const char *argv[])
VersionCondition::addPredefinedGlobalIdent("D_Version2");
VersionCondition::addPredefinedGlobalIdent("all");

global.inifilename = parse_conf_arg(argc, argv);
if (global.inifilename)
{
// can be empty as in -conf=
if (strlen(global.inifilename) && !FileName::exists(global.inifilename))
error(Loc(), "Config file '%s' does not exist.", global.inifilename);
}
else
{
#if _WIN32
global.inifilename = inifile(argv[0], "sc.ini", "Environment");
global.inifilename = findConfFile(argv[0], "sc.ini");
#elif __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
global.inifilename = inifile(argv[0], "dmd.conf", "Environment");
global.inifilename = findConfFile(argv[0], "dmd.conf");
#else
#error "fix this"
#endif
}
parseConfFile(global.inifilename, "Environment");

size_t dflags_argc = 0;
const char** dflags_argv = NULL;
getenv_setargv("DFLAGS", &dflags_argc, &dflags_argv);

const char *arch = global.params.is64bit ? "64" : "32"; // use default
arch = parse_arch(argc, argv, arch);
arch = parse_arch(dflags_argc, dflags_argv, arch);
arch = parse_arch_arg(argc, argv, arch);
arch = parse_arch_arg(dflags_argc, dflags_argv, arch);
bool is64bit = arch[0] == '6';

char envsection[80];
sprintf(envsection, "Environment%s", arch);
inifile(argv[0], global.inifilename, envsection);
parseConfFile(global.inifilename, envsection);

getenv_setargv("DFLAGS", &argc, &argv);

Expand Down Expand Up @@ -430,6 +444,10 @@ int tryMain(size_t argc, const char *argv[])
else if (p[6])
goto Lerror;
}
else if (memcmp(p + 1, "conf=", 5) == 0)
{
// ignore, already handled above
}
else if (memcmp(p + 1, "cov", 3) == 0)
{
global.params.cov = true;
Expand Down Expand Up @@ -1793,10 +1811,11 @@ void escapePath(OutBuffer *buf, const char *fname)
* to detect the desired architecture.
*/

static const char* parse_arch(size_t argc, const char** argv, const char* arch)
static const char* parse_arch_arg(size_t argc, const char** argv, const char* arch)
{
for (size_t i = 0; i < argc; ++i)
{ const char* p = argv[i];
{
const char* p = argv[i];
if (p[0] == '-')
{
if (strcmp(p + 1, "m32") == 0 || strcmp(p + 1, "m32mscoff") == 0 || strcmp(p + 1, "m64") == 0)
Expand All @@ -1808,6 +1827,27 @@ static const char* parse_arch(size_t argc, const char** argv, const char* arch)
return arch;
}

/***********************************
* Parse command line arguments for -conf=path.
*/

static const char* parse_conf_arg(size_t argc, const char** argv)
{
const char *conf=NULL;
for (size_t i = 0; i < argc; ++i)
{
const char* p = argv[i];
if (p[0] == '-')
{
if (strncmp(p + 1, "conf=", 5) == 0)
conf = p + 6;
else if (strcmp(p + 1, "run") == 0)
break;
}
}
return conf;
}

Dsymbols *Dsymbols_create() { return new Dsymbols(); }
Symbols *Symbols_create() { return new Symbols(); }
VarDeclarations *VarDeclarations_create() { return new VarDeclarations(); }
Expand Down

0 comments on commit 3a0637a

Please sign in to comment.