From 8084e4c7284154144c2f9b6c02fa20d159069124 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 20 Sep 2024 22:21:46 -0500 Subject: [PATCH] Add support for multiple directories in JANET_PATH. Use a colon ":" as the separator on posix, and semicolon ";" on windows (and mingw). --- CHANGELOG.md | 4 ++++ Makefile | 13 ++++++++++--- janet.1 | 3 ++- meson.build | 2 +- src/boot/boot.janet | 25 ++++++++++++++++++++++++- src/conf/janetconf.h | 6 +++--- 6 files changed, 44 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94901287b..c55280079 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Changelog All notable changes to this project will be documented in this file. +## ??? - Unreleased +- Add multiple path support in the `JANET_PATH` environment variables. This lets + user more easily import modules from many directories. + ## 1.36.0 - 2024-09-07 - Improve error messages in `bundle/add*` functions. - Add CI testing and verify tests pass on the s390x architecture. diff --git a/Makefile b/Makefile index 6bca25590..f43c9dbc1 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Calvin Rose +# Copyright (c) 2024 Calvin Rose # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to @@ -43,6 +43,7 @@ JANET_DIST_DIR?=janet-dist JANET_BOOT_FLAGS:=. JANET_PATH '$(JANET_PATH)' JANET_TARGET_OBJECTS=build/janet.o build/shell.o JPM_TAG?=master +SPORK_TAG?=master HAS_SHARED?=1 DEBUGGER=gdb SONAME_SETTER=-Wl,-soname, @@ -205,9 +206,9 @@ build/%.bin.o: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) Makefile ######################## ifeq ($(UNAME), Darwin) -SONAME=libjanet.1.36.dylib +SONAME=libjanet.1.37.dylib else -SONAME=libjanet.so.1.36 +SONAME=libjanet.so.1.37 endif build/c/shell.c: src/mainclient/shell.c @@ -359,6 +360,12 @@ install-jpm-git: $(JANET_TARGET) JANET_LIBPATH='$(LIBDIR)' \ $(RUN) ../../$(JANET_TARGET) ./bootstrap.janet +install-spork-git: $(JANET_TARGET) + mkdir -p build + rm -rf build/spork + git clone --depth=1 --branch='$(SPORK_TAG)' https://github.com/janet-lang/spork.git build/spork + $(JANET_TARGET) -e '(bundle/install "build/spork")' + uninstall: -rm '$(DESTDIR)$(BINDIR)/janet' -rm -rf '$(DESTDIR)$(INCLUDEDIR)/janet' diff --git a/janet.1 b/janet.1 index 0c946b2bd..9e7c0ae28 100644 --- a/janet.1 +++ b/janet.1 @@ -255,7 +255,8 @@ and then arguments to the script. .RS The location to look for Janet libraries. This is the only environment variable Janet needs to find native and source code modules. If no JANET_PATH is set, Janet will look in -the default location set at compile time. +the default location set at compile time. This should be a list of as well as a colon +separate list of such directories. .RE .B JANET_PROFILE diff --git a/meson.build b/meson.build index 6fffb5df3..f17e8a596 100644 --- a/meson.build +++ b/meson.build @@ -20,7 +20,7 @@ project('janet', 'c', default_options : ['c_std=c99', 'build.c_std=c99', 'b_lundef=false', 'default_library=both'], - version : '1.36.0') + version : '1.37.0') # Global settings janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet') diff --git a/src/boot/boot.janet b/src/boot/boot.janet index d1aab5d84..b3dc0db90 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -2827,6 +2827,24 @@ (array/insert mp curall-index [(string ":cur:/:all:" ext) loader check-relative]) mp) +# Don't expose this externally yet - could break if custom module/paths is setup. +(defn- module/add-syspath + ``` + Add a custom syspath to `module/paths` by duplicating all entries that being with `:sys:` and + adding duplicates with a specific path prefix instead. + ``` + [path] + (def copies @[]) + (var last-index 0) + (def mp (dyn *module-paths* module/paths)) + (eachp [index entry] mp + (def pattern (first entry)) + (when (and (string? pattern) (string/has-prefix? ":sys:/" pattern)) + (set last-index index) + (array/push copies [(string/replace ":sys:" path pattern) ;(drop 1 entry)]))) + (array/insert mp (+ 1 last-index) ;copies) + mp) + (module/add-paths ":native:" :native) (module/add-paths "/init.janet" :source) (module/add-paths ".janet" :source) @@ -4488,7 +4506,12 @@ (var error-level nil) (var expect-image false) - (if-let [jp (getenv-alias "JANET_PATH")] (setdyn *syspath* jp)) + (when-let [jp (getenv-alias "JANET_PATH")] + (def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":")) + (def paths (reverse! (string/split path-sep jp))) + (for i 1 (length paths) + (module/add-syspath (get paths i))) + (setdyn *syspath* (first paths))) (if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile)) (set colorize (and (not (getenv-alias "NO_COLOR")) diff --git a/src/conf/janetconf.h b/src/conf/janetconf.h index c7c48b1ea..0211ee22f 100644 --- a/src/conf/janetconf.h +++ b/src/conf/janetconf.h @@ -4,10 +4,10 @@ #define JANETCONF_H #define JANET_VERSION_MAJOR 1 -#define JANET_VERSION_MINOR 36 +#define JANET_VERSION_MINOR 37 #define JANET_VERSION_PATCH 0 -#define JANET_VERSION_EXTRA "" -#define JANET_VERSION "1.36.0" +#define JANET_VERSION_EXTRA "-dev" +#define JANET_VERSION "1.37.0-dev" /* #define JANET_BUILD "local" */