Skip to content

Commit 8084e4c

Browse files
committed
Add support for multiple directories in JANET_PATH.
Use a colon ":" as the separator on posix, and semicolon ";" on windows (and mingw).
1 parent ee90f9d commit 8084e4c

File tree

6 files changed

+44
-9
lines changed

6 files changed

+44
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## ??? - Unreleased
5+
- Add multiple path support in the `JANET_PATH` environment variables. This lets
6+
user more easily import modules from many directories.
7+
48
## 1.36.0 - 2024-09-07
59
- Improve error messages in `bundle/add*` functions.
610
- Add CI testing and verify tests pass on the s390x architecture.

Makefile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023 Calvin Rose
1+
# Copyright (c) 2024 Calvin Rose
22
#
33
# Permission is hereby granted, free of charge, to any person obtaining a copy
44
# of this software and associated documentation files (the "Software"), to
@@ -43,6 +43,7 @@ JANET_DIST_DIR?=janet-dist
4343
JANET_BOOT_FLAGS:=. JANET_PATH '$(JANET_PATH)'
4444
JANET_TARGET_OBJECTS=build/janet.o build/shell.o
4545
JPM_TAG?=master
46+
SPORK_TAG?=master
4647
HAS_SHARED?=1
4748
DEBUGGER=gdb
4849
SONAME_SETTER=-Wl,-soname,
@@ -205,9 +206,9 @@ build/%.bin.o: src/%.c $(JANET_HEADERS) $(JANET_LOCAL_HEADERS) Makefile
205206
########################
206207

207208
ifeq ($(UNAME), Darwin)
208-
SONAME=libjanet.1.36.dylib
209+
SONAME=libjanet.1.37.dylib
209210
else
210-
SONAME=libjanet.so.1.36
211+
SONAME=libjanet.so.1.37
211212
endif
212213

213214
build/c/shell.c: src/mainclient/shell.c
@@ -359,6 +360,12 @@ install-jpm-git: $(JANET_TARGET)
359360
JANET_LIBPATH='$(LIBDIR)' \
360361
$(RUN) ../../$(JANET_TARGET) ./bootstrap.janet
361362

363+
install-spork-git: $(JANET_TARGET)
364+
mkdir -p build
365+
rm -rf build/spork
366+
git clone --depth=1 --branch='$(SPORK_TAG)' https://github.com/janet-lang/spork.git build/spork
367+
$(JANET_TARGET) -e '(bundle/install "build/spork")'
368+
362369
uninstall:
363370
-rm '$(DESTDIR)$(BINDIR)/janet'
364371
-rm -rf '$(DESTDIR)$(INCLUDEDIR)/janet'

janet.1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ and then arguments to the script.
255255
.RS
256256
The location to look for Janet libraries. This is the only environment variable Janet needs to
257257
find native and source code modules. If no JANET_PATH is set, Janet will look in
258-
the default location set at compile time.
258+
the default location set at compile time. This should be a list of as well as a colon
259+
separate list of such directories.
259260
.RE
260261

261262
.B JANET_PROFILE

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
project('janet', 'c',
2222
default_options : ['c_std=c99', 'build.c_std=c99', 'b_lundef=false', 'default_library=both'],
23-
version : '1.36.0')
23+
version : '1.37.0')
2424

2525
# Global settings
2626
janet_path = join_paths(get_option('prefix'), get_option('libdir'), 'janet')

src/boot/boot.janet

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2827,6 +2827,24 @@
28272827
(array/insert mp curall-index [(string ":cur:/:all:" ext) loader check-relative])
28282828
mp)
28292829

2830+
# Don't expose this externally yet - could break if custom module/paths is setup.
2831+
(defn- module/add-syspath
2832+
```
2833+
Add a custom syspath to `module/paths` by duplicating all entries that being with `:sys:` and
2834+
adding duplicates with a specific path prefix instead.
2835+
```
2836+
[path]
2837+
(def copies @[])
2838+
(var last-index 0)
2839+
(def mp (dyn *module-paths* module/paths))
2840+
(eachp [index entry] mp
2841+
(def pattern (first entry))
2842+
(when (and (string? pattern) (string/has-prefix? ":sys:/" pattern))
2843+
(set last-index index)
2844+
(array/push copies [(string/replace ":sys:" path pattern) ;(drop 1 entry)])))
2845+
(array/insert mp (+ 1 last-index) ;copies)
2846+
mp)
2847+
28302848
(module/add-paths ":native:" :native)
28312849
(module/add-paths "/init.janet" :source)
28322850
(module/add-paths ".janet" :source)
@@ -4488,7 +4506,12 @@
44884506
(var error-level nil)
44894507
(var expect-image false)
44904508

4491-
(if-let [jp (getenv-alias "JANET_PATH")] (setdyn *syspath* jp))
4509+
(when-let [jp (getenv-alias "JANET_PATH")]
4510+
(def path-sep (if (index-of (os/which) [:windows :mingw]) ";" ":"))
4511+
(def paths (reverse! (string/split path-sep jp)))
4512+
(for i 1 (length paths)
4513+
(module/add-syspath (get paths i)))
4514+
(setdyn *syspath* (first paths)))
44924515
(if-let [jprofile (getenv-alias "JANET_PROFILE")] (setdyn *profilepath* jprofile))
44934516
(set colorize (and
44944517
(not (getenv-alias "NO_COLOR"))

src/conf/janetconf.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#define JANETCONF_H
55

66
#define JANET_VERSION_MAJOR 1
7-
#define JANET_VERSION_MINOR 36
7+
#define JANET_VERSION_MINOR 37
88
#define JANET_VERSION_PATCH 0
9-
#define JANET_VERSION_EXTRA ""
10-
#define JANET_VERSION "1.36.0"
9+
#define JANET_VERSION_EXTRA "-dev"
10+
#define JANET_VERSION "1.37.0-dev"
1111

1212
/* #define JANET_BUILD "local" */
1313

0 commit comments

Comments
 (0)