1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-18 19:29:56 +00:00

Add :hardcode-syspath option to declare-binscript.

This should make fully correct installs easier.
This commit is contained in:
Calvin Rose 2020-05-17 09:29:45 -05:00
parent 33b5d9651f
commit 8b98b331cc

24
jpm
View File

@ -870,11 +870,27 @@ int main(int argc, const char **argv) {
(defn declare-binscript
"Declare a janet file to be installed as an executable script. Creates
a shim on windows."
[&keys opts]
(def main (opts :main))
a shim on windows. If hardcode is true, will insert code into the script
such that it will run correctly even when JANET_PATH is changed."
[&keys {:main main :hardcode-syspath hardcode}]
(def binpath (dyn :binpath JANET_BINPATH))
(install-rule main binpath)
(if hardcode
(let [syspath (dyn :modpath JANET_MODPATH)]
(def parts (peg/match path-splitter main))
(def name (last parts))
(def path (string binpath sep name))
(array/push (dyn :installed-files) path)
(add-body "install"
(def contents
(with [f (file/open main)]
(def first-line (:read f :line))
(def second-line (string/format "(put root-env :syspath %v)\n" syspath))
(def rest (:read f :all))
(string first-line second-line rest)))
(create-dirs path)
(spit path contents)
(unless is-win (shell "chmod" "+x" path))))
(install-rule main binpath))
# Create a dud batch file when on windows.
(when is-win
(def name (last (peg/match path-splitter main)))