Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sources/library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions sources/shared.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -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 :: <file-locator>) => (config :: <table>)
fs/with-open-file(stream = file, if-does-not-exist: #f)
let object = parse-json(stream, strict?: #f, table-class: <istring-table>);
if (~instance?(object, <table>))
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: <istring-table>);
if (~instance?(object, <table>))
error("Invalid JSON file %s, must contain at least {}", file);
end;
object
end
exception (fs/<file-does-not-exist-error>)
make(<istring-table>)
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 :: <locator>) => (text :: false-or(<string>))
block ()
fs/with-open-file(stream = path, if-does-not-exist: #"signal")
Expand Down
45 changes: 26 additions & 19 deletions sources/workspaces/workspaces.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -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 :: <workspace>) => (name :: false-or(<string>))
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
Expand Down Expand Up @@ -176,26 +198,11 @@ end function;
// Load the workspace.json file
define function load-workspace-config
(ws :: <workspace>, file :: <file-locator>) => ()
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
Expand Down