Repository navigation
Improve locating runtime #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |
| * | ||
| */ | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include <QCoreApplication> | ||
| #include <QString> | ||
| #include <QStringList> | ||
|
|
@@ -37,6 +39,42 @@ using namespace Qt::Literals::StringLiterals; | |
|
|
||
| namespace AppImageBuilder { | ||
|
|
||
| namespace { | ||
|
|
||
| // Returns the paths where the bundled AppImage runtime is looked for, in order of preference. | ||
| // Inside an AppImage the executable is started through the bundled dynamic loader, and applicationDirPath() then returns the directory of the loader instead of the executable. | ||
| // The loader can be in either lib64 or usr/lib64, so also look relative to the executable path from argv[0], which the dynamic loader sets to the path of the executable. | ||
| QStringList RuntimeFileCandidates(const QString &arch) { | ||
|
|
||
| const QString runtime_filename = "runtime-"_L1 + arch; | ||
|
|
||
| QStringList runtime_dirs; | ||
| const QStringList arguments = QCoreApplication::arguments(); | ||
| if (!arguments.isEmpty() && arguments.first().contains(u'/')) { | ||
| const QString executable_dir = QFileInfo(arguments.first()).absolutePath(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Resolve the executable symlink before searching for the bundled runtime. If 🤖 Prompt for AI Agents |
||
| runtime_dirs << executable_dir + "/../share/AppImageKit/runtime"_L1 | ||
| << executable_dir | ||
| << executable_dir + "/../lib64"_L1 | ||
| << executable_dir + "/../../lib64"_L1; | ||
| } | ||
| const QString application_dir = QCoreApplication::applicationDirPath(); | ||
| runtime_dirs << application_dir + "/../share/AppImageKit/runtime"_L1 | ||
| << application_dir; | ||
|
|
||
| QStringList runtime_files; | ||
| for (const QString &runtime_dir : std::as_const(runtime_dirs)) { | ||
| const QString runtime_file = QDir::cleanPath(runtime_dir + u'/' + runtime_filename); | ||
| if (!runtime_files.contains(runtime_file)) { | ||
| runtime_files << runtime_file; | ||
| } | ||
| } | ||
|
|
||
| return runtime_files; | ||
|
|
||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| bool Build(const QString &app_dir_path, const Options &options, QString &output_path, QString &error_message) { | ||
|
|
||
| if (!QFileInfo::exists(app_dir_path)) { | ||
|
|
@@ -177,12 +215,20 @@ bool Build(const QString &app_dir_path, const Options &options, QString &output_ | |
|
|
||
| QString runtime_file = options.runtime_file; | ||
| if (runtime_file.isEmpty()) { | ||
| QString runtime_dir = QDir::cleanPath(QCoreApplication::applicationDirPath() + "/../share/AppImageKit/runtime/"_L1); | ||
| if (!QDir(runtime_dir).exists()) runtime_dir = QCoreApplication::applicationDirPath(); | ||
| runtime_file = runtime_dir + "/runtime-"_L1 + arch; | ||
| const QStringList runtime_file_candidates = RuntimeFileCandidates(arch); | ||
| for (const QString &runtime_file_candidate : runtime_file_candidates) { | ||
| if (QFileInfo::exists(runtime_file_candidate)) { | ||
| runtime_file = runtime_file_candidate; | ||
| break; | ||
| } | ||
| } | ||
| if (runtime_file.isEmpty()) { | ||
| error_message = u"Cannot find runtime-%1, looked in:\n%2\nIt should have been bundled, but you can get it from https://github.com/AppImage/type2-runtime/releases/tag/continuous and pass it with --runtime-file"_s.arg(arch, runtime_file_candidates.join(u'\n')); | ||
| return false; | ||
| } | ||
| } | ||
| if (!QFileInfo::exists(runtime_file)) { | ||
| error_message = u"Cannot find %1. It should have been bundled, but you can get it from https://github.com/AppImage/type2-runtime/releases/tag/continuous"_s.arg(runtime_file); | ||
| else if (!QFileInfo::exists(runtime_file)) { | ||
| error_message = u"Runtime file %1 does not exist"_s.arg(runtime_file); | ||
| return false; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix the sort locale so loader selection stays reproducible.
When the AppImage contains multiple matches, different
LC_COLLATEsettings can change which pathhead -n 1selects. GNUsortuses the active locale’s collation sequence. (gnu.org) Set a fixed locale for this pipeline.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents