mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 17:11:44 +03:00
Change behavior when invoking LDC/LDMD without source files
Only display the appropriate usage help (and then fail) if invoked without any explicit cmdline options. Otherwise emit an error about missing source files and fail immediately, without displaying the usage help. Besides making LDC and LDMD behave identically in this regard, it makes just more sense IMO (when forgetting to specify a file, LDC previously just printed the cmdline help without any error message). It also makes `ldmd2 -transition=?` and `ldmd2 -preview=help` etc. print the expected help without LDMD special cases.
This commit is contained in:
parent
12d6193b9a
commit
6765e51799
3 changed files with 14 additions and 28 deletions
|
@ -66,7 +66,6 @@ version (IN_LLVM)
|
|||
|
||||
// in driver/main.cpp
|
||||
void registerPredefinedVersions();
|
||||
void printLDCUsage();
|
||||
void codegenModules(ref Modules modules);
|
||||
// in driver/archiver.cpp
|
||||
int createStaticLibrary();
|
||||
|
@ -379,7 +378,7 @@ version (IN_LLVM) {} else
|
|||
}
|
||||
version (IN_LLVM)
|
||||
{
|
||||
printLDCUsage();
|
||||
error(Loc.initial, "No source files");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -371,7 +371,6 @@ void translateArgs(size_t originalArgc, char **originalArgv,
|
|||
ldcArgs.push_back("-ldmd");
|
||||
|
||||
bool vdmd = false;
|
||||
bool noFiles = true;
|
||||
bool pic = false; // -fPIC already encountered?
|
||||
|
||||
for (size_t i = 1; i < args.size(); i++) {
|
||||
|
@ -529,13 +528,9 @@ void translateArgs(size_t originalArgc, char **originalArgv,
|
|||
}
|
||||
}
|
||||
/* -extern-std
|
||||
*/
|
||||
else if (strcmp(p + 1, "transition=?") == 0) {
|
||||
const char *transitionargs[] = {ldcPath.c_str(), p, nullptr};
|
||||
execute(ldcPath, transitionargs);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
/* -transition=<id>
|
||||
* -transition
|
||||
* -preview
|
||||
* -revert
|
||||
* -w
|
||||
* -wi
|
||||
* -O
|
||||
|
@ -656,11 +651,9 @@ void translateArgs(size_t originalArgc, char **originalArgv,
|
|||
exit(EXIT_SUCCESS);
|
||||
} else if (strcmp(p + 1, "run") == 0) {
|
||||
ldcArgs.insert(ldcArgs.end(), args.begin() + i, args.end());
|
||||
noFiles = (i == args.size() - 1);
|
||||
break;
|
||||
} else if (p[1] == '\0') {
|
||||
ldcArgs.push_back("-");
|
||||
noFiles = false;
|
||||
} else if (p[1] == 'C') {
|
||||
ldcArgs.push_back(concat("-", p + 2));
|
||||
} else {
|
||||
|
@ -686,21 +679,9 @@ void translateArgs(size_t originalArgc, char **originalArgv,
|
|||
}
|
||||
#endif
|
||||
ldcArgs.push_back(p);
|
||||
noFiles = false;
|
||||
}
|
||||
}
|
||||
|
||||
// at least one file is mandatory, except when `-Xi=…` is used
|
||||
if (noFiles && std::find_if(args.begin(), args.end(), [](const char *arg) {
|
||||
return startsWith(arg, "-Xi=");
|
||||
}) == args.end()) {
|
||||
printUsage(originalArgv[0], ldcPath);
|
||||
if (originalArgc == 1)
|
||||
exit(EXIT_FAILURE); // compatible with DMD
|
||||
else
|
||||
error("No source file specified.");
|
||||
}
|
||||
|
||||
if (vdmd) {
|
||||
printf(" -- Invoking:");
|
||||
for (const auto &arg : ldcArgs) {
|
||||
|
@ -762,6 +743,11 @@ int cppmain(int argc, char **argv) {
|
|||
error("Could not locate " LDC_EXE_NAME " executable.");
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
printUsage(argv[0], ldcPath);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// We need to manually set up argv[0] and the terminating NULL.
|
||||
std::vector<const char *> args;
|
||||
args.push_back(ldcPath.c_str());
|
||||
|
|
|
@ -896,6 +896,11 @@ int cppmain(int argc, char **argv) {
|
|||
Strings files;
|
||||
parseCommandLine(argc, argv, files);
|
||||
|
||||
if (argc == 1) {
|
||||
cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (global.errors) {
|
||||
fatal();
|
||||
}
|
||||
|
@ -977,10 +982,6 @@ int cppmain(int argc, char **argv) {
|
|||
return mars_mainBody(global.params, files, libmodules);
|
||||
}
|
||||
|
||||
void printLDCUsage() {
|
||||
cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
|
||||
}
|
||||
|
||||
void codegenModules(Modules &modules) {
|
||||
// Generate one or more object/IR/bitcode files/dcompute kernels.
|
||||
if (global.params.obj && !modules.empty()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue