forked from vlang/v
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
774253e
commit 736067d
Showing
8 changed files
with
425 additions
and
61 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
Module { | ||
name: 'semver' | ||
version: '0.4.5' | ||
version: '0.4.6' | ||
deps: [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
module version | ||
|
||
import os | ||
|
||
pub const v_version = '0.4.6' | ||
|
||
pub fn full_hash() string { | ||
build_hash := vhash() | ||
current_hash := @VCURRENTHASH | ||
if build_hash == current_hash { | ||
return build_hash | ||
} | ||
return '${build_hash}.${current_hash}' | ||
} | ||
|
||
// full_v_version() returns the full version of the V compiler | ||
pub fn full_v_version(is_verbose bool) string { | ||
if is_verbose { | ||
return 'V ${version.v_version} ${full_hash()}' | ||
} | ||
return 'V ${version.v_version} ${@VCURRENTHASH}' | ||
} | ||
|
||
// githash tries to find the current git commit hash for the specified | ||
// project path by parsing the relevant files in its `.git/` folder. | ||
pub fn githash(path string) !string { | ||
// .git/HEAD | ||
git_head_file := os.join_path(path, '.git', 'HEAD') | ||
if !os.exists(git_head_file) { | ||
return error('failed to find `${git_head_file}`') | ||
} | ||
// 'ref: refs/heads/master' ... the current branch name | ||
head_content := os.read_file(git_head_file) or { | ||
return error('failed to read `${git_head_file}`') | ||
} | ||
current_branch_hash := if head_content.starts_with('ref: ') { | ||
rev_rel_path := head_content.replace('ref: ', '').trim_space() | ||
rev_file := os.join_path(path, '.git', rev_rel_path) | ||
// .git/refs/heads/master | ||
if !os.exists(rev_file) { | ||
return error('failed to find revision file `${rev_file}`') | ||
} | ||
// get the full commit hash contained in the ref heads file | ||
os.read_file(rev_file) or { return error('failed to read revision file `${rev_file}`') } | ||
} else { | ||
head_content | ||
} | ||
desired_hash_length := 7 | ||
return current_branch_hash[0..desired_hash_length] or { | ||
error('failed to limit hash `${current_branch_hash}` to ${desired_hash_length} characters') | ||
} | ||
} |