Hog v10.58.0
launch.tcl
Go to the documentation of this file.
1 
2 #if {[catch {
3 ################################################################################
4 ## Set up hog environment
5 ################################################################################
6 source [file join [file dirname [info script]] hog.tcl]
8 
9 
10 ################################################################################
11 ## Resolve argv -> node/project/options (mirrors onto Launcher).
12 ################################################################################
13 set _tool [ActiveTool::CurrentTool]
14 Msg Debug "$_tool launched with arguments: $::argv"
15 
16 set request [Commands::Resolve $::argv]
17 set node [dict get $request node]
18 set typed_path [dict get $request typed_path]
19 set project [dict get $request project]
20 set project_name [dict get $request project_name]
21 
22 ################################################################################
23 ## tclsh-only (banner, env, api-mode)
24 ################################################################################
25 if {$_tool eq "tclsh"} {
26  if {$node ne "" && [Commands::Node::IsRunnable $node] && [tdict getor $node api 0]} {
27  set ::HOG_API_MODE 1
28  }
29 
30  Logo [Repo::Get repo_path]
31 
32  if {[Launcher::Get directive] eq ""} {
33  Msg Error "No directive given. Run './Hog/Do HELP' for usage."
34  exit 1
35  }
36 
37  if {[file exists [Hog::LoggerLib::GetUserFilePath "HogEnv.conf"]]} {
38  Msg Debug "HogEnv.conf found"
39  set loggerdict [Hog::LoggerLib::ParseTOML [Hog::LoggerLib::GetUserFilePath "HogEnv.conf"]]
40  set HogEnvDict [Hog::LoggerLib::GetTOMLDict]
42  }
43 }
44 
45 ################################################################################
46 ## Load the project
47 ################################################################################
48 if {$project_name ne ""} {
49  set hog_project [Projects::GetInfo $project_name [Repo::Get repo_path]]
50  if {[file exists [tdict getval $hog_project conf_path]]} {
51  Projects::LoadListFiles hog_project
52  }
53  CurrentProject::Load $hog_project
54 }
55 
56 ################################################################################
57 ## Dispatch - RunRequest runs inline or boots the right IDE, then returns a
58 ## verdict. Only the top-level entry maps that verdict to a process exit code.
59 ################################################################################
60 if {[catch {Commands::RunRequest $request} result _ropts]} {
61  Msg Error $result
62  # Tools::Launch tags a failed IDE child with {HOG_TOOL_FAILED <exit>} so we
63  # can mirror the child's status instead of flattening it to 1.
64  set _exit 1
65  if {[dict exists $_ropts -errorcode]} {
66  set _ec [dict get $_ropts -errorcode]
67  if {[lindex $_ec 0] eq "HOG_TOOL_FAILED" && [llength $_ec] >= 2} {
68  set _exit [lindex $_ec 1]
69  }
70  }
71  exit $_exit
72 }
73 switch -- [lindex $result 0] {
74  ran { exit 0 }
75  help { exit 0 }
76  usage { exit 1 }
77  boot { exit 0 }
78  default { Msg Error "Unexpected dispatch verdict: $result"; exit 1 }
79 }
80 
81 #} _hog_err _hog_opts]} {
82 # puts stderr "\nError: $_hog_err"
83 # set _hog_code [dict get $_hog_opts -errorcode]
84 # if {$_hog_code ne "NONE" && $_hog_code ne ""} { puts stderr " code: $_hog_code" }
85 # if {[info exists ::env(HOG_DEBUG)]} {
86 # puts stderr "\nStack trace:"
87 # puts stderr [dict get $_hog_opts -errorinfo]
88 # }
89 # exit 1
90 #}