Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 557bad2

Browse filesBrowse files
committed
Add --deploy-deps-only
1 parent 590a746 commit 557bad2
Copy full SHA for 557bad2

3 files changed

+92Lines changed: 92 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎include/linuxdeploy/core/appdir.h‎

Copy file name to clipboardExpand all lines: include/linuxdeploy/core/appdir.h
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ namespace linuxdeploy {
5757
// deploy executable
5858
bool deployExecutable(const boost::filesystem::path& path, const boost::filesystem::path& destination = "");
5959

60+
// deploy dependencies for ELF file in AppDir, without copying it into the library dir
61+
//
62+
// the dependencies end up in the regular location
63+
bool deployDependenciesOnlyForElfFile(const boost::filesystem::path& elfFilePath, bool failSilentForNonElfFile = false);
64+
6065
// deploy desktop file
6166
bool deployDesktopFile(const desktopfile::DesktopFile& desktopFile);
6267

Collapse file

‎src/core/appdir.cpp‎

Copy file name to clipboardExpand all lines: src/core/appdir.cpp
+55Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,61 @@ namespace linuxdeploy {
830830
return true;
831831
}
832832

833+
// TODO: quite similar to deployDependenciesForExistingFiles... maybe they should be merged or use each other
834+
bool AppDir::deployDependenciesOnlyForElfFile(const boost::filesystem::path& elfFilePath, bool failSilentForNonElfFile) {
835+
// preconditions: file must be an ELF one, and file must be contained in the AppDir
836+
const auto absoluteElfFilePath = bf::absolute(elfFilePath);
837+
838+
// can't bundle directories
839+
if (!bf::is_regular_file(absoluteElfFilePath)) {
840+
ldLog() << LD_DEBUG << "Skipping non-file directory entry:" << absoluteElfFilePath << std::endl;
841+
return false;
842+
}
843+
844+
// to do a proper prefix check, we need a proper absolute path for the AppDir
845+
const auto absoluteAppDirPath = bf::absolute(this->path());
846+
ldLog() << LD_DEBUG << "absolute AppDir path:" << absoluteAppDirPath << std::endl;
847+
848+
// a fancy way to check STL strings for prefixes is to "ab"use rfind
849+
if (absoluteElfFilePath.string().rfind(absoluteAppDirPath.string()) != 0) {
850+
ldLog() << LD_ERROR << "File" << absoluteElfFilePath << "is not contained in AppDir, its dependencies cannot be deployed into the AppDir" << std::endl;
851+
return false;
852+
}
853+
854+
// make sure we have an ELF file
855+
try {
856+
elf::ElfFile(absoluteElfFilePath.string());
857+
} catch (const elf::ElfFileParseError& e) {
858+
auto level = LD_ERROR;
859+
860+
if (failSilentForNonElfFile) {
861+
level = LD_WARNING;
862+
}
863+
864+
ldLog() << level << "Not an ELF file:" << absoluteElfFilePath << std::endl;
865+
866+
return failSilentForNonElfFile;
867+
}
868+
869+
// relative path makes for a nicer and more consistent log
870+
ldLog() << "Deploying dependencies for ELF file in AppDir:" << elfFilePath << std::endl;
871+
872+
// bundle dependencies
873+
if (!d->deployElfDependencies(absoluteElfFilePath))
874+
return false;
875+
876+
// set rpath correctly
877+
const auto rpathDestination = this->path() / "usr/lib";
878+
ldLog() << LD_DEBUG << "rpath destination:" << rpathDestination << std::endl;
879+
880+
const auto rpath = PrivateData::calculateRelativeRPath(elfFilePath.parent_path(), rpathDestination);
881+
ldLog() << LD_DEBUG << "Calculated rpath:" << rpath << std::endl;
882+
883+
d->setElfRPathOperations[absoluteElfFilePath] = rpath;
884+
885+
return true;
886+
}
887+
833888
void AppDir::setDisableCopyrightFilesDeployment(bool disable) {
834889
d->disableCopyrightFilesDeployment = disable;
835890
}
Collapse file

‎src/main.cpp‎

Copy file name to clipboardExpand all lines: src/main.cpp
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ int main(int argc, char** argv) {
3636

3737
args::ValueFlagList<std::string> executablePaths(parser, "executable", "Executable to deploy", {'e', "executable"});
3838

39+
args::ValueFlagList<std::string> deployDepsOnlyPaths(parser, "path", "Path to ELF file or directory containing such files (libraries or executables) in the AppDir whose dependencies shall be deployed by linuxdeploy without copying them into the AppDir", {"deploy-deps-only"});
40+
3941
args::ValueFlagList<std::string> desktopFilePaths(parser, "desktop file", "Desktop file to deploy", {'d', "desktop-file"});
4042
args::Flag createDesktopFile(parser, "", "Create basic desktop file that is good enough for some tests", {"create-desktop-file"});
4143

@@ -147,6 +149,36 @@ int main(int argc, char** argv) {
147149
}
148150
}
149151

152+
// deploy executables to usr/bin, and deploy their dependencies to usr/lib
153+
if (deployDepsOnlyPaths) {
154+
ldLog() << std::endl << "-- Deploying dependencies only for ELF files --" << std::endl;
155+
156+
for (const auto& path : deployDepsOnlyPaths.Get()) {
157+
if (bf::is_directory(path)) {
158+
ldLog() << "Deploying files in directory" << path << std::endl;
159+
160+
for (auto it = bf::directory_iterator{path}; it != bf::directory_iterator{}; ++it) {
161+
if (!bf::is_regular_file(*it)) {
162+
continue;
163+
}
164+
165+
if (!appDir.deployDependenciesOnlyForElfFile(*it, true)) {
166+
ldLog() << LD_WARNING << "Failed to deploy dependencies for ELF file" << *it << LD_NO_SPACE << ", skipping" << std::endl;
167+
return 1;
168+
}
169+
}
170+
} else if (bf::is_regular_file(path)) {
171+
if (!appDir.deployDependenciesOnlyForElfFile(path)) {
172+
ldLog() << LD_ERROR << "Failed to deploy dependencies for ELF file: " << path << std::endl;
173+
return 1;
174+
}
175+
} else {
176+
ldLog() << LD_ERROR << "No such file or directory: " << path << std::endl;
177+
return 1;
178+
}
179+
}
180+
}
181+
150182
// perform deferred copy operations before running input plugins to make sure all files the plugins might expect
151183
// are in place
152184
ldLog() << std::endl << "-- Copying files into AppDir --" << std::endl;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.