basechip 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +32 -0
- data/LICENSE.txt +14 -0
- data/README.rdoc +19 -0
- data/VERSION +1 -0
- data/bin/basechip +25 -0
- data/collateral/block/block.rb.erb +20 -0
- data/collateral/configuration/configuration.rb.erb +19 -0
- data/collateral/project/Gemfile +19 -0
- data/collateral/project/gitignore +6 -0
- data/collateral/project/project.rb.erb +76 -0
- data/collateral/project/settings.rb.erb +26 -0
- data/collateral/recipes/icarus.rb +73 -0
- data/collateral/recipes/icarus.rb.erb +88 -0
- data/collateral/recipes/local_cluster.rb +27 -0
- data/lib/array.rb +26 -0
- data/lib/base_chip/action.rb +309 -0
- data/lib/base_chip/base.rb +105 -0
- data/lib/base_chip/block.rb +75 -0
- data/lib/base_chip/bom.rb +75 -0
- data/lib/base_chip/bom_file.rb +45 -0
- data/lib/base_chip/cli.rb +371 -0
- data/lib/base_chip/cluster.rb +93 -0
- data/lib/base_chip/cluster_type.rb +45 -0
- data/lib/base_chip/code_area.rb +30 -0
- data/lib/base_chip/configuration.rb +257 -0
- data/lib/base_chip/dsl.rb +593 -0
- data/lib/base_chip/exit_error.rb +20 -0
- data/lib/base_chip/generator_menu.rb +64 -0
- data/lib/base_chip/git.rb +32 -0
- data/lib/base_chip/hierarchy.rb +84 -0
- data/lib/base_chip/install_menu.rb +89 -0
- data/lib/base_chip/ipc.rb +50 -0
- data/lib/base_chip/list_menu.rb +134 -0
- data/lib/base_chip/menu.rb +70 -0
- data/lib/base_chip/out_file.rb +68 -0
- data/lib/base_chip/permutation.rb +26 -0
- data/lib/base_chip/permute.rb +25 -0
- data/lib/base_chip/post.rb +26 -0
- data/lib/base_chip/problem.rb +33 -0
- data/lib/base_chip/project.rb +472 -0
- data/lib/base_chip/requirement.rb +26 -0
- data/lib/base_chip/runable.rb +36 -0
- data/lib/base_chip/source_language.rb +40 -0
- data/lib/base_chip/source_type.rb +24 -0
- data/lib/base_chip/statistic.rb +27 -0
- data/lib/base_chip/task.rb +21 -0
- data/lib/base_chip/task_master.rb +50 -0
- data/lib/base_chip/taskable.rb +77 -0
- data/lib/base_chip/tasker.rb +260 -0
- data/lib/base_chip/test.rb +202 -0
- data/lib/base_chip/test_list.rb +120 -0
- data/lib/base_chip/tool.rb +51 -0
- data/lib/base_chip/tool_version.rb +34 -0
- data/lib/base_chip/top_menu.rb +203 -0
- data/lib/base_chip/track_state.rb +61 -0
- data/lib/base_chip.rb +215 -0
- data/lib/dir.rb +30 -0
- data/lib/reporting.rb +97 -0
- metadata +215 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'base_chip/tool_version'
|
18
|
+
|
19
|
+
module BaseChip
|
20
|
+
class Tool
|
21
|
+
include Dsl
|
22
|
+
include Base
|
23
|
+
define_settings({:select_version => [ String ],
|
24
|
+
:default_version => [ String ]})
|
25
|
+
define_children({:tool_version => ToolVersion})
|
26
|
+
|
27
|
+
def configure
|
28
|
+
return if @configured
|
29
|
+
super
|
30
|
+
@select_version ||= @default_version
|
31
|
+
if selected_version
|
32
|
+
selected_version.configure
|
33
|
+
else
|
34
|
+
fault "Selected version '#{@select_version}' for tool '#{@name}' in '#{parent.full_name}' doesn't exist"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
def selected_version
|
38
|
+
@selected_version ||= @versions[@select_version] if @versions
|
39
|
+
end
|
40
|
+
def path(str=:crazy_default_value)
|
41
|
+
if str == :crazy_default_value
|
42
|
+
@path ||= (selected_version && selected_version.path)
|
43
|
+
else
|
44
|
+
@path = str
|
45
|
+
end
|
46
|
+
end
|
47
|
+
def available_versions
|
48
|
+
versions.keys if versions
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'base_chip/test_list'
|
18
|
+
|
19
|
+
module BaseChip
|
20
|
+
class ToolVersion
|
21
|
+
include Dsl
|
22
|
+
include Base
|
23
|
+
define_settings({:install => [ Array , String ],
|
24
|
+
:packages => [ Hash ],
|
25
|
+
:path => [ Hash ]})
|
26
|
+
#define_children({:action => Action })
|
27
|
+
|
28
|
+
def configure
|
29
|
+
return if @configured
|
30
|
+
@path = "#{@project.shared_directory}/tools/#{tool.name}/#{@name}"
|
31
|
+
super
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,203 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'base_chip/menu'
|
18
|
+
module BaseChip
|
19
|
+
class TopMenu < Menu
|
20
|
+
include Cli
|
21
|
+
def ready_workload(*args)
|
22
|
+
@targets = args
|
23
|
+
BaseChip.load_environment
|
24
|
+
@project = BaseChip.project
|
25
|
+
@project.ready(@targets) if @targets.size > 0
|
26
|
+
end
|
27
|
+
|
28
|
+
option :yes , :description=>"Accept defaults on any posed questions", :type=>:boolean, :alias=>[:y]
|
29
|
+
option :modes, :description=>"Enable predefined modes" , :type=>:string , :alias=>[:m]
|
30
|
+
|
31
|
+
desc "Create a new project"
|
32
|
+
option :git, :description=>"Set up as a git repository", :type=>:boolean, :alias=>[:g,:r,:repo]
|
33
|
+
def init(project_name)
|
34
|
+
BaseChip.project = project_name
|
35
|
+
BaseChip.root = "./#{project_name}"
|
36
|
+
FileUtils.mkdir_p BaseChip.root
|
37
|
+
BaseChip.build_directory_structure(BaseChip.root, BaseChip.project_directories)
|
38
|
+
BaseChip.erb_template "#{BaseChip::GEM_DIR}/collateral/project/settings.rb.erb", "#{BaseChip.root}/base_chip/settings.rb"
|
39
|
+
FileUtils.cp "#{BaseChip::GEM_DIR}/collateral/project/gitignore" , "#{BaseChip.root}/.gitignore"
|
40
|
+
FileUtils.cd BaseChip.root
|
41
|
+
|
42
|
+
if options.git
|
43
|
+
system "git init ."
|
44
|
+
system "git add ./base_chip ./.gitignore"
|
45
|
+
system "git commit -m 'Initial automated project build by BaseChip.' ."
|
46
|
+
|
47
|
+
normal "Your project has been created.\n" +
|
48
|
+
"Your next step is probably to generate a block.\n" +
|
49
|
+
"You can learn more by entering your newly created directory, and typing:\n" +
|
50
|
+
" basechip help generate block"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Generate a block, tool, testbench, etc"
|
55
|
+
sub_command :generate, GeneratorMenu
|
56
|
+
|
57
|
+
desc 'Install a recipe, plugin, or tool'
|
58
|
+
sub_command :install, InstallMenu
|
59
|
+
|
60
|
+
desc "List blocks, actions, tools, tests, etc"
|
61
|
+
long "If 'pattern' is given as a string, it must completely match the name of the block/action/test/test_list\n" +
|
62
|
+
" or one of it's parents. If surrounded by '/', the pattern will be considered a regular expression\n" +
|
63
|
+
" and will be compared to the full name of the item including it's parents' names separated by colons."
|
64
|
+
sub_command :list, ListMenu
|
65
|
+
|
66
|
+
desc 'Execute targets'
|
67
|
+
full_usage 'basechip <targets+> [options]'
|
68
|
+
default
|
69
|
+
option :work_dir , :description=>"Working directory other than cwd" , :type=>:string , :alias=>[:w]
|
70
|
+
option :max_fails , :description=>"Working directory other than cwd" , :type=>:string , :alias=>[:f]
|
71
|
+
option :max_passes , :description=>"Working directory other than cwd" , :type=>:string , :alias=>[:p]
|
72
|
+
option :repeat , :description=>"Repeat each test 'r' times" , :type=>:integer, :alias=>[:r]
|
73
|
+
option :jobs , :description=>"Number of jobs, and for which cluster", :type=>:string , :alias=>[:j]
|
74
|
+
option :seed , :description=>"Root seed for all actions" , :type=>:integer, :alias=>[:s]
|
75
|
+
option :client_of , :description=>"Internal use only" , :type=>:string
|
76
|
+
option :client_id , :description=>"Internal use only" , :type=>:integer
|
77
|
+
option :opc , :description=>"Internal use only" , :type=>:string
|
78
|
+
option :opi , :description=>"Internal use only" , :type=>:string
|
79
|
+
def exec(*args)
|
80
|
+
begin
|
81
|
+
fault "Repeat is a planned feature" if BaseChip.options.repeat
|
82
|
+
|
83
|
+
args << 'all' if options.client_of && args.size == 0
|
84
|
+
ready_workload(*args)
|
85
|
+
|
86
|
+
@project.enable_tracking(options.opc,options.opi) if options.opc
|
87
|
+
@project.tasker.clusters = @project.dereference_clusters
|
88
|
+
@project.tasker.client_of = options.client_of
|
89
|
+
@project.tasker.client_id = options.client_id || 0
|
90
|
+
|
91
|
+
if options.client_of
|
92
|
+
@project.tasker.run
|
93
|
+
else
|
94
|
+
if @targets.size > 0
|
95
|
+
begin
|
96
|
+
@project.run_all_readied
|
97
|
+
# @project.track_complete 'pass'
|
98
|
+
rescue Reporting::Fault => e
|
99
|
+
# @project.track_complete 'fail', e.message
|
100
|
+
exit 1
|
101
|
+
rescue RuntimeError => e
|
102
|
+
# @project.track_complete 'fail', e.message
|
103
|
+
p e
|
104
|
+
raise e
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
rescue Interrupt # quetly handle the interrupt of clients
|
109
|
+
raise unless options.client_of
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
desc 'rerun targets. Some output remains'
|
114
|
+
def rerun(bundle_path)
|
115
|
+
fault "#{bundle_path} does not exist" unless File.exist?(bundle_path)
|
116
|
+
case bundle_path
|
117
|
+
when /(.*)\.tgz$/
|
118
|
+
puts "Unzipping #{bundle_path}"
|
119
|
+
system "tar -zxvf #{bundle_path}"
|
120
|
+
bundle_path = $1
|
121
|
+
end
|
122
|
+
fault "#{bundle_path}/rerun.yaml does not exist" unless File.exist?("#{bundle_path}/rerun.yaml")
|
123
|
+
rerun_hash = YAML.load(File.read("#{bundle_path}/rerun.yaml"))
|
124
|
+
BaseChip.options.seed ||= rerun_hash['seed' ]
|
125
|
+
BaseChip.options.modes ||= rerun_hash['modes']
|
126
|
+
BaseChip.options. append_arguments = (BaseChip.options. append_arguments || []) + (rerun_hash[' append_arguments'] || [])
|
127
|
+
BaseChip.options.replace_arguments = (BaseChip.options.replace_arguments || []) + (rerun_hash['replace_arguments'] || [])
|
128
|
+
BaseChip.options. append_arguments = nil if BaseChip.options. append_arguments.empty?
|
129
|
+
BaseChip.options.replace_arguments = nil if BaseChip.options.replace_arguments.empty?
|
130
|
+
ready_workload(rerun_hash['full_name'])
|
131
|
+
@project.workload.first.directory "#{@project.workload.first.directory}.rerun"
|
132
|
+
@project.run_all_readied
|
133
|
+
end
|
134
|
+
|
135
|
+
desc 'Clean targets. Some output remains'
|
136
|
+
usage '<targets+> [options]'
|
137
|
+
def clean(*args)
|
138
|
+
ready_workload(*args)
|
139
|
+
@project.workload.each do |w|
|
140
|
+
w.clean
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
desc 'Destroy all output relate to targets'
|
145
|
+
usage '<targets+> [options]'
|
146
|
+
def clobber(*args)
|
147
|
+
ready_workload(*args)
|
148
|
+
@project.workload.each do |w|
|
149
|
+
w.clobber
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# desc 'Return completion options for a command'
|
154
|
+
# def complete
|
155
|
+
# args = BaseChip.options. append_arguments
|
156
|
+
# current = BaseChip.options.replace_arguments[0]
|
157
|
+
# args.shift
|
158
|
+
|
159
|
+
# out = []
|
160
|
+
# tasks = TopMenu.cli.tasks.keys.map{|s|s.to_s}
|
161
|
+
|
162
|
+
# # if args.empty?
|
163
|
+
# # if current
|
164
|
+
# # tasks = TopMenu.cli.tasks.keys.map{|s|s.to_s}
|
165
|
+
# # if tasks.include? current
|
166
|
+
# # puts current
|
167
|
+
# # return
|
168
|
+
# # end
|
169
|
+
# # else
|
170
|
+
# # if tasks.include? current
|
171
|
+
# # puts current
|
172
|
+
# # return
|
173
|
+
# # end
|
174
|
+
# # end
|
175
|
+
# # end
|
176
|
+
# # case args[0]
|
177
|
+
# # when (*%w{clean clobber})
|
178
|
+
# # out += BaseChip.blocks.map{|b|b.name}
|
179
|
+
# # else
|
180
|
+
# # ready_workload('all')
|
181
|
+
# # out += TopMenu.cli.tasks.keys
|
182
|
+
# # out += BaseChip.blocks.map{|b|b.name}
|
183
|
+
# # end
|
184
|
+
|
185
|
+
# if self.class.workload_commands.include? argv[0]
|
186
|
+
# ready_workload('all')
|
187
|
+
# if current
|
188
|
+
# else
|
189
|
+
# out += BaseChip.blocks.map{|b|b.name.to_s}.keep_if{|b| b=~ /^#{current}/}
|
190
|
+
# end
|
191
|
+
# end
|
192
|
+
# puts out.join(" ")
|
193
|
+
# end
|
194
|
+
# def self.workload_commands
|
195
|
+
# return @@workload_commands if @@workload_commands
|
196
|
+
# @@workload_commands = [nil]
|
197
|
+
# self.cli.tasks.each do |k,v|
|
198
|
+
# @@workload_commands << k.to_s if v.usage =~ /targets/
|
199
|
+
# end
|
200
|
+
# @@workload_commands
|
201
|
+
# end
|
202
|
+
end
|
203
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'base_chip/problem'
|
18
|
+
module BaseChip
|
19
|
+
module TrackState
|
20
|
+
def self.included mod
|
21
|
+
mod.extend TrackState::ClassMethods
|
22
|
+
mod.class_eval do
|
23
|
+
include TrackState::InstanceMethods
|
24
|
+
attr_accessor :state
|
25
|
+
attr_accessor :problem
|
26
|
+
attr_accessor :problems
|
27
|
+
end
|
28
|
+
end
|
29
|
+
module ClassMethods
|
30
|
+
end
|
31
|
+
module InstanceMethods
|
32
|
+
def pass! ; @state ||= 'pass' end
|
33
|
+
def warning!(f,s); np(f,s); @state = 'warning' if @state.nil? or @state.pass? end
|
34
|
+
def error!( f,s); np(f,s); @state = (@state =~ /fault/) ? 'error && fault' : 'error' end
|
35
|
+
def fault!( f,s); np(f,s); @state = (@state =~ /error/) ? 'error && fault' : 'fault' end
|
36
|
+
|
37
|
+
def pass? ; @state == 'pass' end
|
38
|
+
def warning? ; @state == 'warning' end
|
39
|
+
def error? ; @state =~ /fault/ end
|
40
|
+
def fault? ; @state =~ /error/ end
|
41
|
+
|
42
|
+
def np(file,signature)
|
43
|
+
return if @problem
|
44
|
+
@problem = Problem.new
|
45
|
+
@problem.file = file
|
46
|
+
@problem.signature = signature
|
47
|
+
@problem
|
48
|
+
end
|
49
|
+
|
50
|
+
def take_state(thing)
|
51
|
+
return if @problem
|
52
|
+
@state = thing.state
|
53
|
+
@problem = thing.problem
|
54
|
+
end
|
55
|
+
|
56
|
+
def first_error ; @problem && @problem.to_s end
|
57
|
+
def first_signature ; @problem && @problem.signature end
|
58
|
+
def first_problem_file ; @problem && @problem.file end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/base_chip.rb
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'fileutils'
|
18
|
+
require 'open3'
|
19
|
+
require 'erb'
|
20
|
+
# require "bundler/setup"
|
21
|
+
|
22
|
+
require 'archive/tar/minitar'
|
23
|
+
require 'active_support/inflector'
|
24
|
+
require 'dir'
|
25
|
+
|
26
|
+
require 'base_chip/ipc.rb'
|
27
|
+
require 'base_chip/taskable'
|
28
|
+
require 'base_chip/task'
|
29
|
+
require 'base_chip/tasker'
|
30
|
+
require 'base_chip/task_master'
|
31
|
+
|
32
|
+
require 'base_chip/cli'
|
33
|
+
require 'base_chip/base'
|
34
|
+
require 'base_chip/dsl'
|
35
|
+
require 'base_chip/tool'
|
36
|
+
require 'base_chip/project'
|
37
|
+
require 'base_chip/generator_menu'
|
38
|
+
require 'base_chip/list_menu'
|
39
|
+
require 'base_chip/install_menu'
|
40
|
+
require 'base_chip/top_menu'
|
41
|
+
require 'base_chip/git'
|
42
|
+
module BaseChip
|
43
|
+
include Reporting
|
44
|
+
|
45
|
+
RANDOM_NAME_PIECES = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
|
46
|
+
RANDOM_NAME_PIECES_SIZE = RANDOM_NAME_PIECES.size
|
47
|
+
def self.random_string(size=10)
|
48
|
+
str = ''
|
49
|
+
size.times do
|
50
|
+
str += RANDOM_NAME_PIECES[rand(RANDOM_NAME_PIECES_SIZE)]
|
51
|
+
end
|
52
|
+
str
|
53
|
+
end
|
54
|
+
|
55
|
+
GEM_DIR = File.expand_path('../..', File.realpath(__FILE__))
|
56
|
+
def self.root=(root) ; @root = root ; end
|
57
|
+
def self.root ; @root ; end
|
58
|
+
def self.project=(project) ; @project = project ; end
|
59
|
+
|
60
|
+
@@options = OpenStruct.new
|
61
|
+
def self.options
|
62
|
+
@@options
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.find_root(dir = nil, passive=false)
|
66
|
+
dir ||= @work_dir ||= Dir.pwd
|
67
|
+
@dirs_to_top = []
|
68
|
+
loop do
|
69
|
+
@dirs_to_top << dir
|
70
|
+
break if File.exist? dir + '/base_chip/settings.rb'
|
71
|
+
|
72
|
+
if dir == '/'
|
73
|
+
return nil if passive
|
74
|
+
fault "Couldn't find file 'base_chip/settings.rb' in any directory above #{Dir.pwd}.\n" +
|
75
|
+
"'base_chip/settings.rb' is expected to reside at the top of the checked " +
|
76
|
+
"out project, and is generated using the command 'base_chip init'."
|
77
|
+
end
|
78
|
+
dir = File.expand_path(dir + '/../')
|
79
|
+
end
|
80
|
+
$project_root = @root = dir
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.build_directory_structure(dir, array)
|
84
|
+
array.each do |subdir|
|
85
|
+
FileUtils.mkdir_p dir + "/" + subdir
|
86
|
+
end
|
87
|
+
end
|
88
|
+
def self.erb_template(in_file, out_file)
|
89
|
+
erb = ERB.new(File.read in_file)
|
90
|
+
erb.filename = in_file
|
91
|
+
File.open(out_file,'w') do |f|
|
92
|
+
f.print(erb.result)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def self. project_directories ; @@project_directories end
|
97
|
+
def self. block_directories ; @@block_directories end
|
98
|
+
def self.configuration_directories ; @@configuration_directories end
|
99
|
+
@@common_directories = %w{
|
100
|
+
base_chip/tools
|
101
|
+
base_chip/recipes
|
102
|
+
base_chip/actions
|
103
|
+
base_chip/test_lists
|
104
|
+
documentation
|
105
|
+
} # base_chip/configurations questionable FIXME
|
106
|
+
@@configuration_directories =
|
107
|
+
@@common_directories +
|
108
|
+
%w{
|
109
|
+
rtl/verilog
|
110
|
+
rtl/headers
|
111
|
+
rtl/vhdl
|
112
|
+
rtl/systemc
|
113
|
+
gates
|
114
|
+
testbench/verilog
|
115
|
+
testbench/headers
|
116
|
+
testbench/classes
|
117
|
+
testbench/vhdl
|
118
|
+
testbench/systemc
|
119
|
+
synthesis
|
120
|
+
timing
|
121
|
+
sw
|
122
|
+
}
|
123
|
+
@@block_directories =
|
124
|
+
@@configuration_directories +
|
125
|
+
%w{
|
126
|
+
base_chip/configurations
|
127
|
+
}
|
128
|
+
@@project_directories =
|
129
|
+
@@common_directories +
|
130
|
+
%w{
|
131
|
+
base_chip/plugins
|
132
|
+
base_chip/subprojects
|
133
|
+
base_chip/blocks
|
134
|
+
base_chip/configurations
|
135
|
+
base_chip/cluster_types
|
136
|
+
}
|
137
|
+
|
138
|
+
def self.project(name = nil, &blk)
|
139
|
+
if name
|
140
|
+
@project = Project.new
|
141
|
+
@project.name = name
|
142
|
+
@project.blks << blk
|
143
|
+
else
|
144
|
+
@project
|
145
|
+
end
|
146
|
+
end
|
147
|
+
# SAFE TO DELETE? def self.action(name, &b)
|
148
|
+
# SAFE TO DELETE? @action_builders ||= {}
|
149
|
+
# SAFE TO DELETE? @action_builders[name] ||= []
|
150
|
+
# SAFE TO DELETE? @action_builders[name] << b
|
151
|
+
# SAFE TO DELETE? end
|
152
|
+
def self.load_environment
|
153
|
+
find_root
|
154
|
+
file = "#{BaseChip.root}/base_chip/settings.rb"
|
155
|
+
instance_eval(File.read(file),file)
|
156
|
+
file = '~/.basechip'
|
157
|
+
instance_eval(File.read(file),file) if File.exist? file
|
158
|
+
@project.configure
|
159
|
+
end
|
160
|
+
|
161
|
+
def self.blocks
|
162
|
+
@project.blocks.values
|
163
|
+
end
|
164
|
+
def self.get_children(parents, child_name)
|
165
|
+
a = []
|
166
|
+
parents.each do |item|
|
167
|
+
item.configure
|
168
|
+
tmp = item.send(child_name)
|
169
|
+
next unless tmp
|
170
|
+
a += tmp.values
|
171
|
+
end
|
172
|
+
a.uniq!
|
173
|
+
a
|
174
|
+
end
|
175
|
+
def self.configurations ; @configurations ||= get_children(self.blocks , :configurations) end
|
176
|
+
def self.actions ; @actions ||= get_children(self.configurations , :actions ) end
|
177
|
+
def self.test_lists ; @test_lists ||= get_children(self.configurations , :test_lists ) end
|
178
|
+
def self.tests ; @tests ||= get_children(self.test_lists , :tests ) end
|
179
|
+
def self.tools ; @tools ||= get_children(self.configurations , :tools ) end
|
180
|
+
|
181
|
+
def self.version_control
|
182
|
+
@version_control ||= (Git.new(root) if File.exist?("#{root}/.git"))
|
183
|
+
end
|
184
|
+
|
185
|
+
@@random_generator = nil
|
186
|
+
def self.random_generator
|
187
|
+
@@random_generator ||= if @@options.seed
|
188
|
+
Random.new(@@options.seed )
|
189
|
+
else
|
190
|
+
Random.new(rand(0x1_0000_0000))
|
191
|
+
end
|
192
|
+
end
|
193
|
+
def self.new_random_generator
|
194
|
+
if @@options.seed
|
195
|
+
random_generator
|
196
|
+
else
|
197
|
+
Random.new(random_generator.rand(0x1_0000_0000))
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
unless $BASE_CHIP_INCLUDE_MODE
|
203
|
+
if BaseChip.find_root(nil,true)
|
204
|
+
Dir.glob("#{BaseChip.root}/base_chip/plugins/*").each do |dir|
|
205
|
+
file = "#{dir}/lib/#{File.basename(dir)}.rb"
|
206
|
+
if File.exist?(file)
|
207
|
+
require file
|
208
|
+
else
|
209
|
+
raise "#{file} doesn't exist within plugin folder #{dir}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
BaseChip::TopMenu.new.run_cli
|
214
|
+
end
|
215
|
+
|
data/lib/dir.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
class Dir
|
18
|
+
@@pushd_stack = []
|
19
|
+
def self.pushd(d)
|
20
|
+
@@pushd_stack << Dir.pwd
|
21
|
+
Dir.chdir d
|
22
|
+
end
|
23
|
+
def self.popd
|
24
|
+
if d = @@pushd_stack.pop
|
25
|
+
Dir.chdir d
|
26
|
+
else
|
27
|
+
raise "directory stack empty, pwd = #{Dir.pwd}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/reporting.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# Copyright 2011 Tommy Poulter
|
2
|
+
#
|
3
|
+
# This file is part of basechip.
|
4
|
+
#
|
5
|
+
# basechip is free software: you can redistribute it and/or modify
|
6
|
+
# it under the terms of the GNU General Public License version 3 as
|
7
|
+
# published by the Free Software Foundation.
|
8
|
+
#
|
9
|
+
# basechip is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with basechip. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
|
17
|
+
require 'drb'
|
18
|
+
require 'base_chip/problem'
|
19
|
+
|
20
|
+
module BaseChip
|
21
|
+
class ReportingError < RuntimeError
|
22
|
+
attr :message
|
23
|
+
attr :file
|
24
|
+
attr :bundle
|
25
|
+
def initialize(message,file=nil,bundle=nil)
|
26
|
+
if message.is_a? Problem
|
27
|
+
@message = message.signature
|
28
|
+
@file = message.file
|
29
|
+
@bundle = message.bundle
|
30
|
+
else
|
31
|
+
@message = message
|
32
|
+
@file = file
|
33
|
+
@bundle = bundle
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
module Reporting
|
38
|
+
class Fault < RuntimeError;
|
39
|
+
# attr_accessor :msg
|
40
|
+
# def initialize(msg)
|
41
|
+
# @msg = msg
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
def self.included mod
|
45
|
+
mod.extend Reporting::Methods
|
46
|
+
mod.class_eval do
|
47
|
+
include Reporting::Methods
|
48
|
+
end
|
49
|
+
end
|
50
|
+
module Methods
|
51
|
+
def error(msg)
|
52
|
+
re = ReportingError.new(msg)
|
53
|
+
message "error", re.message, :red
|
54
|
+
raise re
|
55
|
+
end
|
56
|
+
def fault(msg,exception_msg=nil)
|
57
|
+
message "fault", msg, :red # = "#{Process.pid} #{$0} #{ARGV.join( ' ' )} #{msg}"
|
58
|
+
DRb.stop_service
|
59
|
+
# raise Fault, (exception_msg || msg) # FIXME -- when to raise?
|
60
|
+
exit 0
|
61
|
+
end
|
62
|
+
def normal(msg)
|
63
|
+
puts msg unless $quiet
|
64
|
+
end
|
65
|
+
def verbose(msg)
|
66
|
+
puts msg if $verbose
|
67
|
+
end
|
68
|
+
def debug(msg)
|
69
|
+
message "Debug", msg if $debug
|
70
|
+
end
|
71
|
+
def message(type,msg,color = nil)
|
72
|
+
clear_line if self.respond_to? :clear_line
|
73
|
+
ostring = case color
|
74
|
+
when :red ; "[31m"
|
75
|
+
when :green ; "[32m"
|
76
|
+
when nil ; ''
|
77
|
+
else raise
|
78
|
+
end
|
79
|
+
msg.chomp!
|
80
|
+
if msg =~ /\n/
|
81
|
+
ostring += "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
|
82
|
+
ostring += "+++++ #{type}: (Multi-line) +++++++++++++++++++++++++++++++++++++++\n"
|
83
|
+
ostring += "#{msg}\n"
|
84
|
+
ostring += "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
|
85
|
+
else
|
86
|
+
ostring += "#{type}: #{msg}"
|
87
|
+
end
|
88
|
+
ostring += "[0m" if color
|
89
|
+
puts ostring
|
90
|
+
ostring
|
91
|
+
end
|
92
|
+
def class_string
|
93
|
+
self.class.to_s.gsub(/BaseChip::/,'')
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|