1
0
mirror of https://github.com/janet-lang/janet synced 2025-02-24 04:00:02 +00:00

Get lockfile info from manifest, not cache.

Make manifest files track more information.
Use jdn to store manifest files, as well as repo url and
sha.
This commit is contained in:
Calvin Rose 2020-03-25 20:55:04 -05:00
parent e380c01dd1
commit b8c1c1c144

View File

@ -551,6 +551,15 @@ int main(int argc, const char **argv) {
# Public utilities # Public utilities
# #
(defn parse
"Read a string of Janet source and parse out the first expression."
[src]
(let [p (parser/new)]
(:consume p src)
(if (= :error (:status p))
(error (string "Could not parse: " (parser/error p))))
(:produce p)))
(defn find-manifest-dir (defn find-manifest-dir
"Get the path to the directory containing manifests for installed "Get the path to the directory containing manifests for installed
packages." packages."
@ -560,7 +569,7 @@ int main(int argc, const char **argv) {
(defn find-manifest (defn find-manifest
"Get the full path of a manifest file given a package name." "Get the full path of a manifest file given a package name."
[name] [name]
(string (find-manifest-dir) sep name ".txt")) (string (find-manifest-dir) sep name ".jdn"))
(defn find-cache (defn find-cache
"Return the path to the global cache." "Return the path to the global cache."
@ -572,17 +581,14 @@ int main(int argc, const char **argv) {
"Uninstall bundle named name" "Uninstall bundle named name"
[name] [name]
(def manifest (find-manifest name)) (def manifest (find-manifest name))
(def f (file/open manifest :r)) (when-with [f (file/open manifest)]
(unless f (print manifest " does not exist") (break)) (def man (parse (:read f :all)))
(loop [line :iterate (:read f :line)] (each path (get man :paths [])
(def path ((string/split "\n" line) 0)) (print "removing " path)
(def path ((string/split "\r" path) 0)) (rm path))
(print "removing " path) (print "removing " manifest)
(rm path)) (rm manifest)
(:close f) (print "Uninstalled.")))
(print "removing " manifest)
(rm manifest)
(print "Uninstalled."))
(defn- rimraf (defn- rimraf
"Hard delete directory tree" "Hard delete directory tree"
@ -636,13 +642,13 @@ int main(int argc, const char **argv) {
(rimraf module-dir) (rimraf module-dir)
(error (string "could not clone git dependency " repo)))) (error (string "could not clone git dependency " repo))))
(def olddir (os/cwd)) (def olddir (os/cwd))
(os/cd module-dir) (try
(defer (os/cd olddir)
(with-dyns [:rules @{} (with-dyns [:rules @{}
:modpath (abspath (dyn :modpath JANET_MODPATH)) :modpath (abspath (dyn :modpath JANET_MODPATH))
:headerpath (abspath (dyn :headerpath JANET_HEADERPATH)) :headerpath (abspath (dyn :headerpath JANET_HEADERPATH))
:libpath (abspath (dyn :libpath JANET_LIBPATH)) :libpath (abspath (dyn :libpath JANET_LIBPATH))
:binpath (abspath (dyn :binpath JANET_BINPATH))] :binpath (abspath (dyn :binpath JANET_BINPATH))]
(os/cd module-dir)
(unless fresh (unless fresh
(os/execute ["git" "pull" "origin" "master"] :p)) (os/execute ["git" "pull" "origin" "master"] :p))
(when tag (when tag
@ -651,7 +657,9 @@ int main(int argc, const char **argv) {
(import-rules "./project.janet") (import-rules "./project.janet")
(unless no-deps (do-rule "install-deps")) (unless no-deps (do-rule "install-deps"))
(do-rule "build") (do-rule "build")
(do-rule "install")))) (do-rule "install"))
([err] (print "Error building git repository dependency: " err)))
(os/cd olddir))
(defn install-rule (defn install-rule
"Add install and uninstall rule for moving file from src into destdir." "Add install and uninstall rule for moving file from src into destdir."
@ -674,24 +682,21 @@ int main(int argc, const char **argv) {
(default filename "lockfile.janet") (default filename "lockfile.janet")
(def cwd (os/cwd)) (def cwd (os/cwd))
(def packages @[]) (def packages @[])
(os/cd (find-cache)) # Read installed modules from manifests
(os/cd (find-manifest-dir))
(defer (os/cd cwd) (defer (os/cd cwd)
(each repo (os/dir ".") (each man (os/dir ".")
(os/cd repo) (def package (parse slurp man))
(def sha (pslurp "git rev-parse HEAD")) (if (or (not package :repo) (not package :sha))
(def url (pslurp "git remote get-url origin")) (print "Cannot add local package " man " to lockfile, skipping...")
(def deps (array/push packages package))
(with-dyns [:rules @{}]
(def env (import-rules "./project.janet"))
((env :project) :dependencies)))
(array/push packages {:repo url :sha sha :deps (or deps [])})
(os/cd ".."))) (os/cd "..")))
# Put in correct order, such that a package is preceded by all of its dependencies # Put in correct order, such that a package is preceded by all of its dependencies
(def ordered-packages @[]) (def ordered-packages @[])
(def resolved @{}) (def resolved @{})
(while (< (length ordered-packages) (length packages)) (while (< (length ordered-packages) (length packages))
(each p packages (each p packages
(def {:repo r :sha s :deps d} p) (def {:repo r :sha s :dependencies d} p)
(unless (resolved r) (unless (resolved r)
(when (all resolved d) (when (all resolved d)
(array/push ordered-packages p) (array/push ordered-packages p)
@ -702,13 +707,7 @@ int main(int argc, const char **argv) {
(defn- load-lockfile (defn- load-lockfile
[&opt filename] [&opt filename]
(default filename "lockfile.janet") (default filename "lockfile.janet")
(def locksource (slurp filename)) (def lockarray (parse (slurp filename)))
(def lockarray
(let [p (parser/new)]
(:consume p locksource)
(if (= :error (:status p))
(error (string "Could not parse lockfile " filename ": " (parser/error p))))
(:produce p)))
(each {:repo url :sha sha} lockarray (each {:repo url :sha sha} lockarray
(install-git {:repo url :tag sha} nil true))) (install-git {:repo url :tag sha} nil true)))
@ -857,7 +856,14 @@ int main(int argc, const char **argv) {
(phony "manifest" [] (phony "manifest" []
(print "generating " manifest "...") (print "generating " manifest "...")
(mkdir manifests) (mkdir manifests)
(spit manifest (string (string/join installed-files "\n") "\n"))) (def sha (pslurp "git rev-parse HEAD"))
(def url (pslurp "git remote get-url origin"))
(def man
{:sha (if-not (empty? sha) sha)
:repo (if-not (empty? url) url)
:dependencies (array/slice (get meta :dependencies []))
:paths installed-files})
(spit manifest (string/format "%j\n" man)))
(phony "install" ["uninstall" "build" "manifest"] (phony "install" ["uninstall" "build" "manifest"]
(when (dyn :test) (when (dyn :test)