Skip to content

Commit bf09a34

Browse files
authored
Merge pull request #2761 from GaloisInc/T2756-fix-SAW_IMPORT_PATH
Respect `SAW_IMPORT_PATH`
2 parents 4868cb5 + b9881b5 commit bf09a34

File tree

11 files changed

+46
-26
lines changed

11 files changed

+46
-26
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: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ License : BSD3
55
Maintainer : huffman
66
Stability : provisional
77
-}
8-
{-# LANGUAGE CPP #-}
9-
108
module SAWScript.Import
11-
( loadFile
12-
, findAndLoadFile
9+
( findAndLoadFile
1310
) where
1411

1512
import qualified Data.Text.IO as TextIO (readFile)
1613
import qualified Data.Text as Text
1714
import Control.Exception
1815
import System.Directory
16+
import System.FilePath (normalise)
1917

2018
import SAWCentral.Position (Pos)
2119
import SAWCentral.AST
@@ -24,6 +22,7 @@ import SAWCentral.Options
2422
import SAWScript.Parser
2523
import SAWScript.Token (Token)
2624

25+
-- | Load the 'Stmt's in a @.saw@ file.
2726
loadFile :: Options -> FilePath -> IO [Stmt]
2827
loadFile opts fname = do
2928
printOutLn opts Info $ "Loading file " ++ show fname
@@ -53,6 +52,10 @@ parseFile tokens = do
5352
Left err -> Left err
5453
Right stmts -> Right stmts
5554

55+
-- | Find a file, potentially looking in a list of multiple search paths (as
56+
-- specified via the @SAW_IMPORT_PATH@ environment variable or
57+
-- @-i@/@--import-path@ command-line options). If the file was successfully
58+
-- found, load it. If not, raise an error.
5659
findAndLoadFile :: Options -> FilePath -> IO [Stmt]
5760
findAndLoadFile opts fp = do
5861
let paths = importPath opts
@@ -62,17 +65,10 @@ findAndLoadFile opts fp = do
6265
[ "Couldn't find file: " ++ show fp
6366
, " Searched in directories:"
6467
] ++ map (" " ++) paths
65-
Just fname -> loadFile opts fname
66-
67-
#if __GLASGOW_HASKELL__ < 706
68-
findFile :: [FilePath] -> String -> IO (Maybe FilePath)
69-
findFile paths fileName = search paths
70-
where
71-
search :: [FilePath] -> IO (Maybe FilePath)
72-
search [] = return Nothing
73-
search (d:ds) = do
74-
let path = d </> fileName
75-
b <- doesFileExist path
76-
if b then return (Just path)
77-
else search ds
78-
#endif
68+
Just fname ->
69+
-- NB: Normalise the path name. The default SAW_IMPORT_PATH contains ".",
70+
-- and the behavior of filepath's 'normalise' function is to prepend a
71+
-- search path to the front of the file path that is found, which can
72+
-- cause paths like "./foo.saw" to be returned. This looks ugly in error
73+
-- messages, where we would rather display "foo.saw" instead.
74+
loadFile opts (normalise fname)

0 commit comments

Comments
 (0)