diff --git a/sources/library.dylan b/sources/library.dylan index 456d63d..65ebd5f 100644 --- a/sources/library.dylan +++ b/sources/library.dylan @@ -44,7 +44,7 @@ define module deft-shared use streams, export: all; use strings, export: all; use threads, export: all, import: { dynamic-bind }; - use uncommon-dylan, export: all; + use uncommon-dylan, export: all, exclude: { format-out, format-to-string }; use uncommon-utils, export: all; export diff --git a/sources/shared.dylan b/sources/shared.dylan index 4cf7664..b84c665 100644 --- a/sources/shared.dylan +++ b/sources/shared.dylan @@ -41,19 +41,24 @@ define inline function warn (fmt, #rest args) => () apply(note, concat("WARNING: ", fmt), args); end; +// https://github.com/dylan-lang/opendylan/issues/1358 define function load-json-file (file :: ) => (config :: ) - fs/with-open-file(stream = file, if-does-not-exist: #f) - let object = parse-json(stream, strict?: #f, table-class: ); - if (~instance?(object,
)) - error("Invalid JSON file %s, must contain at least {}", file); - end; - object + block () + fs/with-open-file(stream = file, if-does-not-exist: #"signal") + let object = parse-json(stream, strict?: #f, table-class: ); + if (~instance?(object,
)) + error("Invalid JSON file %s, must contain at least {}", file); + end; + object + end + exception (fs/) + make() end end function; -// Read the full contents of a file and return it as a string. If the file -// doesn't exist return #f. (I thought if-does-not-exist: #f was supposed to -// accomplish this without the need for block/exception.) +// Read the full contents of a file and return it as a string. If the file doesn't exist +// return #f. (I thought if-does-not-exist: #f was supposed to accomplish this without +// the need for block/exception. https://github.com/dylan-lang/opendylan/issues/1358) define function file-content (path :: ) => (text :: false-or()) block () fs/with-open-file(stream = path, if-does-not-exist: #"signal") diff --git a/sources/workspaces/workspaces.dylan b/sources/workspaces/workspaces.dylan index 6123563..843b648 100644 --- a/sources/workspaces/workspaces.dylan +++ b/sources/workspaces/workspaces.dylan @@ -119,9 +119,31 @@ define function load-workspace & dp-file & (ws-file.locator-directory ~= dp-file.locator-directory)))); ws-file & load-workspace-config(ws, ws-file); + if (~ws.workspace-default-library-name) + ws.workspace-default-library-name := find-default-library(ws); + end; ws end function; +define function find-default-library + (ws :: ) => (name :: false-or()) + block (return) + let fallback = #f; + for (lids keyed-by package in ws.lids-by-release) + for (lid in lids) + let name = lid.library-name; + fallback := fallback | name; + if (ends-with?(name, "-test-suite-app") + | ends-with?(name, "-test-suite") + | ends-with?(name, "-tests")) + return(name); + end; + end for; + end for; + fallback + end block +end function; + // Scan the workspace to find all active packages, from which the lids-by-* tables are // populated and deps can be determined. define function scan-workspace @@ -176,26 +198,11 @@ end function; // Load the workspace.json file define function load-workspace-config (ws :: , file :: ) => () - local method find-default-library () - block (return) - let fallback = #f; - for (lids keyed-by package in ws.lids-by-release) - for (lid in lids) - let name = lid.library-name; - fallback := fallback | name; - if (ends-with?(name, "-test-suite-app") - | ends-with?(name, "-test-suite") - | ends-with?(name, "-tests")) - return(name); - end; - end for; - end for; - fallback - end block; - end method; let json = load-json-file(file); - ws.workspace-default-library-name - := element(json, $default-library-key, default: #f) | find-default-library(); + let deflib = element(json, $default-library-key, default: #f); + if (deflib) + ws.workspace-default-library-name := deflib; + end; end function; // Find the workspace directory. The nearest directory containing