code review comments
This commit is contained in:
parent
60f4b25d7d
commit
adf0216d98
|
@ -11,14 +11,11 @@
|
||||||
|
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
typedef std::map<string, std::set<string>> SetMap;
|
|
||||||
|
|
||||||
static auto cacheDir = Path{};
|
static auto cacheDir = Path{};
|
||||||
|
|
||||||
Path resolveCacheFile(const Path & lib) {
|
Path resolveCacheFile(Path lib) {
|
||||||
Path lib2 = Path(lib);
|
std::replace(lib.begin(), lib.end(), '/', '%');
|
||||||
std::replace(lib2.begin(), lib2.end(), '/', '%');
|
return cacheDir + "/" + lib;
|
||||||
return cacheDir + "/" + lib2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<string> readCacheFile(const Path & file) {
|
std::set<string> readCacheFile(const Path & file) {
|
||||||
|
@ -34,7 +31,7 @@ void writeCacheFile(const Path & file, std::set<string> & deps) {
|
||||||
fp.close();
|
fp.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string find_dylib_name(FILE *obj_file, struct load_command cmd) {
|
std::string findDylibName(FILE *obj_file, struct load_command cmd) {
|
||||||
fpos_t pos;
|
fpos_t pos;
|
||||||
fgetpos(obj_file, &pos);
|
fgetpos(obj_file, &pos);
|
||||||
struct dylib_command dylc;
|
struct dylib_command dylc;
|
||||||
|
@ -53,7 +50,7 @@ std::string find_dylib_name(FILE *obj_file, struct load_command cmd) {
|
||||||
return std::string(dylib_name);
|
return std::string(dylib_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool seek_mach64_blob(FILE *obj_file, enum NXByteOrder end) {
|
bool seekMach64Blob(FILE *obj_file, enum NXByteOrder end) {
|
||||||
struct fat_header head;
|
struct fat_header head;
|
||||||
fread(&head, sizeof(struct fat_header), 1, obj_file);
|
fread(&head, sizeof(struct fat_header), 1, obj_file);
|
||||||
swap_fat_header(&head, end);
|
swap_fat_header(&head, end);
|
||||||
|
@ -77,7 +74,7 @@ std::set<std::string> runResolver(const Path & filename) {
|
||||||
enum NXByteOrder endianness;
|
enum NXByteOrder endianness;
|
||||||
if(magic == 0xBEBAFECA) {
|
if(magic == 0xBEBAFECA) {
|
||||||
endianness = NX_BigEndian;
|
endianness = NX_BigEndian;
|
||||||
if(!seek_mach64_blob(obj_file, endianness)) {
|
if(!seekMach64Blob(obj_file, endianness)) {
|
||||||
std::cerr << "Could not find any mach64 blobs in file " << filename << ", continuing..." << std::endl;
|
std::cerr << "Could not find any mach64 blobs in file " << filename << ", continuing..." << std::endl;
|
||||||
return std::set<string>();
|
return std::set<string>();
|
||||||
}
|
}
|
||||||
|
@ -91,13 +88,13 @@ std::set<std::string> runResolver(const Path & filename) {
|
||||||
std::set<string> libs;
|
std::set<string> libs;
|
||||||
for(uint32_t i = 0; i < header.ncmds; i++) {
|
for(uint32_t i = 0; i < header.ncmds; i++) {
|
||||||
struct load_command cmd;
|
struct load_command cmd;
|
||||||
fread(&cmd.cmd, sizeof(uint32_t), 1, obj_file);
|
fread(&cmd.cmd, sizeof(cmd.cmd), 1, obj_file);
|
||||||
fread(&cmd.cmdsize, sizeof(uint32_t), 1, obj_file);
|
fread(&cmd.cmdsize, sizeof(cmd.cmdsize), 1, obj_file);
|
||||||
switch(cmd.cmd) {
|
switch(cmd.cmd) {
|
||||||
case LC_LOAD_DYLIB:
|
case LC_LOAD_DYLIB:
|
||||||
case LC_LOAD_UPWARD_DYLIB:
|
case LC_LOAD_UPWARD_DYLIB:
|
||||||
case LC_REEXPORT_DYLIB:
|
case LC_REEXPORT_DYLIB:
|
||||||
libs.insert(find_dylib_name(obj_file, cmd));
|
libs.insert(findDylibName(obj_file, cmd));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fseek(obj_file, cmd.cmdsize - (sizeof(uint32_t) * 2), SEEK_CUR);
|
fseek(obj_file, cmd.cmdsize - (sizeof(uint32_t) * 2), SEEK_CUR);
|
||||||
|
@ -126,7 +123,7 @@ Path resolveSymlink(const Path & path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<string> resolve_tree(const Path & path, PathSet & deps) {
|
std::set<string> resolveTree(const Path & path, PathSet & deps) {
|
||||||
std::set<string> results;
|
std::set<string> results;
|
||||||
if(deps.find(path) != deps.end()) {
|
if(deps.find(path) != deps.end()) {
|
||||||
return std::set<string>();
|
return std::set<string>();
|
||||||
|
@ -134,14 +131,14 @@ std::set<string> resolve_tree(const Path & path, PathSet & deps) {
|
||||||
deps.insert(path);
|
deps.insert(path);
|
||||||
for (auto & lib : runResolver(path)) {
|
for (auto & lib : runResolver(path)) {
|
||||||
results.insert(lib);
|
results.insert(lib);
|
||||||
for (auto & p : resolve_tree(lib, deps)) {
|
for (auto & p : resolveTree(lib, deps)) {
|
||||||
results.insert(p);
|
results.insert(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::set<string> get_path(const Path & path) {
|
std::set<string> getPath(const Path & path) {
|
||||||
Path cacheFile = resolveCacheFile(path);
|
Path cacheFile = resolveCacheFile(path);
|
||||||
if(pathExists(cacheFile)) {
|
if(pathExists(cacheFile)) {
|
||||||
return readCacheFile(cacheFile);
|
return readCacheFile(cacheFile);
|
||||||
|
@ -157,7 +154,7 @@ std::set<string> get_path(const Path & path) {
|
||||||
paths.insert(next_path);
|
paths.insert(next_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto & t : resolve_tree(next_path, deps)) {
|
for(auto & t : resolveTree(next_path, deps)) {
|
||||||
paths.insert(t);
|
paths.insert(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +185,7 @@ int main(int argc, char ** argv) {
|
||||||
std::set<string> all_paths;
|
std::set<string> all_paths;
|
||||||
|
|
||||||
for (auto & path : impurePaths) {
|
for (auto & path : impurePaths) {
|
||||||
for(auto & p : get_path(path)) {
|
for(auto & p : getPath(path)) {
|
||||||
all_paths.insert(p);
|
all_paths.insert(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue