Skip to content

Commit

Permalink
Added in "post" key.
Browse files Browse the repository at this point in the history
  • Loading branch information
adamharrison committed Dec 28, 2022
1 parent 37e00da commit 966e02a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
3 changes: 2 additions & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/lpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 }
};

Expand Down
20 changes: 18 additions & 2 deletions src/lpm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}, {}, {}, {}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand All @@ -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"]
Expand Down

0 comments on commit 966e02a

Please sign in to comment.