Skip to content

Commit

Permalink
use Topiary's published crates over git
Browse files Browse the repository at this point in the history
Now that Topiary is published and crates.io (and tree-sitter-nickel as
well), we move away from git revision and use proper public versions for
those. Doing so, we can also crap the special casing that was done
during release to disable those dependencies and we'll now be able to
release on crates.io a version with formatting enabled.

Co-authored-by: Yann Hamdaoui <[email protected]>
  • Loading branch information
Erin van der Veen and yannham committed Jun 5, 2024
1 parent b4a3fd9 commit 83b2915
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 111 deletions.
25 changes: 15 additions & 10 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,14 @@ 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"] }
# 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" }
topiary-core = "0.4.0"
topiary-queries = { version = "0.4.0", default-features = false, features = ["nickel"] }
# This version should agree with the topiary-query version: Nickel queries
# target a specific version of the Nickel grammar (though that dependency
# doesn't appear explicitly in `topiary-queries`'s Cargo.toml file). For now you
# might have to look at Topiary's commit messages, but in a near future, we'll
# try to make this data more accessible, e.g. in the query file
tree-sitter-nickel = "0.2.0"
tempfile = "3.5.0"

[profile.dev.package.lalrpop]
Expand Down
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.
92 changes: 10 additions & 82 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 @@ -412,9 +344,12 @@ else
nix flake check

report_progress "Checks run successfully."
confirm_proceed " -- Please add the release notes to RELEASES.md if not already done. Save but don't commit. Then press 'y'."
confirm_proceed " -- Please add the release notes to RELEASES.md if not already done and save. Then press 'y'."

report_progress "Pusing the release branch..."
git add RELEASES.md
cleanup_actions+=("git reset -- ./RELEASES.md")

report_progress "Pushing the release branch..."

git commit -m "[release.sh] update to $new_workspace_version"
git push -u origin "$release_branch"
Expand Down Expand Up @@ -473,25 +408,18 @@ report_progress "Removing 'lsp-harness' from dev-dependencies..."

for crate in "${crates_to_publish[@]}"; do
# Remove `lsp-harness` from `dev-dependencies` of released crates.
# `lsp-harness` is only used for testing the LSP and isn't published on
# `lsp-harness` is only used for testing the LSP and isn't published on
# crates.io, so we cut it off as well
#
# see [^tomlq-sed]
sed -i '/^lsp-harness\.workspace\s*=\s*true$/d' "$crate/Cargo.toml"
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"
# Cargo requires to commit changes, but the last changes are temporary
# work-arounds for the crates.io release that aren't supposed to stay. we'll
# reset them later.
git commit -m "[release.sh][tmp] remove nickel-lang-utils from deps"
cleanup_actions+=("git reset --hard HEAD~")

# We have had reproducibility issues before due to the fact that when installing
Expand Down

0 comments on commit 83b2915

Please sign in to comment.