fixup resolveAllProjects

This commit is contained in:
DavHau 2022-02-26 00:54:52 +07:00
parent 8fbd1d51a9
commit b1872eb866
4 changed files with 56 additions and 26 deletions

View File

@ -419,7 +419,7 @@ let
resolveAllProjects= resolveAllProjects=
{ {
source ? null, source ? null,
tree ? dlib.prepareSourceTree source, tree ? dlib.prepareSourceTree { inherit source; },
pname, pname,
}@args: }@args:
@ -430,52 +430,79 @@ let
getTranslator = subsystem: translatorName: getTranslator = subsystem: translatorName:
translators.translators."${subsystem}".all."${translatorName}"; translators.translators."${subsystem}".all."${translatorName}";
isImpure = project: isImpure = project: translatorName:
(getTranslator project.subsystem project.translator).type == "impure"; (getTranslator project.subsystem translatorName).type == "impure";
getDreamLockPath = project: getDreamLockPath = project:
"${config.projectsDir}/${pname}/${project.relPath}/dream-lock.json"; config.projectRoot +
(dlib.sanitizeRelativePath
"${config.packagesDir}/${pname}/${project.relPath}/dream-lock.json");
projects = getProjectKey = project:
"${project.name}_|_${project.subsystem}_|_${project.relPath}";
# list of projects extended with some information requried for processing
projectsList =
l.map l.map
(project: project // rec { (project: project // rec {
dreamLockPath = getDreamLockPath project; dreamLockPath = getDreamLockPath project;
dreamLock = dlib.readDreamLock dreamLockPath; dreamLock = dlib.readDreamLock dreamLockPath;
impure = isImpure project translator;
key = getProjectKey project;
resolved = l.pathExists dreamLockPath; resolved = l.pathExists dreamLockPath;
impure = isImpure project; translator = l.head project.translators;
}) })
discoveredProjects; discoveredProjects;
# unresolved dimpure projects cannot be resolved on the fly # attrset of projects by key
projectsImpureUnresolved = projects =
l.filter (project: project.impure && ! project.resolved) projects; l.listToAttrs
(l.map
(proj: l.nameValuePair proj.key proj)
projectsList);
# unresolved impure projects cannot be resolved on the fly
projectsImpureUnresolved =
l.filter (project: project.impure && ! project.resolved) projectsList;
# for printing the paths inside the error message
projectsImpureUnresolvedPaths = projectsImpureUnresolvedPaths =
l.map (project: project.relPath) projectsImpureUnresolved; l.map (project: project.relPath) projectsImpureUnresolved;
# projects without existing valid dream-lock.json # projects without existing valid dream-lock.json
projectsUnresolved = l.filter (project: ! project.resolved) projects; projectsUnresolved = l.filter (project: ! project.resolved) projectsList;
# pure projects keyed by '{subsystem}_{translator_name}' # pure projects grouped by translator
projectsByTranslator = projectsByTranslator =
l.groupBy l.groupBy
(proj: "${proj.subsystem}_${l.head proj.translators}") (proj: "${proj.subsystem}_${l.head proj.translators}")
projectsUnresolved; projectsUnresolved;
# list of pure projects extended with 'dreamLock' attribute # list of pure projects extended with 'dreamLock' attribute
translatedProjects = resolvedProjectsList =
l.mapAttrsToList l.flatten
(translatorName: projects: (l.mapAttrsToList
let (translatorName: projects:
translator = getTranslator projects.subsystem translatorName; let
in p = l.head projects;
# transaltor will attach dreamLock to project translator = getTranslator p.subsystem p.translator;
translator.translate { in
inherit projects source tree; # transaltor will attach dreamLock to project
}) translator.translate {
projectsByTranslator; inherit projects source tree;
})
projectsByTranslator);
projectsResolved = projects // translatedProjects; # attrset of projects by key which are now resolved
resolvedProjectsKeyed =
l.listToAttrs
(l.map
(proj: l.nameValuePair proj.key proj)
resolvedProjectsList);
# replace all unresolved projects with resolved ones
projectsFinal =
l.attrValues (projects // resolvedProjectsKeyed);
in in
if projectsImpureUnresolved != [] then if projectsImpureUnresolved != [] then
@ -484,7 +511,7 @@ let
${l.concatStringsSep "\n " projectsImpureUnresolvedPaths} ${l.concatStringsSep "\n " projectsImpureUnresolvedPaths}
'' ''
else else
projectsResolved; projectsFinal;
# produce outputs for a dream-lock or a source # produce outputs for a dream-lock or a source
makeOutputs = makeOutputs =
@ -554,6 +581,7 @@ in
fetchers fetchers
fetchSources fetchSources
makeOutputs makeOutputs
resolveAllProjects
riseAndShine riseAndShine
translators translators
updaters updaters

View File

@ -21,7 +21,7 @@ let
let let
nodes = l.readDir path; nodes = l.readDir path;
in in
l.optionals (nodes ? "package-lock.json") [ "package-lock" ] l.optionals (nodes ? "package-lock.json") [ "package-lock2" ]
++ l.optionals (nodes ? "yarn.lock") [ "yarn-lock" ] ++ l.optionals (nodes ? "yarn.lock") [ "yarn-lock" ]
++ [ "package-json" ]; ++ [ "package-json" ];

View File

@ -253,6 +253,8 @@ rec {
version = 2; version = 2;
inherit translate;
projectName = projectName =
{ {

View File

@ -23,7 +23,7 @@ let
defaults = { defaults = {
overridesDirs = []; overridesDirs = [];
packagesDir = "./packages"; packagesDir = "./packages";
projectRoot = "./."; projectRoot = /project/root/not/set;
repoName = null; repoName = null;
}; };
in in