refactor: writePureShellScript: don't change to WORKDIR

Reverting a bad design choice.
This lead to weird effects if scripts are nested.
This commit is contained in:
DavHau 2022-08-20 18:37:08 +02:00
parent 027083be7d
commit f347034b2b
15 changed files with 18 additions and 28 deletions

View File

@ -200,6 +200,8 @@
]
''
echo "check for correct formatting"
WORKDIR=$(realpath ./.)
cd $TMPDIR
cp -r $WORKDIR ./repo
cd ./repo
${self.apps.${system}.format.program} --fail-on-change

View File

@ -10,7 +10,6 @@
utils.writePureShellScript
[nix]
''
cd $WORKDIR
nix ''${@:1:$#-1} --impure --expr "
let
nixpkgs = <nixpkgs>;

View File

@ -8,8 +8,6 @@ utils.writePureShellScriptBin
"index"
[coreutils]
''
cd $WORKDIR
usage="usage:
$0 INDEXER_NAME INDEXER_INPUT"

View File

@ -15,8 +15,6 @@ in
"translate-index"
[coreutils translate jq parallel]
''
cd $WORKDIR
usage="usage:
$0 INDEX_PATH TARGET_DIR"

View File

@ -20,8 +20,6 @@ utils.writePureShellScriptBin
moreutils
]
''
cd $WORKDIR
usage="usage:
$0 SOURCE_SHORTCUT TARGET_DIR"

View File

@ -621,7 +621,6 @@ in let
"resolve"
[]
''
cd $WORKDIR
${l.concatStringsSep "\n"
(l.mapAttrsToList
(title: script: ''

View File

@ -9,8 +9,6 @@
utils.writePureShellScript
[coreutils curl jq]
''
cd $WORKDIR
input=''${1:?"please provide an input as a JSON file"}
outFile=$(jq '.outputFile' -c -r $input)

View File

@ -33,8 +33,6 @@ libraries.io also supports other interesting popularity metrics:
utils.writePureShellScript
[coreutils curl jq]
''
cd $WORKDIR
input=''${1:?"please provide an input as a JSON file"}
outFile=$(jq '.outputFile' -c -r $input)

View File

@ -9,8 +9,6 @@
utils.writePureShellScript
[coreutils curl jq]
''
cd $WORKDIR
input=''${1:?"please provide an input as a JSON file"}
outFile=$(jq '.outputFile' -c -r $input)

View File

@ -35,11 +35,12 @@
jsonInput=$1
# read the json input
outputFile=$(jq '.outputFile' -c -r $jsonInput)
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInput))
source=$(jq '.source' -c -r $jsonInput)
relPath=$(jq '.project.relPath' -c -r $jsonInput)
npmArgs=$(jq '.project.subsystemInfo.npmArgs' -c -r $jsonInput)
pushd $TMPDIR
cp -r $source/* ./
chmod -R +w ./
newSource=$(pwd)
@ -60,7 +61,7 @@
jq ".source = \"$newSource\"" -c -r $jsonInput > $TMPDIR/newJsonInput
cd $WORKDIR
popd
${subsystems.nodejs.translators.package-lock.translateBin} $TMPDIR/newJsonInput
'';

View File

@ -36,7 +36,7 @@ in {
jsonInput=$1
# read the json input
outputFile=$WORKDIR/$(jq '.outputFile' -c -r $jsonInput)
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInput))
source="$(jq '.source' -c -r $jsonInput)/$(jq '.project.relPath' -c -r $jsonInput)"
name="$(jq '.project.name' -c -r $jsonInput)"
pythonAttr=$(jq '.pythonAttr' -c -r $jsonInput)
@ -44,6 +44,8 @@ in {
sitePackages=$(nix eval --impure --raw --expr "(import <nixpkgs> {}).$pythonAttr.sitePackages")
pushd $TMPDIR
# build python and pip executables
tmpBuild=$(mktemp -d)
nix build \
@ -87,7 +89,7 @@ in {
cd ./source
export NAME=$name
export VERSION=$($python ./setup.py --version 2>/dev/null)
cd $WORKDIR
popd
$python ${./generate-dream-lock.py} $tmp $jsonInput
rm -rf $tmp $tmpBuild

View File

@ -28,11 +28,12 @@
jsonInput=$1
# read the json input
outputFile=$(jq '.outputFile' -c -r $jsonInput)
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInput))
source=$(jq '.source' -c -r $jsonInput)
relPath=$(jq '.project.relPath' -c -r $jsonInput)
cargoArgs=$(jq '.project.subsystemInfo.cargoArgs | select (.!=null)' -c -r $jsonInput)
pushd $TMPDIR
cp -r $source/* ./
chmod -R +w ./
newSource=$(pwd)
@ -43,7 +44,7 @@
cargoResult=$?
jq ".source = \"$newSource\"" -c -r $jsonInput > $TMPDIR/newJsonInput
cd $WORKDIR
popd
if [ $cargoResult -eq 0 ]; then
${subsystems.rust.translators.cargo-lock.translateBin} $TMPDIR/newJsonInput

View File

@ -34,7 +34,9 @@
]
''
jsonInputFile=$(realpath $1)
outputFile=$WORKDIR/$(jq '.outputFile' -c -r $jsonInputFile)
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInputFile))
pushd $TMPDIR
nix eval \
--option experimental-features "nix-command flakes"\
@ -62,7 +64,7 @@
" | python3 ${../apps/cli/format-dream-lock.py} > out
tmpOut=$(realpath out)
cd $WORKDIR
popd
mkdir -p $(dirname $outputFile)
cp $tmpOut $outputFile
'';

View File

@ -63,10 +63,11 @@ in {
jsonInput=$1
# read the json input
outputFile=$WORKDIR/$(jq '.outputFile' -c -r $jsonInput)
outputFile=$(realpath -m $(jq '.outputFile' -c -r $jsonInput))
source=$(jq '.source' -c -r $jsonInput)
relPath=$(jq '.project.relPath' -c -r $jsonInput)
cd $TMPDIR
# TODO:
# read input files/dirs and produce a json file at $outputFile
# containing the dream lock similar to /src/specifications/dream-lock-example.json

View File

@ -101,10 +101,8 @@ in
export PATH="${lib.makeBinPath availablePrograms}"
export NIX_PATH=nixpkgs=${pkgs.path}
export WORKDIR="$PWD"
TMPDIR=$(${coreutils}/bin/mktemp -d)
cd $TMPDIR
${script}
@ -120,10 +118,8 @@ in
export PATH="${lib.makeBinPath availablePrograms}"
export NIX_PATH=nixpkgs=${pkgs.path}
export WORKDIR="$PWD"
TMPDIR=$(${coreutils}/bin/mktemp -d)
cd $TMPDIR
${script}
@ -214,7 +210,6 @@ in
''
dreamLockPath="${project.dreamLockPath}"
cd $WORKDIR
${translator.translateBin} ${argsJsonFile}
# aggregate source hashes