code review comments

This commit is contained in:
Jude Taylor 2016-08-15 10:43:14 -07:00
parent 60f4b25d7d
commit adf0216d98

View file

@ -11,14 +11,11 @@
using namespace nix;
typedef std::map<string, std::set<string>> SetMap;
static auto cacheDir = Path{};
Path resolveCacheFile(const Path & lib) {
Path lib2 = Path(lib);
std::replace(lib2.begin(), lib2.end(), '/', '%');
return cacheDir + "/" + lib2;
Path resolveCacheFile(Path lib) {
std::replace(lib.begin(), lib.end(), '/', '%');
return cacheDir + "/" + lib;
}
std::set<string> readCacheFile(const Path & file) {
@ -34,7 +31,7 @@ void writeCacheFile(const Path & file, std::set<string> & deps) {
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;
fgetpos(obj_file, &pos);
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);
}
bool seek_mach64_blob(FILE *obj_file, enum NXByteOrder end) {
bool seekMach64Blob(FILE *obj_file, enum NXByteOrder end) {
struct fat_header head;
fread(&head, sizeof(struct fat_header), 1, obj_file);
swap_fat_header(&head, end);
@ -77,7 +74,7 @@ std::set<std::string> runResolver(const Path & filename) {
enum NXByteOrder endianness;
if(magic == 0xBEBAFECA) {
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;
return std::set<string>();
}
@ -91,13 +88,13 @@ std::set<std::string> runResolver(const Path & filename) {
std::set<string> libs;
for(uint32_t i = 0; i < header.ncmds; i++) {
struct load_command cmd;
fread(&cmd.cmd, sizeof(uint32_t), 1, obj_file);
fread(&cmd.cmdsize, sizeof(uint32_t), 1, obj_file);
fread(&cmd.cmd, sizeof(cmd.cmd), 1, obj_file);
fread(&cmd.cmdsize, sizeof(cmd.cmdsize), 1, obj_file);
switch(cmd.cmd) {
case LC_LOAD_DYLIB:
case LC_LOAD_UPWARD_DYLIB:
case LC_REEXPORT_DYLIB:
libs.insert(find_dylib_name(obj_file, cmd));
libs.insert(findDylibName(obj_file, cmd));
break;
}
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;
if(deps.find(path) != deps.end()) {
return std::set<string>();
@ -134,14 +131,14 @@ std::set<string> resolve_tree(const Path & path, PathSet & deps) {
deps.insert(path);
for (auto & lib : runResolver(path)) {
results.insert(lib);
for (auto & p : resolve_tree(lib, deps)) {
for (auto & p : resolveTree(lib, deps)) {
results.insert(p);
}
}
return results;
}
std::set<string> get_path(const Path & path) {
std::set<string> getPath(const Path & path) {
Path cacheFile = resolveCacheFile(path);
if(pathExists(cacheFile)) {
return readCacheFile(cacheFile);
@ -157,7 +154,7 @@ std::set<string> get_path(const Path & path) {
paths.insert(next_path);
}
for(auto & t : resolve_tree(next_path, deps)) {
for(auto & t : resolveTree(next_path, deps)) {
paths.insert(t);
}
@ -188,7 +185,7 @@ int main(int argc, char ** argv) {
std::set<string> all_paths;
for (auto & path : impurePaths) {
for(auto & p : get_path(path)) {
for(auto & p : getPath(path)) {
all_paths.insert(p);
}
}