return list;
}
+static bool cmdOptionExists(char** begin, char** end, const std::string& option)
+{
+ return std::find(begin, end, option) != end;
+}
+
static void help(const char *argv0)
{
const char* helpDesc =
{
bool pkgMode = false;
bool dllMode = false;
- bool dirMode = false;
bool rmPkgMode = false;
- bool enableR2R = false;
- bool pkgDllMode = false;
- NiCommonOption option = {std::string(), std::string(), std::string()};
- if (initNICommon(&option) != NI_ERROR_NONE) {
- fprintf(stderr, "Fail to initialize NI Common\n");
+ if (initNICommon() != NI_ERROR_NONE) {
+ return -1;
+ }
+
+ NIOption* opt = getNIOption();
+ if (opt == nullptr) {
+ _SERR("Fail to create option structure.");
return -1;
}
- if (cmdOptionExists(argv, argv+argc, "--r2r")) {
- enableR2R = true;
+ // Parse optional switches first.
+ if (cmdOptionExists(argv, argv+argc, "--verbose")) {
+ opt->flags |= NI_FLAGS_VERBOSE;
}
+ // The following commands are mutually exclusive.
if (cmdOptionExists(argv, argv+argc, "--help")) {
help(argv[0]);
return 0;
} else if (cmdOptionExists(argv, argv+argc, "--system")) {
- createNiPlatform(enableR2R);
+ createNIPlatform("", opt->flags);
return 0;
} else if (cmdOptionExists(argv, argv+argc, "--dll")) {
dllMode = true;
} else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
pkgMode = true;
- } else if (cmdOptionExists(argv, argv+argc, "--dir")) {
- dirMode = true;
} else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
- removeNiPlatform();
+ removeNIPlatform();
return 0;
} else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
rmPkgMode = true;
} else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) {
- regenerateAppNI(enableR2R);
+ regenerateAppNI(opt->flags);
return 0;
- } else if (cmdOptionExists(argv, argv+argc, "--pkg-dll")) {
- pkgDllMode = true;
} else {
help(argv[0]);
return 0;
if (args.size() < 1) {
if (pkgMode)
- fprintf(stderr, "Package name is missed\n");
+ _SERR("Package name is missing.");
else if (dllMode)
- fprintf(stderr, "DLL path is missed\n");
+ _SERR("DLL path is missing.");
help(argv[0]);
- return 1;
+ return -1;
}
if (pkgMode) {
for (const std::string pkg : args) {
// if there is AOTed dlls under package root, that is skiped.
- int ret = createNiUnderPkgRoot(pkg, enableR2R);
+ int ret = createNIUnderPkgRoot(pkg, opt->flags);
if (ret == NI_ERROR_INVALID_PACKAGE) {
- fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
+ _SERR("Failed to get root path from [%s]", pkg.c_str());
return -1;
} else if (ret != NI_ERROR_NONE) {
- fprintf(stderr, "Failed to generate NI file [%s]\n", pkg.c_str());
+ _SERR("Failed to generate NI file [%s]", pkg.c_str());
return -1;
}
}
- } else if (pkgDllMode) {
- int ret = createNiDllUnderPkgRoot(args[0], args[1], enableR2R);
- if (ret == NI_ERROR_INVALID_PACKAGE) {
- fprintf(stderr, "Failed to get root path from [%s]\n", args[0].c_str());
- return -1;
- } else if (ret == NI_ERROR_ALREADY_EXIST) {
- // skip for already exist case
- return -1;
- } else if (ret != NI_ERROR_NONE) {
- fprintf(stderr, "Failed to generate NI file [%s]\n", args[1].c_str());
- return -1;
- }
} else if (rmPkgMode) {
for (const std::string pkg : args) {
- int ret = removeNiUnderPkgRoot(pkg);
+ int ret = removeNIUnderPkgRoot(pkg);
if (ret == NI_ERROR_INVALID_PACKAGE) {
- fprintf(stderr, "Failed to get root path from [%s]\n", pkg.c_str());
+ _SERR("Failed to get root path from [%s]", pkg.c_str());
return -1;
} else if (ret != NI_ERROR_NONE) {
- fprintf(stderr, "Failed to remove dlls for given package [%s]\n", pkg.c_str());
+ _SERR("Failed to remove dlls for given package [%s]", pkg.c_str());
return -1;
}
}
// donot return error code for generation failure.
// we have to run crossgen for all input dlls.
for (const std::string dll : args) {
- int ret = createNiDll(dll, enableR2R);
+ int ret = createNIDll(dll, opt->flags);
if (ret == NI_ERROR_ALREADY_EXIST) {
// skip for already exist case
} else if (ret != NI_ERROR_NONE) {
- fprintf(stderr, "Failed to generate NI file [%s]\n", dll.c_str());
+ _SERR("Failed to generate NI file [%s]", dll.c_str());
}
}
- } else if (dirMode) {
- createNiUnderDirs(args.data(), args.size(), enableR2R);
}
return 0;