Skip to content

Commit

Permalink
Merge pull request #36 from ekala-project/tracing
Browse files Browse the repository at this point in the history
feat: trivial debug tracing information
  • Loading branch information
nrdxp authored Sep 26, 2024
2 parents 4c4f2f8 + f94e53c commit f2f7314
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
34 changes: 22 additions & 12 deletions src/core/compose.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ in
}:
dir':
let
dir = src.prepDir dir';
par = src.prepDir dir';

std = src.readStd {
features = stdFeatures;
Expand All @@ -90,6 +90,8 @@ let
};
};

msg = src.errors.debugMsg config;

f =
f: pre: dir:
let
Expand Down Expand Up @@ -153,13 +155,19 @@ let
let
path = src.path.make dir name;
file = src.file.parse name;
member = l.path { inherit path name; };
member = Import (l.path { inherit path name; });
module = src.path.make path "mod.nix";
in
if type == "directory" && l.pathExists module then
{ ${name} = f ((src.lowerKeys self) // src.set.when preOpt) path; }
else if type == "regular" && file.ext or null == "nix" && name != "mod.nix" then
{ ${file.name} = Import member; }
{
${file.name} =
let
trace = src.errors.modPath par dir;
in
src.errors.context (msg "${trace}.${file.name}") member;
}
else
null # Ignore other file types
;
Expand All @@ -169,14 +177,16 @@ let
self =
let
path = src.path.make dir "mod.nix";
module = l.path {
inherit path;
name = baseNameOf path;
};
mod = Import module;
module = Import (
l.path {
inherit path;
name = baseNameOf path;
}
);
trace = src.errors.modPath par dir;
in
assert src.modIsValid mod dir;
src.filterMap g contents // mod;
assert src.modIsValid module dir;
src.filterMap g contents // (src.errors.context (msg trace) module);

in
if src.hasMod contents then
Expand All @@ -187,12 +197,12 @@ let

atom' = l.removeAttrs (extern // atom // { inherit extern; }) [
"atom"
(baseNameOf dir)
(baseNameOf par)
];

atom =
let
fixed = src.fix f null dir;
fixed = src.fix f null par;
in
src.set.inject fixed [
({ _if = __isStd__; } // src.pureBuiltinsForStd fixed)
Expand Down
24 changes: 24 additions & 0 deletions src/core/errors.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ let
in
{
inherit warn;

debugMsg =
config: path:
"in ${config.atom.name}${if config.atom ? version then "-${config.atom.version}" else ""}${
if path == "" then "" else " at ${path}"
}";

context = msg: value: l.traceVerbose msg value;
modPath =
par: path:
let

modFromDir =
path: l.concatStringsSep "." (l.tail (l.filter l.isString (l.split "/" (toString path))));
stripParentDir =
p: p':
let
len = l.stringLength (toString p);
res = l.substring (len + 1) (-1) (toString p');
in
/. + res;

in
modFromDir (stripParentDir par path);
import = abort "Importing arbitrary Nix files is forbidden. Declare your dependencies via the module system instead.";
fetch = abort "Ad hoc fetching is illegal. Declare dependencies statically in the manifest instead.";
system = abort "Accessing the current system is impure. Declare supported systems in the manifest.";
Expand Down

0 comments on commit f2f7314

Please sign in to comment.