Skip to content

Commit

Permalink
Address #19 Support passing DESTDIR to bootstrap script.
Browse files Browse the repository at this point in the history
Should make JPM installation a bit better. JPM itself can also use
--dest-dir=... to add a prefix to all installed files for bootstrapping
purposes.
  • Loading branch information
bakpakin committed Sep 16, 2021
1 parent 1f48226 commit cd6a30f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
12 changes: 9 additions & 3 deletions bootstrap.janet
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# for installation and then install jpm

(import ./jpm/config)
(import ./jpm/shutil)

(def hostos (os/which))
(def iswin (= :windows hostos))
Expand All @@ -16,14 +17,18 @@
(def libpath (os/getenv "JANET_LIBPATH" (if-not iswin (string prefix "/lib"))))
(def fix-modpath (os/getenv "JANET_STRICT_MODPATH"))
(def modpath (os/getenv "JANET_MODPATH" (if (and (not iswin) fix-modpath) (string prefix "/lib/janet"))))
(def destdir (os/getenv "DESTDIR"))

(defn do-bootstrap
[conf]
(let [mp (or modpath (dyn :syspath))]
(os/mkdir mp)
(os/mkdir (string mp "/.manifests")))
(shutil/create-dirs (string (or destdir "") mp "/.manifests"))
(when manpath (shutil/create-dirs (string (or destdir "") manpath)))
(when binpath (shutil/create-dirs (string (or destdir "") binpath)))
(when libpath (shutil/create-dirs (string (or destdir "") libpath)))
(when headerpath (shutil/create-dirs (string (or destdir "") headerpath))))
(print "Running jpm to self install...")
(os/execute [(dyn :executable) "jpm/cli.janet" "install"]
(os/execute [(dyn :executable) "jpm/cli.janet" "install" ;(if destdir [(string "--dest-dir=" destdir)] [])]
:epx
(merge-into (os/environ)
{"JPM_BOOTSTRAP_CONFIG" conf
Expand All @@ -34,6 +39,7 @@
(os/exit 1))

(print)
(print "destdir: " destdir)
(print "Using install prefix: " prefix)
(print "binpath: " binpath)
(print "libpath: " libpath)
Expand Down
1 change: 1 addition & 0 deletions jpm/config.janet
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,4 @@
(defdyn :test :boolean "Enable testing when installing.")
(defdyn :local :boolean "Switch to use a local tree ./jpm_tree instead of the config specified tree.")
(defdyn :tree :string-opt "Switch to use a custom tree instead of the config specified tree.")
(defdyn :dest-dir :string-opt "Prefix to add to installed files. Useful for bootstrapping.")
22 changes: 13 additions & 9 deletions jpm/declare.janet
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
(def name (last (peg/match path-splitter src)))
(def path (string destdir "/" name))
(array/push (dyn :installed-files) path)
(def dir (string (dyn :dest-dir "") destdir))
(task "install" []
(os/mkdir destdir)
(copy src destdir)))
(os/mkdir dir)
(copy src dir)))

(defn install-file-rule
"Add install and uninstall rule for moving file from src into destdir."
[src dest]
(array/push (dyn :installed-files) dest)
(def dest1 (string (dyn :dest-dir "") dest))
(task "install" []
(copyfile src dest)))
(copyfile src dest1)))

(defn uninstall
"Uninstall bundle named name"
Expand All @@ -31,8 +33,9 @@
(when-with [f (file/open manifest)]
(def man (parse (:read f :all)))
(each path (get man :paths [])
(print "removing " path)
(rm path))
(def path1 (string (dyn :dest-dir "") path))
(print "removing " path1)
(rm path1))
(print "removing manifest " manifest)
(:close f) # I hate windows
(rm manifest)
Expand Down Expand Up @@ -211,9 +214,10 @@
(string (if auto-shebang
(string "#!" (dyn:binpath) "/janet\n"))
first-line (if hardcode second-line) rest)))
(create-dirs path)
(spit path contents)
(unless (= :windows (os/which)) (shell "chmod" "+x" path))))
(def destpath (string (dyn :dest-dir "") path))
(create-dirs destpath)
(spit destpath contents)
(unless (= :windows (os/which)) (shell "chmod" "+x" destpath))))
(install-rule main binpath))
# Create a dud batch file when on windows.
(when (dyn:use-batch-shell)
Expand All @@ -223,7 +227,7 @@
(def newname (string binpath "/" name ".bat"))
(array/push (dyn :installed-files) newname)
(task "install" []
(spit newname bat))))
(spit (string (dyn :dest-dir "") newname) bat))))

(defn declare-archive
"Build a janet archive. This is a file that bundles together many janet
Expand Down
4 changes: 2 additions & 2 deletions jpm/shutil.janet
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"Get the path to the directory containing manifests for installed
packages."
[]
(string (dyn:modpath) "/.manifests"))
(string (dyn :dest-dir "") (dyn:modpath) "/.manifests"))

(defn find-manifest
"Get the full path of a manifest file given a package name."
Expand All @@ -25,7 +25,7 @@
"Return the path to the global cache."
[]
(def path (dyn:modpath))
(string path "/.cache"))
(string (dyn :dest-dir "") path "/.cache"))

(defn rm
"Remove a directory and all sub directories."
Expand Down

0 comments on commit cd6a30f

Please sign in to comment.