6 description "Every registered tool. Usage: <tool>"
13 { ref_name "" optional}
15 { description "" optional}
16 { version "" optional}
17 { features {} optional}
19 { _source_path "" optional}
23 proc _validate_manifest {tool_name raw_dict} {
25 set norm [dict create]
26 dict for {k v} $raw_dict { dict set norm [string tolower $k] $v }
28 set result [dict create]
29 foreach field $_fields {
30 lassign $field fname fdefault frequired
31 if {[dict exists $raw_dict $fname]} {
32 dict set result $fname [dict get $raw_dict $fname]
33 }
elseif {$frequired eq "required"} {
34 error "Tool '$tool_name': missing required field '$fname'"
36 dict set result $fname $fdefault
45 proc detectActiveTool {} {
46 if {![
info exists ::env(HOG_ACTIVE_TOOL)] || $::env(HOG_ACTIVE_TOOL) eq ""} {
return ""}
51 puts "=================================================="
53 puts "=================================================="
54 set tools [
namespace children ::Tools]
55 if {[
llength $tools] == 0} {
62 puts "=================================================="
71 if {$tool_ns eq "" || [
info commands ${tool_ns}::Launch] eq ""} {
72 return -code error -errorcode {HOG_TOOL_FAILED 1} \
73 "Tool '$tool' not found or has no Launch proc"
77 set _had [
info exists ::env(HOG_ACTIVE_TOOL)]
78 set _prev [
expr {$_had ? $::env(HOG_ACTIVE_TOOL) : ""}]
79 set ::env(HOG_ACTIVE_TOOL) [
string tolower [
namespace tail $tool_ns]]
80 set _code [
catch {${tool_ns}::Launch} result _opts]
81 if {$_had} {
set ::env(HOG_ACTIVE_TOOL) $_prev}
else { unset ::env(HOG_ACTIVE_TOOL)}
87 if {[dict exists $_opts -errorcode]} {
88 set _ec [dict get $_opts -errorcode]
89 if {[
lindex $_ec 0] eq "CHILDSTATUS" && [
llength $_ec] >= 3} {
90 set _child [
lindex $_ec 2]
93 return -code error -errorcode [list HOG_TOOL_FAILED $_child] \
94 "Tool '$tool' failed (exit $_child): $result"
99 proc ResolveAlias {alias} {
100 if {$alias eq ""} {
return ""}
101 if {[
string first "::" $alias] >= 0} {
102 return [
expr {[namespace exists $alias] ? $alias : ""}]
104 set needle [
string tolower $alias]
105 foreach ns [
namespace children ::Tools] {
106 if {[
string tolower [
namespace tail $ns]] eq $needle} {
return $ns}
107 if {[
catch {
set m [${ns}::GetManifest]} err]} { continue}
108 if {[dict exists $m ref_name]} {
109 foreach iname [dict get $m ref_name] {
110 if {[
string tolower $iname] eq $needle} {
return $ns}
121 proc RegisterFromDir {dir args} {
122 Msg Debug "Loading tools from $dir"
123 if {![
file isdirectory $dir]} {
return}
124 set is_custom [
expr {"-custom" in $args}]
125 foreach sub [lsort [glob -nocomplain -type d -directory $dir *]] {
126 set tool_name [
file tail $sub]
127 set entry [
file join $sub "$tool_name.tcl"]
128 if {![
file exists $entry]} {
129 set entry [
file join $sub "main.tcl"]
131 if {![
file exists $entry]} {
132 Msg Warning "Tool directory '$tool_name' has no '$tool_name.tcl' or 'main.tcl', skipping"
140 proc _gitInfoFor {entry} {
141 set git_info { commit "unknown" date "unknown" ver "unknown" }
142 if {$entry eq ""} {
return $git_info}
144 cd [
file dirname $entry]
145 set git_ret [
GitRet [list log -n 1 --decorate "--format=commit {%h} tag {%d} date {%ad}" --date=short] .]
148 if {[
lindex $git_ret 0] == 0 && [
llength [
lindex $git_ret 1]] > 0} {
149 set git_info [
lindex $git_ret 1]
152 foreach t [
split [dict get $git_info tag] ","] {
153 set t [
string trim $t " \t()"]
154 if {$_hog_tag eq "" && [regexp {^tag:\s+(Hog\d{4}\.\d+(?:\.\d+)*)$} $t -> _found]} {
156 }
elseif {$_ver_tag eq "" && [regexp {^tag:\s+(v\d+(?:\.\d+)+)$} $t -> _found]} {
160 if {$_hog_tag ne ""} { dict set git_info ver $_hog_tag} \
161 elseif {$_ver_tag ne ""} { dict set git_info ver $_ver_tag} \
162 else { dict set git_info ver "unknown"}
170 proc RegisterTool {ns manifest_dict} {
171 set tool_name [
namespace tail $ns]
173 Msg Warning "Skipping tool '$tool_name': $validated"
176 set is_custom [
set ::Hog::_loading_custom]
177 dict set validated custom $is_custom
178 dict set validated _source_path [
set ::Hog::_loading_source]
179 dict set validated _git [
_gitInfoFor [
set ::Hog::_loading_source]]
181 namespace eval $ns [list variable Manifest $validated]
184 set tool_key [
string toupper $tool_name]
185 set tool_canon "TOOL.$tool_key"
186 set ref_aliases [
expr {[dict exists $validated ref_name] ? [dict get $validated ref_name] : {}}]
189 description [dict get $validated description] \
191 ] {*}[
expr {$is_custom ? "-custom" : ""}] -source [
set ::Hog::_loading_source]
202 proc RegisterStage {tool_ns name spec args} {
203 if {[
llength $args] > 1} {
204 Msg Warning "RegisterStage '$name': expected 'name spec ?body?'"
207 set tool_short [
string tolower [
namespace tail $tool_ns]]
208 if {[
llength $args] == 1} {
209 proc ${tool_ns}::${name} {} [
lindex $args 0]
212 set raw [dict create \
213 script "${tool_ns}::${name}" \
218 foreach k {description help aliases options produces requires} {
219 if {[dict exists $spec $k]} { dict set raw $k [dict get $spec $k]}
222 set tool_key [
string toupper [
namespace tail $tool_ns]]
223 set stage_group "TOOL.$tool_key.STAGE"
227 "Individual stages of [
namespace tail $tool_ns]'s flows.\
228 Usage: $tool_short stage <stage> <project>"]
240 proc GetToolForProject {project top_path} {
241 set conf [
file join $top_path $project hog.conf]
242 if {![
file exists $conf]} {
243 Msg Error "hog.conf not found for project '$project' at $conf"
247 set ide_name [
lindex [regexp -all -inline {\S+} $ide_name_and_ver] 0]
248 foreach ns [
namespace children ::Tools] {
249 if {[
catch {
set m [${ns}::GetManifest]} err]} { continue}
250 if {![dict exists $m ref_name]} { continue}
251 foreach iname [dict get $m ref_name] {
252 if {[
string tolower $iname] eq $ide_name} {
257 Msg Warning "No loaded tool matches IDE '$ide_name' (from $conf)"
263 proc InjectCommonProcs {tool_ns} {
264 namespace eval $tool_ns {
266 if {[
info commands Launch] eq ""} {
273 if {[
info commands Initialize] eq ""} {
274 proc Initialize {} {}
279 proc RegisterCommand {key raw_dict} {
280 set ns [
namespace current]
281 if {![dict exists $raw_dict ide]} { dict set raw_dict ide [
string tolower [
namespace tail $ns]]}
285 proc RegisterFlow {key raw_dict} {
291 proc RegisterStage {name spec args} {
295 proc GetManifest {} {
301 return [
expr {[info commands [namespace current]::${method}] ne ""}]
307 set injected {Has GetManifest _printTool}
308 set tool_name [
namespace tail [
namespace current]]
311 foreach cmd [lsort [
info commands [
namespace current]::*]] {
312 set m [
namespace tail $cmd]
313 if {$m ni $injected && [
string index $m 0] ne "_"} {
318 puts "\[$tool_name\]"
319 puts " Manifest: $Manifest"
320 puts " Methods: [
join $methods {, }]"
331 namespace eval ActiveTool {
332 variable tool "tclsh"
334 proc CurrentTool {} {
341 if {$tool_ns ne ""} {
set tool $tool_ns}