Class: MTBuild::Workspace
- Inherits:
-
Object
- Object
- MTBuild::Workspace
- Includes:
- Rake::DSL
- Defined in:
- lib/mtbuild/workspace.rb
Overview
Use this class to create a workspace
Instance Attribute Summary collapse
-
#configuration_defaults ⇒ Object
readonly
Workspace configuration defaults.
-
#default_tasks ⇒ Object
readonly
List of default tasks to build with this workspace.
-
#output_folder ⇒ Object
readonly
The workspace’s output folder.
-
#parent_workspace ⇒ Object
readonly
The workspace’s parent workspace.
-
#push_configuration_defaults ⇒ Object
readonly
List of configuration defaults that child workspaces should take from this workspace.
-
#workspace_folder ⇒ Object
readonly
The workspace’s folder.
-
#workspace_name ⇒ Object
readonly
The workspace’s name.
Class Method Summary collapse
-
.add_default_tasks(default_tasks) ⇒ Object
Add default tasks to the last active workspace.
- .find_build_file(project_path) ⇒ Object
Instance Method Summary collapse
-
#add_default_rake_tasks(default_tasks) ⇒ Object
Adds Rake tasks to be run by default when MTBuild is invoked with no arguments.
-
#add_default_tasks(default_tasks) ⇒ Object
Adds tasks to be run by default when MTBuild is invoked with no arguments.
-
#add_project(project_location) ⇒ Object
Adds a project subfolder.
-
#add_workspace(workspace_location, pull_default_tasks: false, pull_configurations: [], push_configurations: []) ⇒ Object
Adds a workspace subfolder.
-
#initialize(workspace_name, workspace_folder, &configuration_block) ⇒ Workspace
constructor
A new instance of Workspace.
-
#set_configuration_defaults(configuration_name, defaults_hash) ⇒ Object
Sets defaults for all configurations with the specified name.
-
#set_output_folder(output_folder) ⇒ Object
Sets the build output folder location.
Methods included from Rake::DSL
#application_task, #framework_task, #static_library_task, #test_application_task
Constructor Details
#initialize(workspace_name, workspace_folder, &configuration_block) ⇒ Workspace
Returns a new instance of Workspace.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mtbuild/workspace.rb', line 32 def initialize(workspace_name, workspace_folder, &configuration_block) @workspace_folder = File.(workspace_folder) @output_folder = File.(File.join(@workspace_folder, MTBuild.default_output_folder)) @projects = [] @workspaces = [] @default_tasks = [] @configuration_defaults = {} @child_workspaces = {} @push_configuration_defaults = [] @workspace_name, @parent_workspace = MTBuild::BuildRegistry.enter_workspace(workspace_name, self) unless @parent_workspace.nil? pull_configuration_defaults(@parent_workspace, @parent_workspace.push_configuration_defaults) end configuration_block.call(self) if configuration_block # If there's a parent workspace, use its output folder. # Don't use the current workspace's output folder. @output_folder = @parent_workspace.output_folder unless @parent_workspace.nil? @workspaces.each do |workspace| MTBuild::BuildRegistry.expect_workspace @push_configuration_defaults = workspace[:push_cfg] require workspace[:build_file] last_workspace = MTBuild::BuildRegistry.reenter_workspace(self) unless last_workspace.nil? pull_configuration_defaults(last_workspace, workspace[:pull_cfg]) @default_tasks+=last_workspace.default_tasks if workspace[:pull_tasks] end end @projects.each do |project| MTBuild::BuildRegistry.expect_project require project end Cleaner.global_clean_list.include(@output_folder) # Only register default tasks and generate global clean if we're the top-level workspace. if @parent_workspace.nil? task Rake.application.default_task_name => @default_tasks Cleaner.generate_global_clean_task end MTBuild::BuildRegistry.exit_workspace end |
Instance Attribute Details
#configuration_defaults ⇒ Object (readonly)
Workspace configuration defaults
23 24 25 |
# File 'lib/mtbuild/workspace.rb', line 23 def configuration_defaults @configuration_defaults end |
#default_tasks ⇒ Object (readonly)
List of default tasks to build with this workspace
30 31 32 |
# File 'lib/mtbuild/workspace.rb', line 30 def default_tasks @default_tasks end |
#output_folder ⇒ Object (readonly)
The workspace’s output folder
17 18 19 |
# File 'lib/mtbuild/workspace.rb', line 17 def output_folder @output_folder end |
#parent_workspace ⇒ Object (readonly)
The workspace’s parent workspace
20 21 22 |
# File 'lib/mtbuild/workspace.rb', line 20 def parent_workspace @parent_workspace end |
#push_configuration_defaults ⇒ Object (readonly)
List of configuration defaults that child workspaces should take from this workspace
27 28 29 |
# File 'lib/mtbuild/workspace.rb', line 27 def push_configuration_defaults @push_configuration_defaults end |
#workspace_folder ⇒ Object (readonly)
The workspace’s folder. Relative path references are interpreted as relative to this folder.
14 15 16 |
# File 'lib/mtbuild/workspace.rb', line 14 def workspace_folder @workspace_folder end |
#workspace_name ⇒ Object (readonly)
The workspace’s name
10 11 12 |
# File 'lib/mtbuild/workspace.rb', line 10 def workspace_name @workspace_name end |
Class Method Details
.add_default_tasks(default_tasks) ⇒ Object
Add default tasks to the last active workspace
137 138 139 |
# File 'lib/mtbuild/workspace.rb', line 137 def self.add_default_tasks(default_tasks) MTBuild::BuildRegistry.active_workspace.add_default_rake_tasks(default_tasks) unless MTBuild::BuildRegistry.active_workspace.nil? end |
.find_build_file(project_path) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/mtbuild/workspace.rb', line 141 def self.find_build_file(project_path) Rake.application.rakefiles.each do |fn| build_file = File.join(project_path, fn) if File.file? build_file return build_file end end return nil end |
Instance Method Details
#add_default_rake_tasks(default_tasks) ⇒ Object
Adds Rake tasks to be run by default when MTBuild is invoked with no arguments. This method will not namespace the tasks, so it can be used to specify plain Rake task names.
122 123 124 |
# File 'lib/mtbuild/workspace.rb', line 122 def add_default_rake_tasks(default_tasks) @default_tasks |= Utils.ensure_array(default_tasks).flatten end |
#add_default_tasks(default_tasks) ⇒ Object
Adds tasks to be run by default when MTBuild is invoked with no arguments. This method expects only MTBuild tasks and will namespace them according to the current workspace hierarchy.
116 117 118 |
# File 'lib/mtbuild/workspace.rb', line 116 def add_default_tasks(default_tasks) @default_tasks |= Utils.ensure_array(default_tasks).flatten.collect {|default_task| "#{@workspace_name}:#{default_task}"} end |
#add_project(project_location) ⇒ Object
Adds a project subfolder
101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/mtbuild/workspace.rb', line 101 def add_project(project_location) new_projects = [] Utils.(project_location, @workspace_folder).each do |project_path| if File.directory? project_path project_rakefile = MTBuild::Workspace.find_build_file(project_path) new_projects << project_rakefile unless project_rakefile.nil? end end $stderr.puts "Could not find a valid project at '#{project_location}'. Ignored." if new_projects.empty? @projects += new_projects end |
#add_workspace(workspace_location, pull_default_tasks: false, pull_configurations: [], push_configurations: []) ⇒ Object
Adds a workspace subfolder
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mtbuild/workspace.rb', line 81 def add_workspace(workspace_location, pull_default_tasks: false, pull_configurations: [], push_configurations: []) new_workspaces = [] Utils.(workspace_location, @workspace_folder).each do |workspace_path| if File.directory? workspace_path workspace_rakefile = MTBuild::Workspace.find_build_file(workspace_path) unless workspace_rakefile.nil? new_workspaces << { :build_file=>workspace_rakefile, :pull_tasks=>pull_default_tasks, :pull_cfg=>pull_configurations, :push_cfg=>push_configurations } end end end $stderr.puts "Could not find a valid workspace at '#{workspace_location}'. Ignored." if new_workspaces.empty? @workspaces += new_workspaces end |
#set_configuration_defaults(configuration_name, defaults_hash) ⇒ Object
Sets defaults for all configurations with the specified name
127 128 129 |
# File 'lib/mtbuild/workspace.rb', line 127 def set_configuration_defaults(configuration_name, defaults_hash) @configuration_defaults[configuration_name] = defaults_hash end |
#set_output_folder(output_folder) ⇒ Object
Sets the build output folder location
132 133 134 |
# File 'lib/mtbuild/workspace.rb', line 132 def set_output_folder(output_folder) @output_folder = File.(File.join(@workspace_folder,output_folder)) end |