Skip to content

Commit 840997c

Browse files
committed
Initial commit
0 parents  commit 840997c

10 files changed

+453
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*build*/
2+
.idea/

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/args"]
2+
path = lib/args
3+
url = https://github.com/Taywee/args.git

CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
project(linuxdeploy-plugin-appimage)
3+
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
add_subdirectory(lib)
8+
9+
add_subdirectory(src)

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# linuxdeploy-plugin-appimage
2+
3+
Creates AppImages from AppDirs. For use with
4+
[linuxdeploy](https://github.com/TheAssassin/linuxdeploy).
5+
6+
***More info will follow soon!***
7+
8+

lib/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(args EXCLUDE_FROM_ALL)

lib/args

Submodule args added at bd0429e
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[Desktop Entry]
2+
Name=linuxdeploy-plugin-appimage
3+
Exec=linuxdeploy-plugin-appimage %f
4+
Icon=linuxdeploy-plugin-appimage
5+
Terminal=true
6+
Type=Application

resources/linuxdeploy-plugin-appimage.svg

+320
Loading

src/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# support for ccache
2+
# call CMake with -DUSE_CCACHE=OFF to explicitly disable it
3+
set(USE_CCACHE ON CACHE BOOL "Use CCache to speed up builds")
4+
if(USE_CCACHE)
5+
find_program(CCACHE ccache)
6+
if(CCACHE)
7+
message(STATUS "Using ccache")
8+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
9+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
10+
else()
11+
message(WARNING "USE_CCACHE set, but could not find ccache")
12+
endif()
13+
endif()
14+
15+
# main executable
16+
add_executable(linuxdeploy-plugin-appimage main.cpp)
17+
18+
target_link_libraries(linuxdeploy-plugin-appimage args)
19+
20+
install(
21+
TARGETS linuxdeploy-plugin-appimage
22+
RUNTIME DESTINATION bin
23+
)

src/main.cpp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// system includes
2+
#include <cstring>
3+
#include <iostream>
4+
#include <dirent.h>
5+
#include <libgen.h>
6+
#include <unistd.h>
7+
8+
// library includes
9+
#include <args.hxx>
10+
11+
bool isFile(const std::string& path) {
12+
return access(path.c_str(), F_OK) == 0;
13+
}
14+
15+
std::string findAppimagetool(const char* const argv0) {
16+
std::vector<char> argv0Buf(strlen(argv0) + 1);
17+
strcpy(argv0Buf.data(), argv0);
18+
19+
auto currentDirPath = std::string(dirname(argv0Buf.data()));
20+
21+
// search next to current binary
22+
std::vector<std::string> knownPaths = {
23+
currentDirPath + "/appimagetool",
24+
currentDirPath + "/appimagetool.AppImage",
25+
currentDirPath + "/appimagetool-x86_64.AppImage",
26+
};
27+
28+
std::stringstream ss;
29+
ss << getenv("PATH");
30+
31+
// also search in PATH
32+
std::string currentPath;
33+
while (std::getline(ss, currentPath, ':')) {
34+
knownPaths.push_back(currentPath + "/appimagetool");
35+
knownPaths.push_back(currentPath + "/appimagetool.AppImage");
36+
knownPaths.push_back(currentPath + "/appimagetool-x86_64.AppImage");
37+
}
38+
39+
for (const auto& path : knownPaths) {
40+
if (isFile(path))
41+
return path;
42+
}
43+
44+
throw std::runtime_error("Could not find appimagetool in PATH");
45+
}
46+
47+
int main(const int argc, const char* const* const argv) {
48+
args::ArgumentParser parser("linuxdeploy-plugin-appimage");
49+
50+
args::ValueFlag<std::string> appdir(parser, "AppDir", "AppDir to package as AppImage", {"appdir"});
51+
args::Flag pluginType(parser, "", "Return plugin type and exit", {"plugin-type"});
52+
53+
try {
54+
parser.ParseCLI(argc, argv);
55+
} catch (const args::UsageError&) {
56+
std::cout << parser;
57+
} catch (const args::ParseError& e) {
58+
std::cerr << "Failed to parse arguments: " << e.what() << std::endl << std::endl;
59+
std::cout << parser;
60+
return 1;
61+
}
62+
63+
if (!appdir) {
64+
std::cerr << "--appdir parameter required" << std::endl << std::endl;
65+
std::cout << parser;
66+
return 1;
67+
}
68+
69+
if (pluginType) {
70+
std::cout << "output" << std::endl;
71+
return 0;
72+
}
73+
74+
auto pathToAppimagetool = findAppimagetool(argv[0]);
75+
76+
execl(pathToAppimagetool.c_str(), "appimagetool", appdir.Get().c_str(), nullptr);
77+
78+
auto error = errno;
79+
std::cerr << "execl() failed: " << strerror(error) << std::endl;
80+
}

0 commit comments

Comments
 (0)