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

Add buildinfo and version vars #1348

Merged
merged 1 commit into from
Jul 3, 2021
Merged

Add buildinfo and version vars #1348

merged 1 commit into from
Jul 3, 2021

Conversation

krader1961
Copy link
Contributor

Introduce builtin:buildinfo and builtin:version vars. This also
changes the -buildinfo -json implementation to use the standard
encoding/json package rather than handcrafting the JSON string.

This also fixes three incorrect spellings of "overridden". Normally I would
do those in a separate change but since there are only three instances,
one of which one was legitimately part of this change, I decided to bundle
the other two.

Introduce `builtin:buildinfo` and `builtin:version` vars. This also
changes the `-buildinfo -json` implementation to use the standard
encoding/json package rather than handcrafting the JSON string.

This also fixes three incorrect spellings of "overridden". Normally I would
do those in a separate change but since there are only three instances,
one of which one was legitimately part of this change, I decided to bundle
the other two.
if f.Version {
fmt.Fprintln(fds[1], fullVersion)
return nil
func GetBuildInfo() Buildinfo {
Copy link
Member

Choose a reason for hiding this comment

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

This needs to have a godoc, and it can be a simple var declaration instead of a function.

(If you're worried that the overridden values won't be picked up by a var declaration, those overrides happen at link time and directly modify the initial value of the variables.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. This is a function because an earlier iteration of this change had more complicated logic in a misguided attempt to normalize the components of the full version string.

Comment on lines +56 to +57
// Note: The only way this will be executed is if option -buildinfo is also present.
// See the ShouldRun() method above.
Copy link
Member

Choose a reason for hiding this comment

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

// Note: The only way this will be executed is if option -buildinfo is also present.
// See the ShouldRun() method above.

That's not true? -json -version will also trigger this code path, and this PR changes the behavior from printing the version string to printing the entire buildinfo. Neither of them is correct; the correct behavior should be printing out the version string as a JSON-encoded string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The new implementation behaves the same as the old implementation. I don't think there is a good reason to have elvish -json -version emit the version as a JSON encoded string. Consider that doing so simply turns the value into a quoted string:

> put $version | to-json
"0.16.0-dev.bfb990f932611060edc198886396076004e48c53"

Copy link
Member

Choose a reason for hiding this comment

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

Probably not very useful but consistent.

can use commands like [`keys`](./builtin.html#keys) and
[`has-key`](./builtin.html#keys) on such objects. However, unlike a normal map
it is not possible to add new keys, remove existing keys, or even assign a new
value to an existing key. In other words, a pseudo-map is immutable.
Copy link
Member

Choose a reason for hiding this comment

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

In other words, a pseudo-map is immutable.

This is potentially misleading because normal maps are also immutable. The "mutation" operation supported by normal maps create copies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, normal maps are also technically immutable but can be mutated using assoc explicitly or implicitly via magic LHS syntax. A pseudo-map cannot be mutated by assoc. That subtlety should probably be clarified but I couldn't see a way to word this that didn't hide the most important point of this paragraph.

Copy link
Member

Choose a reason for hiding this comment

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

This concept is sometimes called "nondestructive mutation" but that concept would require its own paragraph to explain. The doc now says "it is currently not possible to create a modified version of an existing pseudo-map".

@xiaq xiaq merged commit 3ba0397 into elves:master Jul 3, 2021
xiaq added a commit that referenced this pull request Jul 3, 2021
@krader1961 krader1961 deleted the version-var branch July 4, 2021 02:45
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.

None yet

2 participants