Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Semver matching #127

Merged
merged 1 commit into from
Nov 7, 2020
Merged

Semver matching #127

merged 1 commit into from
Nov 7, 2020

Conversation

GregBowyer
Copy link
Contributor

@GregBowyer GregBowyer commented Jan 30, 2020

This is a little WIP, as we / I need to add unit and integration tests for this.

In reworking #123 a little, to allow for aliases to be presented in the "root" raze crate and to avoid a problem with crates presenting multiple versions of aliases I added in basic support for using the semver library to do matches for alias determination.

It occured to me, that rather than just use semver in that one specific place we should expose the richness of the semver objects into raze more generally. As such this commit exposes semver to raze and allows it to use semver for both version details and in matching configuration settings.

Semver Matching

Raze settings come in the form of a TOML section like so

[raze.crates.some-crate.'1.2.3']
some_new_setting = true

Where the version number (in the above example 1.2.3) is a literal, hardcoded
value.

This works but is a little inflexible for dependencies, especially
dependencies that are transiant and update a lot (for instance syn).

Since Cargo follows Semver we can use this fact, along with the richness of
the exported and serialisable semver::Version types to perform section
matching with Semver in the same fashion as Cargo itself.

This means that the above example can be written with semver expressions, for
example it can be written as:

[raze.crates.some-crate.'1.2.*']
some_new_setting = true

[raze.crates.some-crate.'~1.2.3']
some_new_setting = true

[raze.crates.some-crate.'^1.2.3']
some_new_setting = true

[raze.crates.some-crate.'=1.6.6']
some_new_setting = true

Note: Bare versions follow the semantics as if they had specified a ^,
which is in keeping with Cargo semver semantics but is distinct from previous
behaviour of raze (in which these would be interpreted as exacting or =).

This is deliberate as we should aim to mirror the semantics of cargo as much as
possible to avoid confusion.

We presently do not allow for multiple matches in raze settings, this is
intentional and is presented to the end user as an error.

@acmcarther
Copy link
Member

This feature looks good to me, and is more user friendly than the original implementation. I originally justified my laziness here with the assumption that overrides/settings would need to be tweaked between versions, but in practice I haven't seen this be true and it's a nuisance to manually bump these versions.

Can you rebase this off master now that #121 is merged?

@acmcarther
Copy link
Member

I'm not sure if this is waiting on me, or is stuck on something else.

Is this ready to submit? Looks like it needs a rebase.

@GregBowyer
Copy link
Contributor Author

I was going to write some unit tests but had not got around to it

@GregBowyer GregBowyer force-pushed the semver-matching branch 2 times, most recently from a7c9f59 to a578c09 Compare April 30, 2020 02:26
@GregBowyer GregBowyer force-pushed the semver-matching branch 2 times, most recently from b52ca19 to cc96241 Compare July 20, 2020 19:05
impl/src/planning.rs Outdated Show resolved Hide resolved
@UebelAndre
Copy link
Collaborator

@GregBowyer Hey, is this still relatively close to being done?

Additionally, would this allow for me to also specify the following?

[raze.crates.some-crate.'*']
some_new_setting = true

@GregBowyer
Copy link
Contributor Author

GregBowyer commented Sep 9, 2020 via email

@UebelAndre
Copy link
Collaborator

@GregBowyer Thanks! Really looking forward to this change getting in 😄

@UebelAndre
Copy link
Collaborator

@GregBowyer Hey, just a friendly poke? Do you think you'll have some time this week for this pull request? 😅

@GregBowyer
Copy link
Contributor Author

@UebelAndre its my top thing today (sorry took a while). Since you have built out an awesome test framework I can make good headway with ... some actual tests :P

@GregBowyer
Copy link
Contributor Author

Ok unit test pushed so we can take a review

Copy link
Collaborator

@dfreese dfreese left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after a rebase and some very picky nits.

impl/src/planning.rs Outdated Show resolved Hide resolved
impl/src/planning.rs Show resolved Hide resolved
@dfreese
Copy link
Collaborator

dfreese commented Nov 6, 2020

Thanks for putting this together! Assuming CI passes, I'll go ahead and release this under 0.7.0

@dfreese
Copy link
Collaborator

dfreese commented Nov 6, 2020

Thanks for putting this together! Assuming CI passes, I'll go ahead and release this under 0.7.0

The command "if [ -n "$(git status --porcelain)" ]; then 
  echo '/examples is out of date. Please run `./smoke-test.sh` locally and commit the changes' >&2
  exit 1
fi" exited with 0.

Looks like the examples need to be updated.

@GregBowyer
Copy link
Contributor Author

Just git add examples/vendored?

@UebelAndre
Copy link
Collaborator

The vendored source should be ignored

git stage examples should get you the relevant new things I think

@GregBowyer
Copy link
Contributor Author

Humm after running smoke-test then I get nothing for examples

@UebelAndre
Copy link
Collaborator

Oh, that's not the error.

cargo-raze appears to have failed to build tests

@GregBowyer
Copy link
Contributor Author

Weird ... pushed the fix

Raze settings come in the form of a [TOML] section like so

```toml
[raze.crates.some-crate.'1.2.3']
some_new_setting = True
```

Where the version number (in the above example `1.2.3`) is a literal, hardcoded
value.

This works but is a little inflexible for dependencies, _especially_
dependencies that are transiant and update a lot (for instance `syn`).

Since Cargo follows [Semver] we can use this fact, along with the richness of
the exported and serialisable `semver::Version` types to perform section
matching with [Semver] in the same fashion as Cargo itself.

This means that the above example can be written with semver expressions, for
example it can be written as:

```toml
[raze.crates.some-crate.'1.2.*']
some_new_setting = True

[raze.crates.some-crate.'~1.2.3']
some_new_setting = True

[raze.crates.some-crate.'^1.2.3']
some_new_setting = True

[raze.crates.some-crate.'=1.6.6']
some_new_setting = True
```

_Note_: Bare versions follow the semantics _as if they had_ specified a `^`,
which is in keeping with [Cargo semver semantics] but is distinct from previous
behaviour of raze (in which these would be interpreted as exacting or `=`).

This is deliberate as we should aim to mirror the semantics of cargo as much as
possible to avoid confusion.

We presently do not allow for multiple matches in raze settings, this is
intentional and is presented to the end user as an error.

[TOML]: https://github.com/toml-lang/toml
[Semver]: https://semver.org/spec/v2.0.0.html
[Cargo semver semantics]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-cratesio
@dfreese dfreese merged commit 9e82b65 into google:master Nov 7, 2020
@GregBowyer GregBowyer deleted the semver-matching branch November 7, 2020 01:39
@dfreese
Copy link
Collaborator

dfreese commented Nov 7, 2020

Released in 0.7.0

@UebelAndre
Copy link
Collaborator

@dfreese how did you deploy? Isn't there normally a commit associated with a deploy?

@dfreese
Copy link
Collaborator

dfreese commented Nov 7, 2020

@dfreese how did you deploy? Isn't there normally a commit associated with a deploy?

1b7e178. Forgot to push the commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants