mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
all: implement @VCURRENTHASH
to replace C.V_CURRENT_COMMIT_HASH
(#19514)
This commit is contained in:
parent
1512486d01
commit
32bb8cf86d
8 changed files with 20 additions and 13 deletions
|
@ -5533,6 +5533,9 @@ that are substituted at compile time:
|
|||
- `@VEXEROOT` => will be substituted with the *folder*,
|
||||
where the V executable is (as a string).
|
||||
- `@VHASH` => replaced with the shortened commit hash of the V compiler (as a string).
|
||||
- `@VCURRENTHASH` => Similar to `@VHASH`, but changes when the compiler is
|
||||
recompiled on a different commit (after local modifications, or after
|
||||
using git bisect etc).
|
||||
- `@VMOD_FILE` => replaced with the contents of the nearest v.mod file (as a string).
|
||||
- `@VMODROOT` => will be substituted with the *folder*,
|
||||
where the nearest v.mod file is (as a string).
|
||||
|
|
|
@ -50,7 +50,7 @@ fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
|
|||
eprintln(' function: ${fn_name}()')
|
||||
eprintln(' message: ${s}')
|
||||
eprintln(' file: ${file}:${line_no}')
|
||||
eprintln(' v hash: ${@VHASH}')
|
||||
eprintln(' v hash: ${@VHASH}') // TODO: use @VCURRENTHASH when bootstrapped
|
||||
eprintln('=========================================')
|
||||
$if native {
|
||||
C.exit(1) // TODO: native backtraces
|
||||
|
@ -104,7 +104,7 @@ pub fn panic(s string) {
|
|||
} $else {
|
||||
eprint('V panic: ')
|
||||
eprintln(s)
|
||||
eprintln('v hash: ${@VHASH}')
|
||||
eprintln('v hash: ${@VHASH}') // TODO: use @VCURRENTHASH when bootstrapped
|
||||
$if native {
|
||||
C.exit(1) // TODO: native backtraces
|
||||
} $else $if exit_after_panic_message ? {
|
||||
|
|
|
@ -133,6 +133,8 @@ mut:
|
|||
goto_labels map[string]ast.GotoLabel // to check for unused goto labels
|
||||
enum_data_type ast.Type
|
||||
fn_return_type ast.Type
|
||||
|
||||
v_current_commit_hash string // same as V_CURRENT_COMMIT_HASH
|
||||
}
|
||||
|
||||
pub fn new_checker(table &ast.Table, pref_ &pref.Preferences) &Checker {
|
||||
|
@ -145,6 +147,7 @@ pub fn new_checker(table &ast.Table, pref_ &pref.Preferences) &Checker {
|
|||
pref: pref_
|
||||
timers: util.new_timers(should_print: timers_should_print, label: 'checker')
|
||||
match_exhaustive_cutoff_limit: pref_.checker_match_exhaustive_cutoff_limit
|
||||
v_current_commit_hash: version.githash(pref_.building_v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3368,6 +3371,9 @@ fn (mut c Checker) at_expr(mut node ast.AtExpr) ast.Type {
|
|||
.vhash {
|
||||
node.val = version.vhash()
|
||||
}
|
||||
.v_current_hash {
|
||||
node.val = c.v_current_commit_hash
|
||||
}
|
||||
.vmod_file {
|
||||
// cache the vmod content, do not read it many times
|
||||
if c.vmod_file_content.len == 0 {
|
||||
|
|
|
@ -282,9 +282,8 @@ fn (e Eval) error(msg string) {
|
|||
}
|
||||
|
||||
fn (e Eval) panic(s string) {
|
||||
commithash := unsafe { tos5(&char(C.V_CURRENT_COMMIT_HASH)) }
|
||||
eprintln('V panic: ${s}')
|
||||
eprintln('V hash: ${commithash}')
|
||||
eprintln('V hash: ${@VCURRENTHASH}')
|
||||
e.print_backtrace()
|
||||
exit(1)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import v.ast
|
|||
import v.token
|
||||
import v.pref
|
||||
import v.util
|
||||
import v.util.version
|
||||
import v.depgraph
|
||||
import encoding.base64
|
||||
import v.gen.js.sourcemap
|
||||
|
@ -247,7 +246,7 @@ pub fn gen(files []&ast.File, table &ast.Table, pref_ &pref.Preferences) string
|
|||
// deps_resolved := graph.resolve()
|
||||
// nodes := deps_resolved.nodes
|
||||
|
||||
mut out := g.definitions.str() + g.hashes()
|
||||
mut out := g.definitions.str()
|
||||
if !g.pref.output_es5 {
|
||||
out += '\nlet wasmExportObject;\n'
|
||||
|
||||
|
@ -491,12 +490,6 @@ pub fn (mut g JsGen) init() {
|
|||
g.definitions.writeln('function ReturnException(val) { this.val = val; }')
|
||||
}
|
||||
|
||||
pub fn (g JsGen) hashes() string {
|
||||
mut res := '// V_COMMIT_HASH ${version.vhash()}\n'
|
||||
res += '// V_CURRENT_COMMIT_HASH ${version.githash(g.pref.building_v)}\n'
|
||||
return res
|
||||
}
|
||||
|
||||
[noreturn]
|
||||
fn verror(msg string) {
|
||||
eprintln('jsgen error: ${msg}')
|
||||
|
|
|
@ -8,6 +8,9 @@ import v.util
|
|||
|
||||
fn (mut g Gen) expr(node ast.Expr) {
|
||||
match node {
|
||||
ast.AtExpr {
|
||||
g.allocate_string(g.comptime_at(node), 3, .rel32)
|
||||
}
|
||||
ast.ParExpr {
|
||||
g.expr(node.expr)
|
||||
}
|
||||
|
|
|
@ -352,6 +352,7 @@ fn (mut p Parser) at() ast.AtExpr {
|
|||
'@FILE_LINE' { token.AtKind.file_path_line_nr }
|
||||
'@LOCATION' { token.AtKind.location }
|
||||
'@COLUMN' { token.AtKind.column_nr }
|
||||
'@VCURRENTHASH' { token.AtKind.v_current_hash }
|
||||
'@VHASH' { token.AtKind.vhash }
|
||||
'@VMOD_FILE' { token.AtKind.vmod_file }
|
||||
'@VEXE' { token.AtKind.vexe_path }
|
||||
|
|
|
@ -173,6 +173,7 @@ pub enum AtKind {
|
|||
line_nr
|
||||
column_nr
|
||||
vhash
|
||||
v_current_hash
|
||||
vmod_file
|
||||
vmodroot_path
|
||||
vroot_path // obsolete
|
||||
|
@ -187,7 +188,8 @@ pub const (
|
|||
.unsigned_right_shift_assign]
|
||||
|
||||
valid_at_tokens = ['@VROOT', '@VMODROOT', '@VEXEROOT', '@FN', '@METHOD', '@MOD', '@STRUCT',
|
||||
'@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH', '@VMOD_FILE', '@FILE_LINE', '@LOCATION']
|
||||
'@VEXE', '@FILE', '@LINE', '@COLUMN', '@VHASH', '@VCURRENTHASH', '@VMOD_FILE', '@FILE_LINE',
|
||||
'@LOCATION']
|
||||
|
||||
token_str = build_token_str()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue