Skip to content

Commit 5512bf8

Browse files
committed
Improved diagnostic messages.
The --debug flag now takes either a number or the name of the messages to show. Ie. one can now use mm --debug verbose to enable messages. All debug messages above normal will also tell which level they originate from, so that it is easier to discover the different levels. Added the new level PEDANTIC to allow for a level that spots suspicious things which are not always errors that one can use to easily spot common mistakes. Currently, I added a warning for including files outside the working directory. These were previously silently ignored. This is currently the only warning for PEDANTIC, but more will come as they are needed. Signed-off-by: Filip Strömbäck <fstromback@gmail.com>
1 parent be2e5d4 commit 5512bf8

File tree

6 files changed

+73
-20
lines changed

6 files changed

+73
-20
lines changed

src/cmdline.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ static const char *helpStr =
3535
"[option] - use the corresponding section in the config file.\n"
3636
"[file] - input files in addition to those specified in the config.\n"
3737
"--output, -o - specify the name of the output file.\n"
38-
"--debug, -d - specify debug level. 0 = silent, 3 = verbose.\n"
38+
"--debug, -d - specify debug level. One of the following values, or its numerical value:\n"
39+
" QUIET = 0 - no output except for hard errors.\n"
40+
" NORMAL = 1 - standard. Outputs progress information.\n"
41+
" PEDANTIC = 2 - warns about suspicious things, which could be errors.\n"
42+
" INFO = 3 - information about decisions made during the build. Good for debugging.\n"
43+
" VERBOSE = 4 - all information you will possibly need when debugging your configurations.\n"
44+
" DEBUG = 5 - information usually only needed when debugging mymake itself.\n"
3945
"--exec-path, -p - specify the cwd when running the output.\n"
4046
"--help, -? - show this help.\n"
4147
"--force, -f - always recompile everything.\n"
@@ -256,6 +262,38 @@ bool CmdLine::parseOption(char opt) {
256262
return true;
257263
}
258264

265+
static bool strEq(const String &a, const char *b) {
266+
for (nat i = 0; i < a.size(); i++) {
267+
if (b[i] == 0)
268+
return false;
269+
270+
if (tolower(a[i]) != tolower(b[i]))
271+
return false;
272+
}
273+
274+
if (b[a.size()] != 0)
275+
return false;
276+
277+
return true;
278+
}
279+
280+
static int findDebugLevel(const String &name) {
281+
if (strEq(name, "QUIET"))
282+
return dbg_QUIET;
283+
if (strEq(name, "NORMAL"))
284+
return dbg_NORMAL;
285+
if (strEq(name, "PEDANTIC"))
286+
return dbg_PEDANTIC;
287+
if (strEq(name, "INFO"))
288+
return dbg_INFO;
289+
if (strEq(name, "VERBOSE"))
290+
return dbg_VERBOSE;
291+
if (strEq(name, "DEBUG"))
292+
return dbg_DEBUG;
293+
294+
return to<int>(name, -1);
295+
}
296+
259297
bool CmdLine::optionParam(const String &v) {
260298
State s = state;
261299
state = sNone;
@@ -269,7 +307,11 @@ bool CmdLine::optionParam(const String &v) {
269307
state = sArguments;
270308
return true;
271309
case sDebug:
272-
debugLevel = to<int>(v);
310+
debugLevel = findDebugLevel(v);
311+
if (debugLevel < 0) {
312+
PLN("Invalid value for debug level!");
313+
errors = true;
314+
}
273315
return true;
274316
case sExecPath:
275317
execPath = Path(v).makeAbsolute();

src/compile.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ namespace compile {
103103
}
104104

105105
// No need to follow further!
106+
DEBUG(L"Ignoring file outside of working directory: " << now.makeRelative(wd), PEDANTIC);
106107
continue;
107108
}
108109

@@ -200,7 +201,7 @@ namespace compile {
200201

201202
if (!force && pchValid && output.exists() && output.mTime() >= lastModified) {
202203
DEBUG("Skipping " << src.makeRelative(wd) << "...", INFO);
203-
DEBUG("Source modified: " << lastModified << ", output modified " << output.mTime(), VERBOSE);
204+
DEBUG("Source modified: " << lastModified << ", output modified " << output.mTime(), DEBUG);
204205

205206
Timestamp mTime = output.mTime();
206207
if (i == 0)
@@ -281,7 +282,7 @@ namespace compile {
281282
// Link the output.
282283
if (!force && output.exists() && output.mTime() >= latestModified) {
283284
DEBUG("Skipping linking.", INFO);
284-
DEBUG("Output modified " << output.mTime() << ", input modified " << latestModified, VERBOSE);
285+
DEBUG("Output modified " << output.mTime() << ", input modified " << latestModified, DEBUG);
285286
return true;
286287
}
287288

@@ -438,12 +439,12 @@ namespace compile {
438439
vector<Path> children = at.children();
439440
for (nat i = 0; i < children.size(); i++) {
440441
if (children[i].isDir()) {
441-
DEBUG("Found directory " << children[i], VERBOSE);
442+
DEBUG("Found directory " << children[i], DEBUG);
442443
addFilesRecursive(to, children[i]);
443444
} else {
444-
DEBUG("Found file " << children[i], VERBOSE);
445+
DEBUG("Found file " << children[i], DEBUG);
445446
if (std::find(validExts.begin(), validExts.end(), children[i].ext()) != validExts.end()) {
446-
DEBUG("Adding file " << children[i], INFO);
447+
DEBUG("Adding file " << children[i], VERBOSE);
447448
to << Compile(children[i], false, true);
448449
}
449450
}
@@ -496,7 +497,7 @@ namespace compile {
496497
if (w.matches(file))
497498
return variant.substr(colon + 1);
498499

499-
DEBUG("No match for " << file << " using " << variant, VERBOSE);
500+
DEBUG("No match for " << file << " using " << variant, INFO);
500501
}
501502

502503
return "";

src/includes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ bool Includes::ignored(const Path &path) const {
277277

278278
for (nat i = 0; i < ignorePatterns.size(); i++) {
279279
if (ignorePatterns[i].matches(t)) {
280-
DEBUG(path << " ignored as per " << ignorePatterns[i], VERBOSE);
280+
DEBUG(path << " ignored as per " << ignorePatterns[i], INFO);
281281
return true;
282282
}
283283
}

src/mymake.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ int compileTarget(const Path &wd, const CmdLine &cmdline) {
1212
// Load the system-global file.
1313
Path globalFile(Path::home() + localConfig);
1414
if (globalFile.exists()) {
15-
DEBUG("Global file found: " << globalFile, INFO);
15+
DEBUG("Global file found: " << globalFile, VERBOSE);
1616
config.load(globalFile);
1717
}
1818

1919
Path localFile(wd + localConfig);
2020
if (localFile.exists()) {
2121
config.load(localFile);
22-
DEBUG("Local file found: " << localFile, INFO);
22+
DEBUG("Local file found: " << localFile, VERBOSE);
2323
}
2424

2525
// Compile plain .mymake-file.
@@ -58,11 +58,11 @@ int compileProject(const Path &wd, const Path &projectFile, const CmdLine &cmdli
5858

5959
Path globalFile(Path::home() + localConfig);
6060
if (globalFile.exists()) {
61-
DEBUG("Global file found: " << globalFile, INFO);
61+
DEBUG("Global file found: " << globalFile, VERBOSE);
6262
config.load(globalFile);
6363
}
6464

65-
DEBUG("Project file found: " << projectFile, INFO);
65+
DEBUG("Project file found: " << projectFile, VERBOSE);
6666
config.load(projectFile);
6767

6868
Config params;

src/std.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ inline set<T> operator +(set<T> a, const set<T> &b) {
130130

131131
// Convert to number.
132132
template <class T>
133-
T to(const String &s) {
133+
T to(const String &s, const T &def = T()) {
134134
std::istringstream ss(s);
135-
T t = T();
135+
T t = def;
136136
ss >> t;
137137
return t;
138138
}
@@ -271,16 +271,21 @@ class SetBanner : NoCopy {
271271
// Debug level.
272272
enum {
273273
dbg_QUIET = 0,
274-
dbg_NORMAL = 1,
275-
dbg_INFO = 2,
276-
dbg_VERBOSE = 3,
277-
dbg_DEBUG = 4,
274+
dbg_NORMAL,
275+
dbg_PEDANTIC,
276+
dbg_INFO,
277+
dbg_VERBOSE,
278+
dbg_DEBUG,
278279
};
279280

280281
#define DEBUG(x, level) \
281282
do { \
282283
if (debugLevel >= dbg_ ## level) { \
283-
PLN(x); \
284+
if (dbg_ ## level > dbg_NORMAL) { \
285+
PLN(#level ": " << x); \
286+
} else { \
287+
PLN(x); \
288+
} \
284289
} \
285290
} while (false)
286291

todo.org

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
* Things to do
2+
3+
Make sure we process all input from a process that has died. Currently, if a process prints
4+
lots of things to stdout and then crashes, sometimes we do not get all of it through mymake.
5+
This may be either because mymake exits, or because mymake decides the process is dead and do
6+
not need more output.
27

38
Move constants used with Config into string constants somewhere.
49

0 commit comments

Comments
 (0)