Skip to content

Commit

Permalink
use topiary's published crates over git
Browse files Browse the repository at this point in the history
  • Loading branch information
ErinvanderVeen committed May 17, 2024
1 parent 8d88d63 commit d1949a2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 106 deletions.
20 changes: 12 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void = "1"
metrics = "0.21"
metrics-util = "0.15"

topiary-core = { git = "https://github.com/tweag/topiary.git", rev = "82a94a9f57104b89d4316afaeeab271cc51f7698", package = "topiary-core" }
topiary-queries = { git = "https://github.com/tweag/topiary.git", rev = "82a94a9f57104b89d4316afaeeab271cc51f7698", package = "topiary-queries", default-features = false, features = ["nickel"] }
topiary-core = "0.4.0"
topiary-queries = { version = "0.4.0", default-features = false, features = ["nickel"] }
# This should be kept in sync with the revision in topiary
tree-sitter-nickel = { git = "https://github.com/nickel-lang/tree-sitter-nickel", rev = "58baf89db8fdae54a84bcf22c80ff10ee3f929ed" }
tempfile = "3.5.0"
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ highlighting and NLS.

#### Formatting

**Warning**: because the cargo registry (crates.io) requires that all
dependencies of Nickel are published there as well, the `format` feature isn't
enabled when installing nickel with `cargo install` as of Nickel version 1.5.0.
In this case, please use [Topiary](https://github.com/tweag/topiary/) separately
to format Nickel source code.

To format one or several Nickel source files, use `nickel format`:

```console
Expand Down
9 changes: 0 additions & 9 deletions lsp/nls/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ it in VSCode, (Neo)Vim and Emacs.

## Formatting Capabilities

**Warning**: because the cargo registry (crates.io) requires that all
dependencies of Nickel are published there as well, the format feature isn't
enabled when installing nls with `cargo install` as of NLS version 1.3.0. In
this case, to enable formatting in NLS, you have to make the `topiary`
executable available in your `PATH`. Please follow [Topiary's setup
instructions](https://github.com/tweag/topiary#installing) and ensure in
particular that the environment variable `TOPIARY_LANGUAGE_DIR` is correctly set
(this is covered in the setup instructions).

Formatting in `nls` is currently based on
[Topiary](https://github.com/tweag/topiary), used as a library. No configuration
or external dependencies are necessary.
81 changes: 0 additions & 81 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,74 +178,6 @@ update_dependencies() {
done
}

# Currently, topiary isn't published on crates.io, so we can't publish crates
# that depend on it.
#
# The version released on the stable branch, the release branch and in the
# GitHub release should support the format feature, but the version published on
# crates.io can't, for the time being.
#
# For cargo to accept to publish our crates, we have to remove the "format"
# feature from the list of features and from the list of default features, as
# well as removing all the dependencies enabled by this feature (even if they
# aren't used anymore, their mere presence in `Cargo.toml` without them being
# available on crates.io is forbidden by cargo).
remove_format_feature() {
local path_cargo_toml
local tmpfile

path_cargo_toml="$1"
tmpfile="$path_cargo_toml.tmp"
local -a deps_to_remove

cleanup_actions+=('git restore '"$path_cargo_toml")

# We first extract the list of dependencies that are required by the format
# feature, because we'll need to remove them all (it'll include topiary, but
# might not be limited to it)
#
# We filter out dependencies (as `format = [..]` can also contain features,
# such as `nickel-lang-core/format`), and then remove the `dep:` prefix.
readarray -t deps_to_remove < <(tomlq -r '(.features.format | .[] | select(startswith("dep:")) | sub("dep:";""))' "$path_cargo_toml")

# see [^tomlq-sed]
# Removing the format feature is a bit more complicated than handling
# version numbers, because the format feature is a list of strings, so we
# resort to a stronger weapon: awk
#
# The following script looks for the `[features]` section, then for the
# `default` key and remove "format" from the list of default features. It
# also removes the feature format key (and its value) itself from the
# [features] section.
awk -F'[\n= ]+' '
{
if($0 ~ /^\[features\]$/) {
a=1
}
else if(a==1 && $1=="format") {
next
}
else if(a==1 && $0 ~ /^default ?= ?\[/) {
gsub(/, *"format"|"format" *,?/,"")
}
else if(a==1 && $0 ~ /^$/) {
a=0
}
}
1' "$path_cargo_toml" > "$tmpfile" && mv "$tmpfile" "$path_cargo_toml"

# We remove all dependencies required by the format feature that we just
# removed
for dep in "${deps_to_remove[@]}"; do
# see [^tomlq-sed]
report_progress "Removing dependency $dep from $path_cargo_toml"
sed -i '/^'"$dep"'\s*=\s*{.*}$/d' "$path_cargo_toml"
done

git add "$path_cargo_toml"
cleanup_actions+=('git reset -- '"$path_cargo_toml")
}

print_usage_and_exit() {
echo "Usage: $0 <major|minor|patch>" >&2
exit 1
Expand Down Expand Up @@ -481,19 +413,6 @@ for crate in "${crates_to_publish[@]}"; do
cleanup_actions+=('git restore '"$crate/Cargo.toml")
done

report_progress "Remove the format feature and topiary dependencies..."

for crate in "${crates_to_publish[@]}"; do
remove_format_feature "$crate/Cargo.toml"

git add "$crate/Cargo.toml"
cleanup_actions+=('git reset -- '"$crate/Cargo.toml")
done

# Cargo requires to commit changes, but we'll reset them later
git commit -m "[release.sh][tmp] remove nickel-lang-utils and topiary from deps"
cleanup_actions+=("git reset --hard HEAD~")

# We have had reproducibility issues before due to the fact that when installing
# the version of say `nickel-lang-cli` from crates.io, Cargo doesn't pick the
# current workspace file `Cargo.lock`, but regenerates a fresh one. This can
Expand Down

0 comments on commit d1949a2

Please sign in to comment.