}
}
+void removeNiUnderDirs(const char* rootPaths[], int count)
+{
+ auto convert = [](const char* path, const char* name) {
+ std::string ni;
+ if (isNativeImage(path)) {
+ remove(path);
+ }
+ };
+
+ for (int i = 0; i < count; i++)
+ scanFilesInDir(rootPaths[i], convert, -1);
+}
+
+void removeNiPlatform()
+{
+ std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll");
+ std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll");
+ std::string coreLibBackup = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll.Backup");
+
+ if (fileNotExist(coreLibBackup)) {
+ return;
+ }
+
+ if (remove(coreLib.c_str())) {
+ _ERR("Failed to remove System.Private.CoreLib native image file");
+ }
+
+ rename(coreLibBackup.c_str(), coreLib.c_str());
+
+ const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"};
+
+ removeNiUnderDirs(platformDirs, 3);
+}
+
void createNiPlatform()
{
createCoreLibNI();
createNiUnderDirs(rootPaths, count, nullptr);
}
+int removeNiUnderPkgRoot(const char* pkgName)
+{
+ std::string pkgRoot;
+ if (getRootPath(pkgName, pkgRoot) < 0)
+ return 1;
+
+ std::string binDir = concatPath(pkgRoot, "bin");
+ std::string libDir = concatPath(pkgRoot, "lib");
+ _INFO("bindir : %s", binDir.c_str());
+ _INFO("libdir : %s", libDir.c_str());
+
+ const char* paths[] = {
+ binDir.c_str(),
+ libDir.c_str()
+ };
+
+ removeNiUnderDirs(paths, 2);
+
+ return 0;
+}
+
+
int createNiUnderPkgRoot(const char* pkgName)
{
std::string pkgRoot;
" --system - Create NI under System DLLs\n"
" --dll - Create NI for DLL\n"
" --pkg - Create NI for package\n"
+ " --reset-system - Remove System NI files\n"
+ " --reset-pkg - Remove App NI files\n"
"\n"
"Example:\n"
"Create native image for dlls and exes under platform directories\n"
{
bool pkgMode = false;
bool dllMode = false;
+ bool rmPkgMode = false;
if (cmdOptionExists(argv, argv+argc, "--help")) {
help(argv[0]);
dllMode = true;
} else if (cmdOptionExists(argv, argv+argc, "--pkg")) {
pkgMode = true;
+ } else if (cmdOptionExists(argv, argv+argc, "--reset-system")) {
+ removeNiPlatform();
+ return 0;
+ } else if (cmdOptionExists(argv, argv+argc, "--reset-pkg")) {
+ rmPkgMode = true;
} else {
help(argv[0]);
return 1;
return 1;
}
}
+ } else if (rmPkgMode) {
+ for (const char* pkg : args) {
+ if (removeNiUnderPkgRoot(pkg) != 0) {
+ fprintf(stderr, "Failed to get root path from [%s]\n", pkg);
+ return 1;
+ }
+ }
} else if (dllMode) {
for (const char* dll : args)
createNiSelect(dll);