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

Use dune-build-info to compute version number #1133

Merged
merged 1 commit into from
Sep 9, 2020

Conversation

emillon
Copy link
Collaborator

@emillon emillon commented Nov 7, 2019

This switches the handling of --version using dune-build-info instead of a script.

Here is how it works.

The version string is resolved in the following way:

  • if (version) is set in (dune-project), it is used.
    This is what happens when using opam pins (through dune subst), or for released versions (through dune-release).
  • otherwise, a description from git describe will be used.
    Caveat for this case: binaries under _build/default will not have this information, but dune install --prefix _install will copy a valid binary under _install/bin.

(see #454)

@emillon
Copy link
Collaborator Author

emillon commented Nov 7, 2019

We'll discuss the implementation later but I'm curious to hear if that's compatible with your vendoring use cases @jberdine & @ceastlund?

@emillon emillon mentioned this pull request Nov 7, 2019
@ceastlund
Copy link

We currently override the version information anyway, because we use neither dune nor git internally at present. Once we move from jenga to dune I suspect this will work fine for us.

src/Version.mli Outdated Show resolved Hide resolved
ocamlformat.opam Show resolved Hide resolved
@jberdine
Copy link
Collaborator

jberdine commented Nov 12, 2019 via email

@emillon emillon force-pushed the dune-build-info branch 2 times, most recently from 7ff1c3f to a4c53ba Compare November 13, 2019 09:32
@jberdine
Copy link
Collaborator

jberdine commented Nov 16, 2019 via email

@Julow
Copy link
Collaborator

Julow commented Nov 18, 2019

Are you using version strings of the form 0.12-25-g6bdc881 in your .ocamlformat files ?
Yes, we at least currently can't use any released version.
To support that, we could match the version depending on the precision given by the user: If we use version strings of the form a.b.c-commit: • 0.12 matches any 0.12.- • 0.12.0 matches only 0.12.0-* • 0.12-hash match precisely one commit: 0.12.*-hash
IIUC doing that would make it impossible to e.g. depend on exactly the released 0.12 version, as the binary does not know it's commit hash (it could be built from a tarball rather than a git checkout) in order to check it against the specified version.

Hashes are for dev binaries that are passed around. 0.12.0 would match only one possible version for opam users. For users who built the binary, any build between 0.12.0 and 0.12.1 (excluded) would be allowed, on purpose.

@jberdine
Copy link
Collaborator

jberdine commented Nov 18, 2019 via email

@Julow
Copy link
Collaborator

Julow commented Nov 18, 2019

I see. Allowing a range of versions may not be a good idea because even a very small regression or bug fix can change formatting.
For the compiler/OMP issue, we should test that and increase the constraints if necessary.

@Julow Julow closed this Nov 18, 2019
@Julow Julow reopened this Nov 18, 2019
@jberdine
Copy link
Collaborator

jberdine commented Nov 18, 2019 via email

@jberdine
Copy link
Collaborator

It would be nice to revive this to simplify the version management and implement it in a more common way. Is there anything blocking this now?

One addition I would like to see to help testing and development if nothing else, is a version-stamped binary in a stable/reliable path. Perhaps something like a make target implemented using something like:

(executable
 (name ocamlformat)
 (promote until_clean)
 ...)

@emillon
Copy link
Collaborator Author

emillon commented May 14, 2020

It seems that there are two distincts problems here:

  • where to get info about the current binary (is it a release one, does it come from git, etc)
  • what is the semantics of version numbers

For the second one, it seems that there's a distinction to be made between the tool version (release vs git vs vendored vs patched) and the behavior version (the thing that is checked by version=). This PR is about the first one; I opened #1363 to suggest the beginning of a solution to the second one, but that's not the whole story.

@emillon emillon requested a review from gpetiot May 14, 2020 12:11
@emillon emillon marked this pull request as ready for review May 14, 2020 12:11
@emillon emillon changed the title WIP: use dune-build-info to compute version number Use dune-build-info to compute version number May 14, 2020
@jberdine
Copy link
Collaborator

I think that this is almost ready. Could you rebase and run make headers? Also, it would address the caveat currently noted in Version.mli if this PR added dune clause to promote the binary into the source tree. I think that should be done as part of this PR. The question of how to get a version number to automatically always change other than from git should be left for another PR.

@gpetiot
Copy link
Collaborator

gpetiot commented Jun 22, 2020

I rebased and updated the headers. But dune install --prefix _install does not set the correct version for me (only unknown)

@emillon
Copy link
Collaborator Author

emillon commented Jun 22, 2020

do you mean when running the binary that's copied under _install ?

@gpetiot
Copy link
Collaborator

gpetiot commented Jun 22, 2020

Yes this binary returns an unknown version.

@gpetiot
Copy link
Collaborator

gpetiot commented Jun 30, 2020

The stamping issue I reported happens on linux. But I didn't observe the dune warning you got.

@jberdine
Copy link
Collaborator

jberdine commented Jul 1, 2020

This will need to add a version constraint for dune > 2.6.0 to make sure to pull in ocaml/dune#3599.

@gpetiot gpetiot added the no changelog set this to bypass the CI check for changelog entries label Jul 2, 2020
@gpetiot gpetiot force-pushed the dune-build-info branch from a785182 to f41f244 Compare July 2, 2020 09:51
@gpetiot
Copy link
Collaborator

gpetiot commented Jul 2, 2020

I rebased and added the constraint on the dune-build-info version, there is still a quirk causing the version number to be 0.14.1-... instead of 0.14.2-... but it's because I messed the last release.

@jberdine
Copy link
Collaborator

jberdine commented Jul 2, 2020 via email

@emillon
Copy link
Collaborator Author

emillon commented Jul 2, 2020

Have you git pulled the tags recently? As far as I can tell, I fixed that a bit ago with some retagging.

You pushed a lightweight tag and not an annotated tag (produced by git tag -a). dune-build-info expects this kind of tags, compared to what gen_version.mlt used to do. (dune-release will do the right thing)

Also I think in general it's better not to try fixing these errors, as moving tags can break more things down the line.

Copy link
Collaborator

@gpetiot gpetiot left a comment

Choose a reason for hiding this comment

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

Everything looks good to me.

@gpetiot gpetiot requested a review from jberdine July 2, 2020 13:25
Makefile Outdated
install:
dune build @install
dune install --prefix _install
dune install
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is this expected to run install twice?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also had this question, seems like the second dune install should be removed.

ocamlformat.opam Outdated Show resolved Hide resolved
@jberdine
Copy link
Collaborator

jberdine commented Jul 2, 2020 via email

@emillon
Copy link
Collaborator Author

emillon commented Jul 2, 2020

They will be wrong with dune-build-info < 2.7.0 if you use a flambda switch, yes. But that's not specific to ocamlformat so I'm not sure that this fix should live in ocamlformat metadata. I suppose we can wait until there's a fix available in dune for flambda users, and maybe in the meantime add conflicts between existing versions of dune-build-info and flambda.

@emillon
Copy link
Collaborator Author

emillon commented Jul 3, 2020

Actually as pointed in the corresponding bug, it's only a problem on 4.10.0+flambda, and it's dune that you need to upgrade, not dune-build-info.
In terms of releases, we're in a situation where dune is waiting for an ocamlformat release compatible with base 0.14 for the test suite to run on recent versions of base, and this PR needs an unreleased dune to be useful to 4.10.0+flambda users, so let's keep this PR out of the next ocamlformat release and include it in the next one.

Copy link
Collaborator

@jberdine jberdine left a comment

Choose a reason for hiding this comment

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

Ok, that plan sounds good. For now I'll mark this as changes requested as we'll need to update once dune 2.7 is released. There is another question, which whether to also delay merging #1361 until after this one. I don't have a strong view either way, but #1361 doesn't seem to be urgent and delaying would avoid the opam template file business. What do others think?

Makefile Outdated
install:
dune build @install
dune install --prefix _install
dune install
Copy link
Collaborator

Choose a reason for hiding this comment

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

I also had this question, seems like the second dune install should be removed.

ocamlformat.opam Outdated Show resolved Hide resolved
@emillon
Copy link
Collaborator Author

emillon commented Jul 6, 2020

Seems good to batch this with #1361.

About bound, yes we just need to depend on dune-build-info and bumping the dune dependency to >= 2.7. To do this we can either add an explicit bound or use (lang dune 2.7) in dune-project.

@jberdine jberdine added this to the 0.16.0 milestone Jul 11, 2020
@emillon
Copy link
Collaborator Author

emillon commented Aug 25, 2020

I rebased and fixed the opam metadata now that there is a dune version with a fix available.

Two remaining questions:

  • should we remove the second dune install in the make target? (I think so, I don't think it makes sense to install at both places at the same time)
  • is it ok to just add an opam bound, or should we bump to (lang dune 2.7) as well? the latter would ensure that we keep the same metadata when merging Dunify release #1361 (and we'll need lang dune 2.7 to try cram tests anyway)

@gpetiot
Copy link
Collaborator

gpetiot commented Aug 27, 2020

Bumping the dnue language version sounds good to me. About the double install rule I think I did that because it was necessary to have the substitution working to have the right version number. Don't know if I missed something or if it was a bug that is fixed now, if only one install works we can simplify it of course.

@emillon
Copy link
Collaborator Author

emillon commented Aug 27, 2020

There's no need for any make install target at all in normal operation. So that's up to us to define the semantics if we want this target :)

This uses dune-build-info to compute the version number.

It will be resolved in the following way:

- if (version) is set in (dune-project), it is used. This is what happens
  when using opam pins (through dune subst), or for released versions
  (through dune-release).
- otherwise, a description from [git describe] will be used. Caveat for
  this case: binaries under [_build/] will not have this information, but
  [dune install --prefix _install] will copy a valid binary under
  [_install/bin].

We require at least dune 2.7, since `dune-build-info` is broken on
flambda switches before this version.

See ocaml/dune#3599
@emillon
Copy link
Collaborator Author

emillon commented Sep 9, 2020

I removed the makefile changes, we can add them once we have a concrete use case. Thanks!

@emillon emillon merged commit 66b6b3a into ocaml-ppx:master Sep 9, 2020
@emillon emillon deleted the dune-build-info branch September 9, 2020 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog set this to bypass the CI check for changelog entries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants