Skip to content

Commit 7d83a39

Browse files
authored
Merge pull request dylan-lang#63 from cgay/dev
Improve loading workspace config
2 parents ba82e34 + d6416e7 commit 7d83a39

3 files changed

Lines changed: 41 additions & 29 deletions

File tree

sources/library.dylan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ define module deft-shared
4444
use streams, export: all;
4545
use strings, export: all;
4646
use threads, export: all, import: { dynamic-bind };
47-
use uncommon-dylan, export: all;
47+
use uncommon-dylan, export: all, exclude: { format-out, format-to-string };
4848
use uncommon-utils, export: all;
4949

5050
export

sources/shared.dylan

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,24 @@ define inline function warn (fmt, #rest args) => ()
4141
apply(note, concat("WARNING: ", fmt), args);
4242
end;
4343

44+
// https://github.com/dylan-lang/opendylan/issues/1358
4445
define function load-json-file (file :: <file-locator>) => (config :: <table>)
45-
fs/with-open-file(stream = file, if-does-not-exist: #f)
46-
let object = parse-json(stream, strict?: #f, table-class: <istring-table>);
47-
if (~instance?(object, <table>))
48-
error("Invalid JSON file %s, must contain at least {}", file);
49-
end;
50-
object
46+
block ()
47+
fs/with-open-file(stream = file, if-does-not-exist: #"signal")
48+
let object = parse-json(stream, strict?: #f, table-class: <istring-table>);
49+
if (~instance?(object, <table>))
50+
error("Invalid JSON file %s, must contain at least {}", file);
51+
end;
52+
object
53+
end
54+
exception (fs/<file-does-not-exist-error>)
55+
make(<istring-table>)
5156
end
5257
end function;
5358

54-
// Read the full contents of a file and return it as a string. If the file
55-
// doesn't exist return #f. (I thought if-does-not-exist: #f was supposed to
56-
// accomplish this without the need for block/exception.)
59+
// Read the full contents of a file and return it as a string. If the file doesn't exist
60+
// return #f. (I thought if-does-not-exist: #f was supposed to accomplish this without
61+
// the need for block/exception. https://github.com/dylan-lang/opendylan/issues/1358)
5762
define function file-content (path :: <locator>) => (text :: false-or(<string>))
5863
block ()
5964
fs/with-open-file(stream = path, if-does-not-exist: #"signal")

sources/workspaces/workspaces.dylan

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,31 @@ define function load-workspace
119119
& dp-file
120120
& (ws-file.locator-directory ~= dp-file.locator-directory))));
121121
ws-file & load-workspace-config(ws, ws-file);
122+
if (~ws.workspace-default-library-name)
123+
ws.workspace-default-library-name := find-default-library(ws);
124+
end;
122125
ws
123126
end function;
124127

128+
define function find-default-library
129+
(ws :: <workspace>) => (name :: false-or(<string>))
130+
block (return)
131+
let fallback = #f;
132+
for (lids keyed-by package in ws.lids-by-release)
133+
for (lid in lids)
134+
let name = lid.library-name;
135+
fallback := fallback | name;
136+
if (ends-with?(name, "-test-suite-app")
137+
| ends-with?(name, "-test-suite")
138+
| ends-with?(name, "-tests"))
139+
return(name);
140+
end;
141+
end for;
142+
end for;
143+
fallback
144+
end block
145+
end function;
146+
125147
// Scan the workspace to find all active packages, from which the lids-by-* tables are
126148
// populated and deps can be determined.
127149
define function scan-workspace
@@ -176,26 +198,11 @@ end function;
176198
// Load the workspace.json file
177199
define function load-workspace-config
178200
(ws :: <workspace>, file :: <file-locator>) => ()
179-
local method find-default-library ()
180-
block (return)
181-
let fallback = #f;
182-
for (lids keyed-by package in ws.lids-by-release)
183-
for (lid in lids)
184-
let name = lid.library-name;
185-
fallback := fallback | name;
186-
if (ends-with?(name, "-test-suite-app")
187-
| ends-with?(name, "-test-suite")
188-
| ends-with?(name, "-tests"))
189-
return(name);
190-
end;
191-
end for;
192-
end for;
193-
fallback
194-
end block;
195-
end method;
196201
let json = load-json-file(file);
197-
ws.workspace-default-library-name
198-
:= element(json, $default-library-key, default: #f) | find-default-library();
202+
let deflib = element(json, $default-library-key, default: #f);
203+
if (deflib)
204+
ws.workspace-default-library-name := deflib;
205+
end;
199206
end function;
200207

201208
// Find the workspace directory. The nearest directory containing

0 commit comments

Comments
 (0)