1
0
mirror of https://github.com/janet-lang/janet synced 2025-04-28 05:33:18 +00:00

Add the --offline flag to jpm.

This will let jpm install things only from the cache, and not
try and sync the latest from git.
This commit is contained in:
Calvin Rose 2020-04-21 12:41:08 -05:00
parent 13559baecc
commit 99d9c57154
2 changed files with 25 additions and 16 deletions

View File

@ -266,15 +266,12 @@
(defn rm (defn rm
"Remove a directory and all sub directories." "Remove a directory and all sub directories."
[path] [path]
(try
(if (= (os/lstat path :mode) :directory) (if (= (os/lstat path :mode) :directory)
(do (do
(each subpath (os/dir path) (each subpath (os/dir path)
(rm (string path sep subpath))) (rm (string path sep subpath)))
(os/rmdir path)) (os/rmdir path))
(os/rm path)) (os/rm path)))
([err f] (unless (string/has-prefix? "No such file or directory" err)
(propagate err f)))))
(defn copy (defn copy
"Copy a file or directory recursively from one location to another." "Copy a file or directory recursively from one location to another."
@ -680,12 +677,16 @@ int main(int argc, const char **argv) {
(def id (filepath-replace repo)) (def id (filepath-replace repo))
(def module-dir (string cache sep id)) (def module-dir (string cache sep id))
(var fresh false) (var fresh false)
(if (dyn :offline)
(if (not= :directory (os/stat module-dir :mode))
(error (string "did not find cached repo for dependency " repo))
(set fresh true))
(when (mkdir module-dir) (when (mkdir module-dir)
(set fresh true) (set fresh true)
(print "cloning repository " repo " to " module-dir) (print "cloning repository " repo " to " module-dir)
(unless (zero? (os/execute ["git" "clone" repo module-dir] :p)) (unless (zero? (os/execute ["git" "clone" repo module-dir] :p))
(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))
(try (try
(with-dyns [:rules @{} (with-dyns [:rules @{}
@ -698,7 +699,8 @@ int main(int argc, const char **argv) {
(os/execute ["git" "pull" "origin" "master"] :p)) (os/execute ["git" "pull" "origin" "master"] :p))
(when tag (when tag
(os/execute ["git" "reset" "--hard" tag] :p)) (os/execute ["git" "reset" "--hard" tag] :p))
(os/execute ["git" "submodule" "update" "--init" "--recursive"] :p) (unless (dyn :offline)
(os/execute ["git" "submodule" "update" "--init" "--recursive"] :p))
(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")
@ -1030,6 +1032,7 @@ Flags are:
--nocolor : Disable color in the jpm repl. --nocolor : Disable color in the jpm repl.
--verbose : Print shell commands as they are executed. --verbose : Print shell commands as they are executed.
--test : If passed to jpm install, runs tests before installing. Will run tests recursively on dependencies. --test : If passed to jpm install, runs tests before installing. Will run tests recursively on dependencies.
--offline : Prevents jpm from going to network to get dependencies - all dependencies should be in the cache or this command will fail.
`)) `))
(defn show-help (defn show-help

6
jpm.1
View File

@ -36,6 +36,12 @@ Print detailed messages of what jpm is doing, including compilation commands and
.BR \-\-test .BR \-\-test
If passed to jpm install, runs tests before installing. Will run tests recursively on dependencies. If passed to jpm install, runs tests before installing. Will run tests recursively on dependencies.
.TP
.BR \-\-offline
Prevents jpm from going to network to get dependencies - all dependencies should be in the cache or this command will fail.
Use this flag with the deps and update-pkgs subcommands. This is not a surefire way to prevent a build script from accessing
the network, for example, a build script that invokes curl will still have network access.
.SH OPTIONS .SH OPTIONS
.TP .TP