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