Skip to content

Commit

Permalink
Add support for multiple directories in JANET_PATH.
Browse files Browse the repository at this point in the history
Use a colon ":" as the separator on posix, and semicolon ";" on
windows (and mingw).
  • Loading branch information
bakpakin committed Sep 21, 2024
1 parent ee90f9d commit 8084e4c
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion janet.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
25 changes: 24 additions & 1 deletion src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand Down
6 changes: 3 additions & 3 deletions src/conf/janetconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" */

Expand Down

0 comments on commit 8084e4c

Please sign in to comment.