Hog v10.58.0
hog.tcl
Go to the documentation of this file.
1 namespace eval Hog {
2  variable _loading_custom 0
3  variable _loading_source ""
4  variable _initialized 0
5 
6  variable _tcl_path [file normalize [file join [file dirname [info script]] ..]]
7 
8  # set context, source in the global namespace, reset context.
9  # label, if given, is folded into the warning on failure for extra
10  # info a generic message can't have (e.g. which tool directory a file belongs to).
11  proc SourceFile {file is_custom {label ""}} {
12  variable _loading_custom
13  variable _loading_source
14  set _loading_custom $is_custom
15  set _loading_source $file
16  if {[catch {namespace eval :: [list source $file]} err]} {
17  set _for [expr {$label ne "" ? " for $label" : ""}]
18  Msg Warning "failed to source [file tail $file]$_for: $err"
19  }
20  set _loading_custom 0
21  set _loading_source ""
22  }
23 
24  # Entry point to run a command/flow internally
25  # mirrors how one would run it from the cmdline:
26  # 'Hog::Do vivado create -option example' == './Hog/Do vivado create -option example'
27  # Lets one tool run another tool's command/flow
28  proc Do {args} {
29  set _wrapper [file join [Repo::Get repo_path] Hog Do]
30 
31  set ::env(HOG_LOGO_PRINTED) 1
32  Msg Info "Running sub process: $args"
33  set _code [catch {exec -ignorestderr $_wrapper {*}$args >@ stdout 2>@ stderr} _res _opts]
34  if {$_code} {
35  set _exit 1
36  if {[dict exists $_opts -errorcode]} {
37  set _ec [dict get $_opts -errorcode]
38  if {[lindex $_ec 0] eq "CHILDSTATUS" && [llength $_ec] >= 3} {
39  set _exit [lindex $_ec 2]
40  }
41  }
42  return -code error -errorcode [list HOG_SPAWN_FAILED $_exit] \
43  "Hog::Spawn $args failed (exit $_exit): $_res"
44  }
45  return $_res
46  }
47 }
48 
49 # Loads every core module, discovers tools/commands/flows
50 # Populates the Repo/Launcher/CurrentProject DataStores.
51 # Allows resourcing without wiping live state
52 proc InitHog {} {
53  if {$::Hog::_initialized} { return }
54  set ::Hog::_initialized 1
55 
56  set tcl_path $::Hog::_tcl_path
57  set repo_path [file normalize [file join $tcl_path .. ..]]
58  set top_path [file join $repo_path Top]
59 
60  source [file join $tcl_path hog.tcl]
61  source [file join $tcl_path core datastore.tcl]
62  source [file join $tcl_path create_project.tcl]
63  source [file join $tcl_path core listfile.tcl]
64  source [file join $tcl_path core project.tcl]
65  source [file join $tcl_path core tobj.tcl]
66  source [file join $tcl_path core commands.tcl]
67  source [file join $tcl_path core tools.tcl]
68  source [file join $tcl_path core flow.tcl]
69 
70  if {[catch {package require cmdline} ERROR]} {
71  Msg Debug "The cmdline Tcl package was not found, sourcing it from Hog..."
72  source $tcl_path/utils/cmdline.tcl
73  }
74 
75  ################################################################################
76  ## Tool Discovery
77  ################################################################################
78  Tools::RegisterFromDir [file join $tcl_path tools]
79  Tools::RegisterFromDir [file join $repo_path hog-tools] -custom
81 
82  ################################################################################
83  ## Flows
84  ################################################################################
85  # Custom flows load after tools, so their parent tool groups already exist.
86  Flow::RegisterCustomFlows $repo_path/hog-flows
87 
88  ################################################################################
89  ## Command Registration
90  ################################################################################
91  Commands::RegisterCommandsDir [file join $tcl_path commands]
92  Commands::RegisterCommandsDir [file join $repo_path hog-commands] -custom
93 
94  ################################################################################
95  ## DataStores
96  ################################################################################
98  DataStore::create Launcher
99  DataStore::create CurrentProject
100  namespace eval CurrentProject {
101  proc GetProjectObj {} { variable _ctx; return $_ctx }
102  }
103 
104  Launcher::Set Name "Experimental"
105  Launcher::Set Version "0.1.0"
106  Launcher::Set time [clock format [clock seconds] -format "%Y-%m-%d %H:%M:%S"]
107  Launcher::Set script [file normalize [info script]]
108  Launcher::Set Git [lindex [Git --version] 2]
109  Launcher::Set HogTag [Git {describe --tags --always}]
110 
111  set _old_dir [pwd]
112  cd $repo_path
113  Repo::Set Tag [Git {describe --tags --always}]
114  cd $_old_dir
115 
116  Repo::Set repo_path $repo_path
117  Repo::Set tcl_path $tcl_path
118  Repo::Set top_path $top_path
119  Repo::Set pre_synth [file normalize "${tcl_path}/integrated/pre-synthesis.tcl"]
120  Repo::Set post_synth [file normalize "${tcl_path}/integrated/post-synthesis.tcl"]
121  Repo::Set pre_impl [file normalize "${tcl_path}/integrated/pre-implementation.tcl"]
122  Repo::Set post_impl [file normalize "${tcl_path}/integrated/post-implementation.tcl"]
123  Repo::Set pre_bit [file normalize "${tcl_path}/integrated/pre-bitstream.tcl"]
124  Repo::Set post_bit [file normalize "${tcl_path}/integrated/post-bitstream.tcl"]
125  Repo::Set quartus_post_module [file normalize "${tcl_path}/integrated/quartus-post-module.tcl"]
126  Repo::Set config_path [file normalize [file join $top_path repo.conf]]
127  Repo::Set config [tdict create]
128  if {[file exists [Repo::Get config_path]]} {
129  set PROPERTIES [ReadConf [Repo::Get config_path]]
130  dict for {section content} $PROPERTIES {
131  Repo::Set config $section [tdict create]
132  dict for {key val} $content {
133  Msg Debug "Setting property $key to $val for section $section"
134  Repo::Set config $section $key $val
135  }
136  }
137  }
138 
139  Repo::Set projects_dir [file join $repo_path Projects]
140  Repo::Set projects [Projects::GetAll $repo_path]
141 
142  ################################################################################
143  ## Lint
144  ################################################################################
146 }