Skip to content

Commit 8b1ad79

Browse files
committed
Respect SAW_IMPORT_PATH
Due to an oversight, the `SAW_IMPORT_PATH` environment variable (or, equivalently, the `-i`/`--import-path` command-line options) were being blatantly ignored by SAW. This fixes that oversight by restricting the API in `SAWScript.Import` to a single exported function (`findAndLoadFile`), which always consults `SAW_IMPORT_PATH` before attempting to load a file. Fixes #2756.
1 parent 213f9ed commit 8b1ad79

File tree

11 files changed

+38
-10
lines changed

11 files changed

+38
-10
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ This release supports [version
197197
* Fix a bug that would cause SAW to crash when loading an instantiation of a
198198
parameterized Cryptol module that contains newtypes or enums (#2673).
199199

200+
* Fix a bug that would cause SAW to completely ignore the paths specified in
201+
the `SAW_IMPORT_PATH`/`--import-path` options.
202+
200203
# Version 1.4 -- date still TBD
201204

202205
This release supports [version

doc/pdfs/saw-user-manual.pdf

206 Bytes
Binary file not shown.

doc/saw-user-manual/appendices/repl-reference.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ command-line options:
2121
: Specify a colon-delimited list of paths to search for Java classes.
2222

2323
`-i path, --import-path=path`
24-
: Specify a colon-delimited list of paths to search for imports.
24+
: Specify a colon-delimited list of paths to search for imports. Note that
25+
paths can also be specified using the `SAW_IMPORT_PATH` environment variable.
2526

2627
`-t, --extra-type-checking`
2728
: Perform extra type checking of intermediate values.
@@ -70,7 +71,9 @@ SAW also uses several environment variables for configuration:
7071
searched to find a Java executable.
7172

7273
`SAW_IMPORT_PATH`
73-
: Specify a colon-delimited list of directory paths to search for imports.
74+
: Specify a colon-delimited list of directory paths to search for imports. Note
75+
that paths can also be specified using the `-i`/`--import-path` command-line
76+
options.
7477

7578
`SAW_JDK_JAR`
7679
: Specify the path of the `.jar` file containing the core Java

doc/scripts/epoch.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@
2424
# - the devel version can then be bumped to the current day if needed
2525
#
2626

27-
# BSD/Linux: date +%s -d "09/29/2025 00:00:00 GMT"
28-
# OSX: date -j -f "%m/%d/%Y %H:%M:%S %Z" "9/29/2025 00:00:00 GMT" +%s
29-
SOURCE_DATE_EPOCH=1759104000
27+
# BSD/Linux: date +%s -d "10/30/2025 00:00:00 GMT"
28+
# OSX: date -j -f "%m/%d/%Y %H:%M:%S %Z" "10/30/2025 00:00:00 GMT" +%s
29+
SOURCE_DATE_EPOCH=1761782400

intTests/test2756/a.saw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a = 1;

intTests/test2756/b_dir/b.saw

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let b = 2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let c = 3;

intTests/test2756/test.saw

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
include "a.saw";
2+
include "b.saw";
3+
include "c.saw";
4+
5+
print a;
6+
print b;
7+
print c;

intTests/test2756/test.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set -e
2+
3+
# All of the following are equivalent, and they should all succeed.
4+
SAW_IMPORT_PATH=b_dir:c_dir1/c_dir2 $SAW test.saw
5+
$SAW --import-path b_dir:c_dir1/c_dir2 test.saw
6+
$SAW -i b_dir:c_dir1/c_dir2 test.saw
7+
$SAW --import-path b_dir --import-path c_dir1/c_dir2 test.saw
8+
$SAW -i b_dir -i c_dir1/c_dir2 test.saw

saw-script/src/SAWScript/Import.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Stability : provisional
88
{-# LANGUAGE CPP #-}
99

1010
module SAWScript.Import
11-
( loadFile
12-
, findAndLoadFile
11+
( findAndLoadFile
1312
) where
1413

1514
import qualified Data.Text.IO as TextIO (readFile)
@@ -24,6 +23,7 @@ import SAWCentral.Options
2423
import SAWScript.Parser
2524
import SAWScript.Token (Token)
2625

26+
-- | Load the 'Stmt's in a @.saw@ file.
2727
loadFile :: Options -> FilePath -> IO [Stmt]
2828
loadFile opts fname = do
2929
printOutLn opts Info $ "Loading file " ++ show fname
@@ -53,6 +53,10 @@ parseFile tokens = do
5353
Left err -> Left err
5454
Right stmts -> Right stmts
5555

56+
-- | Find a file, potentially looking in a list of multiple search paths (as
57+
-- specified via the @SAW_IMPORT_PATH@ environment variable or
58+
-- @-i@/@--import-path@ command-line options). If the file was successfully
59+
-- found, load it. If not, raise an error.
5660
findAndLoadFile :: Options -> FilePath -> IO [Stmt]
5761
findAndLoadFile opts fp = do
5862
let paths = importPath opts

0 commit comments

Comments
 (0)