init translatorV2 downwards compatibility

This commit is contained in:
DavHau 2022-02-27 14:07:51 +07:00
parent 0ba71a6d1b
commit 14954c7d14
3 changed files with 34 additions and 8 deletions

View File

@ -428,7 +428,7 @@ let
discoveredProjects = dlib.discoverers.discoverProjects { inherit tree; };
getTranslator = subsystem: translatorName:
translators.translatorsV2."${subsystem}".all."${translatorName}";
translators.translators."${subsystem}".all."${translatorName}";
isImpure = project: translatorName:
(getTranslator project.subsystem translatorName).type == "impure";

View File

@ -232,7 +232,7 @@ let
# like nixpkgs recursiveUpdateUntil, but with the depth as a stop condition
recursiveUpdateUntilDepth = depth: lhs: rhs:
lib.recursiveUpdateUntil (path: l: r: (l.length path) > depth) lhs rhs;
lib.recursiveUpdateUntil (path: _: _: (l.length path) > depth) lhs rhs;
sanitizeDerivationName = name:
lib.replaceStrings [ "@" "/" ] [ "__at__" "__slash__" ] name;

View File

@ -19,7 +19,7 @@ let
l = lib // builtins;
# transforms all V1 translators to V2 translators
# transforms V1 translators to V2 translators
ensureTranslatorV2 = translator:
let
version = translator.version or 1;
@ -29,12 +29,11 @@ let
translator // {
translate = args:
l.map
(proj: proj // {
dreamLock = translator.translate
(proj:
translator.translate
((cleanedArgs args) // {
source = "${args.source}${proj.relPath}";
});
})
}))
args.projects;
};
in
@ -43,10 +42,37 @@ let
else
upgradedTranslator;
# transforms V2 translators to V1 translators
ensureTranslatorV1 = translator:
let
version = translator.version or 1;
downgradeTranslator =
translator // {
translate = args:
translator.translate (args // {
inherit (args) source;
tree = dlib.prepareSourceTree { inherit (args) source; };
projects = [{
name = translator.projectName { inherit (args) source; };
relPath = "";
subsystem = translator.subsystem;
}];
});
};
in
if version == 1 then
translator
else
downgradeTranslator;
makeTranslatorV2 = translatorModule:
ensureTranslatorV2 (makeTranslator translatorModule);
makeTranslatorV1 = translatorModule:
ensureTranslatorV1 (makeTranslator translatorModule);
makeTranslator =
translatorModule:
@ -90,7 +116,7 @@ let
translatorWithDefaults;
translators = dlib.translators.mapTranslators makeTranslator;
translators = dlib.translators.mapTranslators makeTranslatorV1;
translatorsV2 = dlib.translators.mapTranslators makeTranslatorV2;