Add shorthand package name support in jpm.

Package installation checks in the package listing if
the package name is not a url. The package listsing can be specified
via switch or env variable.
This commit is contained in:
Calvin Rose 2019-10-10 18:11:45 -05:00
parent f9d57103f4
commit 54b66a4199
3 changed files with 26 additions and 5 deletions

View File

@ -565,12 +565,24 @@ int main(int argc, const char **argv) {
(os/shell (string `rmdir /S /Q "` cache `"`))
(rm cache)))
(def- default-pkglist (or (os/getenv "JANET_PKGLIST") "https://github.com/janet-lang/pkgs.git"))
(defn install-git
"Install a bundle from git. If the bundle is already installed, the bundle
is reinistalled (but not rebuilt if artifacts are cached)."
[repotab]
[repotab &opt recurse]
(def repo (if (string? repotab) repotab (repotab :repo)))
(def tag (unless (string? repotab) (repotab :tag)))
# prevent infinite recursion (very unlikely, but consider
# 'my-package "my-package" in the package listing)
(when (> (or recurse 0) 100)
(error "too many references resolving package url"))
# Handle short names
(unless (string/find ":" repo)
(install-git (dyn :pkglist default-pkglist))
(def pkgs (require "pkgs"))
(break (install-git (get-in pkgs ['packages :value (symbol repo)])
(if recurse (inc recurse) 0))))
(def cache (find-cache))
(os/mkdir cache)
(def id (filepath-replace repo))
@ -832,6 +844,7 @@ Keys are:
--compiler : C compiler to use for natives. Defaults to cc (cl on windows).
--archiver : C compiler to use for static libraries. Defaults to ar (lib on windows).
--linker : C linker to use for linking natives. Defaults to cc (link on windows).
--pkglist : URL of git repository for package listing. Defaults to $JANET_PKGLIST or https://github.com/janet-lang/pkgs.git
Flags are:
--verbose : Print shell commands as they are executed.

10
jpm.1
View File

@ -64,6 +64,10 @@ to cc.
.BR \-\-linker=ld
Sets the linker used to create native modules and executables.
.TP
.BR \-\-pkglist=https://github.com/janet-lang/pkgs.git
Sets the git repository for the package listing used to resolve shorthand package names.
.TP
.BR \-\-archiver=ar
Sets the command used for creating static libraries, use for linking into the standalone executable.
@ -172,5 +176,11 @@ Defaults to
The --binpath=/some/path will override this variable.
.RE
.B JANET_PKGLIST
.RS
The git repository URL that contains a listing of packages. This allows installing packages with shortnames, which
is mostly a convenience. However, package dependencies can use short names, package listings
can be used to choose a particular set of dependency versions for a whole project.
.SH AUTHOR
Written by Calvin Rose <calsrose@gmail.com>

View File

@ -887,10 +887,8 @@ static uint32_t peg_compile1(Builder *b, Janet peg) {
JanetTable *grammar = old_grammar;
for (; i > 0 && janet_checktype(peg, JANET_KEYWORD); --i) {
peg = janet_table_get_ex(grammar, peg, &grammar);
if (!grammar || janet_checktype(peg, JANET_NIL)) {
builder_cleanup(b);
janet_panicf("grammar error in %p, unknown rule", b->form);
}
if (!grammar || janet_checktype(peg, JANET_NIL))
peg_panic(b, "unkown rule");
b->form = peg;
b->grammar = grammar;
}