Skip to content

Commit

Permalink
Revert "Use entire workspace, begin refactor of toml munging"
Browse files Browse the repository at this point in the history
This reverts commit 79cd412.
  • Loading branch information
proski committed Feb 15, 2024
1 parent 856de6b commit 93092cd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
34 changes: 0 additions & 34 deletions overlay/mkcrate-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -317,37 +317,3 @@ cargoRelativeManifest() {

echo "${manifest_path#"$workspace_path"}"
}

sanitizeTomlForRemarshal () {
# Remarshal was failing on table names of the form:
# [key."cfg(foo = \"a\", bar = \"b\"))".path]
# The regex to find or deconstruct these strings must find, in order,
# these components: open bracket, open quote, open escaped quote, and
# their closing pairs. Because each quoted path can contain multiple
# quote escape pairs, a loop is employed to match the first quote escape,
# which the sed will replace with a single quote equivalent until all
# escaped quote pairs are replaced. The grep regex is identical to the
# sed regex but does not destructure the match into groups for
# restructuring in the replacement.
while grep '\[[^"]*"[^\\"]*\\"[^\\"]*\\"[^"]*[^]]*\]' $1; do
sed -i -r 's/\[([^"]*)"([^\\"]*)\\"([^\\"]*)\\"([^"]*)"([^]]*)\]/[\1"\2'"'"'\3'"'"'\4"\5]/g' $1
done;
}

removeTomlDeps () {
local manifestPatch="$3"
remarshal -if toml -of json $1 \
| jq "{ package: .package
, workspace: .workspace
, lib: .lib
, bin: .bin
, test: .test
, example: .example
, bench: (if \"$registry\" == \"unknown\" then .bench else null end)
}
| with_entries(select( .value != null )) \
| del( .package.workspace )
+ $manifestPatch" \
| jq "del(.[][] | nulls)" \
| remarshal -if json -of toml > $2
}
29 changes: 26 additions & 3 deletions overlay/mkcrate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,33 @@ let
if [ "$registry" != "unknown" ]; then
echo source = \"registry+''${registry}\" >> Cargo.lock
fi
mv Cargo.toml Cargo.original.toml
sanitizeTomlForRemarshal Cargo.original.toml
removeTomlDeps Cargo.original.toml Cargo.toml "$manifestPatch"
# Remarshal was failing on table names of the form:
# [key."cfg(foo = \"a\", bar = \"b\"))".path]
# The regex to find or deconstruct these strings must find, in order,
# these components: open bracket, open quote, open escaped quote, and
# their closing pairs. Because each quoted path can contain multiple
# quote escape pairs, a loop is employed to match the first quote escape,
# which the sed will replace with a single quote equivalent until all
# escaped quote pairs are replaced. The grep regex is identical to the
# sed regex but does not destructure the match into groups for
# restructuring in the replacement.
while grep '\[[^"]*"[^\\"]*\\"[^\\"]*\\"[^"]*[^]]*\]' Cargo.original.toml; do
sed -i -r 's/\[([^"]*)"([^\\"]*)\\"([^\\"]*)\\"([^"]*)"([^]]*)\]/[\1"\2'"'"'\3'"'"'\4"\5]/g' Cargo.original.toml
done;
remarshal -if toml -of json Cargo.original.toml \
| jq "{ package: .package
, lib: .lib
, bin: .bin
, test: .test
, example: .example
, bench: (if \"$registry\" == \"unknown\" then .bench else null end)
}
| with_entries(select( .value != null ))
| del( .package.workspace )
+ $manifestPatch" \
| jq "del(.[][] | nulls)" \
| remarshal -if json -of toml > Cargo.toml
'';

setBuildEnv = ''
Expand Down
6 changes: 5 additions & 1 deletion templates/Cargo.nix.tera
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ in
{%- endif -%}
};
{%- elif crate.source.Local.path %}
{%- if crate.source.Local.path == "." %}
src = fetchCrateLocal workspaceSrc;
{%- else %}
src = fetchCrateLocal (workspaceSrc + "/{{ crate.source.Local.path }}");
{%- endif %}
{%- elif crate.source.Registry.index %}
src = fetchCrateAlternativeRegistry {
index = {{ crate.source.Registry.index }};
Expand All @@ -85,7 +89,7 @@ in
};
{%- else %}
# ERROR: Could not resolve source: {{ crate.source | safe | json_encode() }}
{%- endif -%}
{% endif -%}

{%- if crate.features | length > 0 %}
features = builtins.concatLists [
Expand Down

0 comments on commit 93092cd

Please sign in to comment.