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

Inject a source identifer into moc #1631

Merged
merged 7 commits into from
Jun 21, 2020
Merged

Inject a source identifer into moc #1631

merged 7 commits into from
Jun 21, 2020

Conversation

nomeata
Copy link
Collaborator

@nomeata nomeata commented Jun 20, 2020

I have been preaching this for so long to other teams, I really better
clean up my own backyard: Make sure that you can run

moc --version

and get a somewhat useful indication what version that is. This is
important for when random people use moc from random versions of SDK
or – later – build it themselves and then provide bug reports.

When building locally, with .git around, this now injects the git
revision:

$ ./moc --version
Motoko compiler (revision 9abae15e-dirty)

(the -dirty indicates that my work-tree is not clean).

When .git is not available, as typically (and rightfully) when
building with nix, it looks if Nix’s $out variable is set, and
includes that:

$ $(nix-build -A moc)/bin/moc --version
Motoko compiler (revision 3yrjbw6g-aqppc05d-596yiq8k-bsznw5jw)

This is less useful for end-users, but it still allows us to (hopefully)
identify the version, in the worst case by running this command on all
revisions to find the right one:

$ nix-store --query --outputs $(nix-instantiate -A moc-bin)
/nix/store/3yrjbw6gaqppc05d596yiq8kbsznw5jw-moc-bin

Note that I injected dashes into the id so that it does not trip up
common.lib.standaloneRust which otherwise would take it for an
unwanted dependency.

@basvandijk suggests in
dfinity/sdk#383 (comment) that one
may query Hydra’s database to map from id to revision.

Once we do versioned releases, we can of course extend this to inject
the version number there, and use git describe --tag to have
v1.0-200-9abae15e like descriptions.

I hope this will not cause extra recompilations with dune, and will
work out-of-the box for everyone, but we’ll see.

I have been preaching this for so long to other teams, I really better
clean up my own backyard: Make sure that you can run

    moc --version

and get a somewhat useful indication what version that is. This is
important for when random people use `moc` from random versions of SDK
or – later – build it themselves and then provide bug reports.

When building locally, with `.git` around, this now injects the git
revision:

    $ ./moc --version
    Motoko compiler (revision 9abae15e-dirty)

(the `-dirty` indicates that my work-tee is not clean).

When `.git` is _not_ available, as typially (and rightfully) when
building with nix, it looks if Nix’s `$out` variable is set, and
includes that:

    ~/dfinity/motoko $ $(nix-build -A moc)/bin/moc --version
    Motoko compiler (revision xx6fmamdh5bjph9law6x02d7f4hw8f84-moc-bin)

This is less useful for end-users, but it still allows us to (hopefully)
identify the version, in the worst case by running this command on all
revisions to find the right one:

    $ nix-store --query --outputs $(nix-instantiate -A moc-bin)
    /nix/store/xx6fmamdh5bjph9law6x02d7f4hw8f84-moc-bin

Or by querying hydra (as @basvandijk suggests in
dfinity/sdk#383 (comment))

Once we do versioned releases, we can of course extend this to inject
the version number there, and use `git describe --tag` to have
`v1.0-200-9abae15e` like derscriptions.

I _hope_ this will not cause extra recompilations with `dune`, and will
work out-of-the box for everyone, but we’ll see.
@dfinity-ci
Copy link

This PR does not affect the produced WebAssembly code.

so that it will hopefully not be picked up as a “dependency”
so that it does not get picked up by `common.lib.standaloneRust`
@nomeata nomeata added the automerge-squash When ready, merge (using squash) label Jun 20, 2020
Copy link
Contributor

@ggreif ggreif left a comment

Choose a reason for hiding this comment

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

I appreciate this heroic move! Looks good to me, but since version-injection schemes are highly fragile, only time will tell. Hopefully @basvandijk can chime in for the nix parts.

@mergify mergify bot merged commit ef93e9a into master Jun 21, 2020
@mergify mergify bot deleted the joachim/embed-source-id branch June 21, 2020 21:09
@mergify mergify bot removed the automerge-squash When ready, merge (using squash) label Jun 21, 2020
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.

3 participants