Hog Hog2026.2-1
project_sha.tcl
Go to the documentation of this file.
1 #!/usr/bin/env tclsh
2 # Copyright 2018-2026 The University of Birmingham
3 # Copyright 2018-2026 Max-Planck-Institute for Physics
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 # @file
18 # Get the SHA of the last commit of a specific project
19 
20 if {[catch {package require cmdline} ERROR]} {
21  puts "$ERROR\n If you are running this script on tclsh, you can fix this by installing 'tcllib'"
22  return
23 }
24 
25 set parameters {
26  {version "If set, the version is returned rather than the git sha."}
27  {ext_path.arg "" "Path to external libraries"}
28 }
29 
30 set usage "Returns the git SHA of the last commit in which the specified project was modified.\nUsage: $argv0 \[-version\] <project name>"
31 set tcl_path [file dirname [info script]]
32 set repo_path [file normalize $tcl_path/../../..]
33 source $tcl_path/../hog.tcl
34 
35 
36 if {[catch {array set options [cmdline::getoptions ::argv $parameters $usage]}] || [llength $argv] < 1} {
37  Msg Info [cmdline::usage $parameters $usage]
38  exit 1
39 } else {
40  set project [lindex $argv 0]
41  if {$options(version) == 1} {
42  set do_ver 1
43  } else {
44  set do_ver 0
45  }
46  if {$options(ext_path) == ""} {
47  set ext_path ""
48  } else {
49  set ext_path $options(ext_path)
50  }
51 }
52 set proj_dir $repo_path/Top/$project
53 
54 if {[file exists $proj_dir]} {
55  lassign [GetRepoVersions $proj_dir $repo_path $ext_path] sha ver
56  if {$do_ver == 1} {
57  set ret [HexVersionToString $ver]
58  } else {
59  set ret $sha
60  }
61 } else {
62  Msg Error "Project $project does not exist: $proj_dir not found."
63  exit
64 }
65 
66 puts $ret