From f20af7dc671e7a76a9808d1bb369f74afc8201a6 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Sun, 22 Sep 2019 18:58:21 +0200 Subject: [PATCH] Refactor and improve relative directory calculation Also makes variable names less ambiguous and adds some documenting comments. --- src/core/appdir.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/core/appdir.cpp b/src/core/appdir.cpp index 3f6a4cd..106db9e 100644 --- a/src/core/appdir.cpp +++ b/src/core/appdir.cpp @@ -311,6 +311,12 @@ namespace linuxdeploy { return stripPath; } + static std::string calculateRelativeRPath(const bf::path& originDir, const bf::path& dependencyLibrariesDir) { + auto relPath = bf::relative(bf::absolute(dependencyLibrariesDir), bf::absolute(originDir)); + std::string rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN"; + return rpath; + } + bool deployLibrary(const bf::path& path, bool forceDeploy = false, bool deployDependencies = true, const bf::path& destination = bf::path()) { if (!forceDeploy && hasBeenVisitedAlready(path)) { ldLog() << LD_DEBUG << "File has been visited already:" << path << std::endl; @@ -375,19 +381,20 @@ namespace linuxdeploy { std::string rpath = "$ORIGIN"; if (!destination.empty()) { - std::string rpathDestination = destination.string(); + // destination is the place where to deploy this file + // therefore, rpathDestination means + std::string rpathOriginDir = destination.string(); if (destination.string().back() == '/') { - rpathDestination = destination.string(); + rpathOriginDir = destination.string(); - while (rpathDestination.back() == '/') - rpathDestination.erase(rpathDestination.end() - 1, rpathDestination.end()); + while (rpathOriginDir.back() == '/') + rpathOriginDir.erase(rpathOriginDir.end() - 1, rpathOriginDir.end()); } else { - rpathDestination = destination.parent_path().string(); + rpathOriginDir = destination.parent_path().string(); } - auto relPath = bf::relative(bf::absolute(libraryDir), bf::absolute(rpathDestination)); - rpath = "$ORIGIN/" + relPath.string() + ":$ORIGIN"; + rpath = calculateRelativeRPath(rpathOriginDir, libraryDir); } // no need to set rpath in debug symbols files @@ -400,7 +407,7 @@ namespace linuxdeploy { if (!deployDependencies) return true; - + return deployElfDependencies(path); }