@@ -30,8 +30,9 @@ public static TreeNode load(File file) throws IOException, SanyFrontendException
3030
3131 String parentDirPath = file .getAbsoluteFile ().getParent ();
3232
33- // Resolver for filenames, patched for wired modules.
34- var filenameResolver = new CustomFilenameToStream (parentDirPath );
33+ // Build library paths: parent dir + any paths from -DTLA-Library
34+ var libraryPaths = buildLibraryPaths (parentDirPath );
35+ var filenameResolver = new CustomFilenameToStream (libraryPaths );
3536
3637 // Set a unique tmpdir to avoid race-condition in SANY
3738 // TODO: RM once https://github.com/tlaplus/tlaplus/issues/688 is fixed
@@ -43,6 +44,27 @@ public static TreeNode load(File file) throws IOException, SanyFrontendException
4344 return parseUnitContext .get (specObj .getRootModule ().getName ().toString ()).getParseTree ();
4445 }
4546
47+ /**
48+ * Builds the array of library paths for SANY's module resolution.
49+ * Includes the parent directory of the spec file and any paths
50+ * specified via the -DTLA-Library system property.
51+ */
52+ static String [] buildLibraryPaths (String parentDirPath ) {
53+ List <String > paths = new ArrayList <>();
54+ paths .add (parentDirPath );
55+
56+ String tlaLibrary = System .getProperty (SimpleFilenameToStream .TLA_LIBRARY );
57+ if (tlaLibrary != null && !tlaLibrary .isEmpty ()) {
58+ for (String p : tlaLibrary .split (File .pathSeparator )) {
59+ if (!p .isEmpty ()) {
60+ paths .add (p );
61+ }
62+ }
63+ }
64+
65+ return paths .toArray (new String [0 ]);
66+ }
67+
4668 public static void loadSpecObject (SpecObj specObj , File file , StringWriter errBuf ) throws IOException , SanyFrontendException {
4769 var outStream = WriterOutputStream
4870 .builder ()
@@ -88,65 +110,9 @@ private static void ThrowOnError(SpecObj specObj) {
88110 }
89111
90112 private static class CustomFilenameToStream extends SimpleFilenameToStream {
91- private final List <String > additionalPaths ;
92-
93- public CustomFilenameToStream (String parentDirPath ) {
94- super (parentDirPath );
95- this .additionalPaths = getAdditionalModulePaths ();
113+ public CustomFilenameToStream (String [] libraryPaths ) {
114+ super (libraryPaths );
96115 this .tmpDir .toFile ().deleteOnExit ();
97116 }
98-
99- private static List <String > getAdditionalModulePaths () {
100- List <String > paths = new ArrayList <>();
101- // Check for community modules, TLAPS, and Apalache in common locations
102- String [] possiblePaths = {
103- // Community modules
104- System .getenv ("TLA_COMMUNITY_MODULES" ),
105- "/tmp/CommunityModules/modules" ,
106- "/tmp/CommunityModules" ,
107- System .getProperty ("user.home" ) + "/.tlaplus/CommunityModules/modules" ,
108- // TLAPS library
109- System .getenv ("TLAPS_LIBRARY" ),
110- "/tmp/tlapm/library" ,
111- System .getProperty ("user.home" ) + "/.tlaplus/tlaps/library" ,
112- "/usr/local/lib/tlaps/library" ,
113- // Apalache modules
114- System .getenv ("APALACHE_HOME" ) != null ? System .getenv ("APALACHE_HOME" ) + "/src/tla" : null ,
115- "/tmp/apalache/src/tla" ,
116- System .getProperty ("user.home" ) + "/.tlaplus/apalache/src/tla"
117- };
118- for (String path : possiblePaths ) {
119- if (path != null ) {
120- File dir = new File (path );
121- if (dir .exists () && dir .isDirectory ()) {
122- paths .add (path );
123- }
124- }
125- }
126- return paths ;
127- }
128-
129- @ Override
130- public TLAFile resolve (String name , boolean isModule ) {
131- // First try with the default resolver.
132- TLAFile sourceFile = super .resolve (name , isModule );
133- if (sourceFile != null && sourceFile .exists ()) {
134- return sourceFile ;
135- }
136-
137- // Try additional paths (community modules, etc.)
138- // name already includes .tla extension when isModule=true
139- String filename = name .endsWith (".tla" ) ? name : name + ".tla" ;
140- for (String path : additionalPaths ) {
141- File file = new File (path , filename );
142- if (file .exists ()) {
143- return new TLAFile (file .getAbsolutePath (), this );
144- }
145- }
146-
147- // Return the result from parent resolver (non-existent TLAFile, not null)
148- // to preserve SANY's expected behavior
149- return sourceFile ;
150- }
151117 }
152118}
0 commit comments