remove deprecated interfaces:

- makeOutputs
- translators.translators
This commit is contained in:
DavHau 2022-04-20 16:58:38 +02:00
parent f1f1633804
commit 34f1ff3e23
4 changed files with 7 additions and 231 deletions

View File

@ -233,57 +233,6 @@
else fetchedSources;
};
makeDreamLockForSource = {
source,
translator ? null,
translatorArgs ? {},
} @ args: let
sourceSpec =
if b.isString args.source && ! lib.isStorePath args.source
then fetchers.translateShortcut {shortcut = args.source;}
else {
type = "path";
path = args.source;
};
source = fetchers.fetchSource {source = sourceSpec;};
t = let
translator = translators.findOneTranslator {
inherit source;
translatorName = args.translator or null;
};
in
if b.elem translator.type ["pure" "ifd"]
then translator
else
throw ''
All comaptible translators are impure and therefore require
pre-processing the input before evaluation.
Use the CLI to add this package:
nix run .# -- add ...
'';
dreamLock' =
translators.translators."${t.subsystem}"."${t.type}"."${t.name}".translate
(translatorArgs
// {
inherit source;
});
dreamLock = let
defaultPackage = dreamLock'._generic.defaultPackage;
defaultPackageVersion = dreamLock'._generic.packages."${defaultPackage}";
in
lib.recursiveUpdate dreamLock' {
sources."${defaultPackage}"."${defaultPackageVersion}" = {
type = "path";
path = "${source}";
};
};
in
dreamLock;
# build a dream lock via a specific builder
callBuilder = {
builder,
@ -386,7 +335,7 @@
formattedOutputs;
riseAndShine = throw ''
Use makeOutputs instead of riseAndShine.
`riseAndShine` is deprecated. See usage in readme.md.
'';
makeOutputsForDreamLock = {
@ -653,62 +602,6 @@
projectOutputs;
in
mergedOutputs;
# produce outputs for a dream-lock or a source
makeOutputs = {
source, # source tree or dream-lock
builder ? null,
fetcher ? null,
inject ? {},
sourceOverrides ? oldSources: {},
packageOverrides ? {},
builderArgs ? {},
translator ? null,
translatorArgs ? {},
} @ args: let
dreamLock' =
# in case of a dream-lock.json file or dream-lock attributes
if
(lib.isAttrs args.source && args.source ? _generic && args.source ? _subsytem)
|| lib.hasSuffix "dream-lock.json" source
then args.source
# input is a source tree -> generate the dream-lock
else makeDreamLockForSource {inherit source translator translatorArgs;};
# parse dreamLock
dreamLockLoaded = utils.readDreamLock {dreamLock = dreamLock';};
dreamLock = dreamLockLoaded.lock;
dreamLockInterface = dreamLockLoaded.interface;
# sub packages
builderOutputsSub =
b.mapAttrs
(dirName: dreamLock:
makeOutputs
(args // {source = dreamLock.lock;}))
dreamLockInterface.subDreamLocks;
builderOutputs =
makeOutputsForDreamLock
((b.removeAttrs args ["source"])
// {
inherit dreamLock;
});
allOutputs =
{subPackages = builderOutputsSub;}
//
# merge with sub package outputs
b.foldl'
(old: new:
old
// {
packages = new.packages or {} // old.packages;
})
builderOutputs
(b.attrValues builderOutputsSub);
in
allOutputs;
in {
inherit
apps
@ -717,7 +610,6 @@ in {
dream2nixWithExternals
fetchers
fetchSources
makeOutputs
realizeProjects
translateProjects
riseAndShine

View File

@ -17,45 +17,15 @@
l = lib // builtins;
# transforms V1 translators to V2 translators
ensureTranslatorV2 = translator: let
version = translator.version or 1;
cleanedArgs = args: l.removeAttrs args ["project" "tree"];
upgradedTranslator =
translator
// (lib.optionalAttrs (translator ? translate) {
translate = args: let
dreamLock =
translator.translate
((cleanedArgs args)
// {
source = "${args.source}/${args.project.relPath}";
name = args.project.name;
});
in
dreamLock
// {
_generic =
dreamLock._generic
// {
location = args.project.relPath;
};
};
});
finalTranslator =
if version == 2
then translator
else upgradedTranslator;
in
finalTranslator
// (lib.optionalAttrs (finalTranslator ? translate) {
ensureTranslatorV2 = translator:
translator
// (lib.optionalAttrs (translator ? translate) {
translateBin =
wrapPureTranslator2
(with translator; [subsystem type name]);
# ensure `tree` is passed
translate = args:
finalTranslator.translate (
translator.translate (
args
// args.project.subsystemInfo
// {
@ -65,39 +35,9 @@
);
});
# transforms V2 translators to V1 translators
ensureTranslatorV1 = translator: let
version = translator.version or 1;
downgradeTranslator =
translator
// (lib.optionalAttrs (translator ? translate) {
translate = args:
translator.translate (args
// {
inherit (args) source;
tree = dlib.prepareSourceTree {inherit (args) source;};
project = {
name = translator.projectName {inherit (args) source;};
relPath = "";
subsystem = translator.subsystem;
};
});
});
finalTranslator =
if version == 1
then translator
else downgradeTranslator;
in
finalTranslator;
makeTranslatorV2 = translatorModule:
ensureTranslatorV2 (makeTranslator translatorModule);
makeTranslatorV1 = translatorModule:
ensureTranslatorV1 (makeTranslator translatorModule);
makeTranslator = translatorModule: let
translator =
translatorModule
@ -118,7 +58,7 @@
// args
);
translateBin =
wrapPureTranslator
wrapPureTranslator2
(with translatorModule; [subsystem type name]);
})
# for impure translators:
@ -133,8 +73,6 @@
in
translator;
translators = dlib.translators.mapTranslators makeTranslatorV1;
translatorsV2 = dlib.translators.mapTranslators makeTranslatorV2;
# adds a translateBin to a pure translator
@ -183,56 +121,8 @@
bin.overrideAttrs (old: {
name = "translator-${lib.concatStringsSep "-" translatorAttrPath}";
});
# adds a translateBin to a pure translator
wrapPureTranslator = translatorAttrPath: let
bin =
utils.writePureShellScript
[
coreutils
jq
nix
python3
]
''
jsonInputFile=$(realpath $1)
outputFile=$(jq '.outputFile' -c -r $jsonInputFile)
nix eval \
--option experimental-features "nix-command flakes"\
--show-trace --impure --raw --expr "
let
dream2nix = import ${dream2nixWithExternals} {};
translatorArgs =
(builtins.fromJSON
(builtins.unsafeDiscardStringContext (builtins.readFile '''$1''')));
dreamLock =
dream2nix.translators.translators.${
lib.concatStringsSep "." translatorAttrPath
}.translate
translatorArgs;
in
dream2nix.utils.dreamLock.toJSON
# don't use nix to detect cycles, this will be more efficient in python
(dreamLock // {
_generic = builtins.removeAttrs dreamLock._generic [ \"cyclicDependencies\" ];
})
" | python3 ${../apps/cli/format-dream-lock.py} > out
tmpOut=$(realpath out)
cd $WORKDIR
mkdir -p $(dirname $outputFile)
cp $tmpOut $outputFile
'';
in
bin.overrideAttrs (old: {
name = "translator-${lib.concatStringsSep "-" translatorAttrPath}";
});
in {
inherit
translators
translatorsV2
;

View File

@ -59,9 +59,6 @@
${translators.translatorsV2.nodejs.pure.package-lock.translateBin} $TMPDIR/newJsonInput
'';
# inherit projectName function from package-lock translator
projectName = dlib.translators.translators.nodejs.pure.package-lock.projectName;
# This allows the framework to detect if the translator is compatible with the given input
# to automatically select the right translator.
compatible = {source}:
@ -69,7 +66,7 @@
# inherit options from package-lock translator
extraArgs =
dlib.translators.translators.nodejs.pure.package-lock.extraArgs
dlib.translators.translatorsV2.nodejs.pure.package-lock.extraArgs
// {
npmArgs = {
description = "Additional arguments for npm";

View File

@ -315,9 +315,6 @@ in {
inherit translate;
# inherit projectName function from package-lock translator
projectName = dlib.translators.translators.nodejs.pure.package-lock.projectName;
# This allows the framework to detect if the translator is compatible with the given input
# to automatically select the right translator.
compatible = {source}: