aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Harrison <adamdharrison@gmail.com>2022-12-27 23:37:30 -0500
committerAdam Harrison <adamdharrison@gmail.com>2022-12-27 23:37:30 -0500
commit966e02a42546949170a1deb5e38dc93b63fdf6fb (patch)
tree17b2d74611cd6ebb37af43585e4a8bc6c7455172
parent37e00da1c6714346487eb1a0ec21afe704f712ef (diff)
downloadlite-xl-plugin-manager-966e02a42546949170a1deb5e38dc93b63fdf6fb.tar.gz
lite-xl-plugin-manager-966e02a42546949170a1deb5e38dc93b63fdf6fb.zip
Added in "post" key.
-rw-r--r--SPEC.md3
-rwxr-xr-xbuild.sh2
-rw-r--r--src/lpm.c15
-rw-r--r--src/lpm.lua20
4 files changed, 36 insertions, 4 deletions
diff --git a/SPEC.md b/SPEC.md
index 70f7531..6795078 100644
--- a/SPEC.md
+++ b/SPEC.md
@@ -149,7 +149,8 @@ that any version greater than `0.1` can be used.
"version": "1.0",
"mod_version": 3,
"remote": "https://github.com/anthonyaxenov/lite-xl-ignore-syntax:2ed993ed4376e1840b0824d7619f2d3447891d3aa234459378fcf9387c4e4680", # The remote to be used for this plugin.
- "name": "language_ignore"
+ "name": "language_ignore",
+ "post": {"x86-linux":"cp language_ignore.lua /tmp/somewhere-else", "x86-windows":"COPY language_ignore.lua C:\\Users\\Someone\\ignore.lua"} # Post download steps to run to fully set up the plugin. Does not run by default, requires --post.
},
{
"description": "Provides a GUI to manage core and plugin settings, bindings and select color theme. Depends on widget.",
diff --git a/build.sh b/build.sh
index 2c7b497..64eca82 100755
--- a/build.sh
+++ b/build.sh
@@ -17,7 +17,7 @@ CMAKE_DEFAULT_FLAGS=" $CMAKE_DEFAULT_FLAGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_PR
mkdir -p lib/prefix/include lib/prefix/lib
if [[ "$@" != *"-lz"* ]]; then
[ ! -e "lib/zlib" ] && echo "Make sure you've cloned submodules. (git submodule update --init --depth=1)" && exit -1
- [[ ! -e "lib/zlib/build" && $OSTYPE != 'msys'* ]] && cd lib/zlib && mkdir build && cd build && $CC -I.. ../*.c -c && ar rc libz.a *.o && cp libz.a ../../prefix/lib && cp ../*.h ../../prefix/include && cd ../../../
+ [[ ! -e "lib/zlib/build" && $OSTYPE != 'msys'* ]] && cd lib/zlib && mkdir build && cd build && $CC -D_LARGEFILE64_SOURCE -I.. ../*.c -c && ar rc libz.a *.o && cp libz.a ../../prefix/lib && cp ../*.h ../../prefix/include && cd ../../../
LDFLAGS="$LDFLAGS -l:libz.a"
fi
if [[ "$@" != *"-lmbedtls"* && "$@" != *"-lmbedcrypto"* ]]; then
diff --git a/src/lpm.c b/src/lpm.c
index 076f5ef..79549bf 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -788,6 +788,19 @@ static int lpm_get(lua_State* L) {
return 2;
}
+static int lpm_chdir(lua_State* L) {
+ if (chdir(luaL_checkstring(L, 1)))
+ return luaL_error(L, "error chdiring: %s", strerror(errno));
+ return 0;
+}
+
+static int lpm_pwd(lua_State* L) {
+ char buffer[MAX_PATH];
+ if (!getcwd(buffer, sizeof(buffer)))
+ return luaL_error(L, "error getcwd: %s", strerror(errno));
+ lua_pushstring(L, buffer);
+ return 1;
+}
static const luaL_Reg system_lib[] = {
{ "ls", lpm_ls }, // Returns an array of files.
@@ -803,6 +816,8 @@ static const luaL_Reg system_lib[] = {
{ "get", lpm_get }, // HTTP(s) GET request.
{ "extract", lpm_extract }, // Extracts .tar.gz, and .zip files.
{ "certs", lpm_certs }, // Sets the SSL certificate chain folder/file.
+ { "chdir", lpm_chdir }, // Changes directory. Only use for --post actions.
+ { "pwd", lpm_pwd }, // Gets existing directory. Only use for --post actions.
{ NULL, NULL }
};
diff --git a/src/lpm.lua b/src/lpm.lua
index a9db970..3d4e849 100644
--- a/src/lpm.lua
+++ b/src/lpm.lua
@@ -443,8 +443,15 @@ function common.reset(path, ref, type)
if not pcall(system.reset, path, "refs/tags/" .. ref, type) then system.reset(path, "refs/remotes/origin/" .. ref, type) end
end
end
+function common.chdir(dir, callback)
+ local wd = system.pwd()
+ system.chdir(dir)
+ local status, err = pcall(callback)
+ system.chdir(wd)
+ if not status then error(err)
+end
-local HOME, USERDIR, CACHEDIR, JSON, VERBOSE, MOD_VERSION, QUIET, FORCE, AUTO_PULL_REMOTES, ARCH, ASSUME_YES, NO_INSTALL_OPTIONAL, TMPDIR, DATADIR, BINARY, repositories, lite_xls, system_bottle
+local HOME, USERDIR, CACHEDIR, JSON, VERBOSE, MOD_VERSION, QUIET, FORCE, AUTO_PULL_REMOTES, ARCH, ASSUME_YES, NO_INSTALL_OPTIONAL, TMPDIR, DATADIR, BINARY, POST, repositories, lite_xls, system_bottle
local Plugin, Repository, LiteXL, Bottle = {}, {}, {}, {}
@@ -691,6 +698,13 @@ function Plugin:install(bottle, installing)
common.rmrf(temporary_install_path)
error(err)
else
+ if POST and self.post then
+ common.chdir(temporary_install_path, function()
+ if type(self.post) == "table" and not self.post[ARCH] then error("can't find post command for arch " .. ARCH) end
+ local code = os.system(type(self.post) == "table" and self.post[ARCH] or self.post) ~= 0
+ if code ~= 0 then error("post step failed with error code " .. code) end
+ end)
+ end
common.rmrf(install_path)
common.mkdirp(common.dirname(install_path))
common.rename(temporary_install_path, install_path)
@@ -1514,7 +1528,7 @@ Usage: lpm COMMAND [...ARGUMENTS] [--json] [--userdir=directory]
[--cachedir=directory] [--quiet] [--version] [--help] [--remotes]
[--ssl_certs=directory/file] [--force] [--arch=]] .. _G.ARCH .. [[]
[--assume-yes] [--no-install-optional] [--verbose] [--mod-version=3]
- [--datadir=directory] [--binary=path]
+ [--datadir=directory] [--binary=path] [--post]
LPM is a package manager for `lite-xl`, written in C (and packed-in lua).
@@ -1604,6 +1618,7 @@ Flags have the following effects:
to all.
--no-install-optional On install, anything marked as optional
won't prompt.
+ --post Run post-install build steps. Must be explicitly enabled.
]]
)
return 0
@@ -1613,6 +1628,7 @@ Flags have the following effects:
JSON = ARGS["json"] or os.getenv("LPM_JSON")
QUIET = ARGS["quiet"] or os.getenv("LPM_QUIET")
FORCE = ARGS["force"]
+ POST = ARGS["post"]
DATADIR = common.normalize_path(ARGS["datadir"])
BINARY = common.normalize_path(ARGS["binary"])
NO_INSTALL_OPTIONAL = ARGS["no-install-optional"]