Class: MTBuild::Project

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/mtbuild/project.rb

Overview

This is the base class for all project types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rake::DSL

#application_task, #framework_task, #static_library_task, #test_application_task

Constructor Details

#initialize(project_name, project_folder, &configuration_block) ⇒ Project

If supplied, the configuration_block will be passed the newly-constructed Project object.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/mtbuild/project.rb', line 26

def initialize(project_name, project_folder, &configuration_block)
  @default_configuration = nil
  @configurations = {}
  @project_folder = File.expand_path(project_folder)
  @output_folder = File.expand_path(File.join(@project_folder, MTBuild.default_output_folder))
  @project_name, @parent_workspace = MTBuild::BuildRegistry.enter_project(project_name, self)
  @clean_list = Rake::FileList.new

  configuration_block.call(self) if configuration_block

  generate_implicit_workspace_configurations

  namespace @project_name do
    @configurations.each_value do |configuration|
      configuration.configure_tasks
    end

    Cleaner.generate_clean_task_for_project(@project_name, @clean_list)
  end

  MTBuild::BuildRegistry.exit_project
end

Instance Attribute Details

#clean_listObject (readonly)

The project’s list of things to clean



22
23
24
# File 'lib/mtbuild/project.rb', line 22

def clean_list
  @clean_list
end

#output_folderObject (readonly)

The project’s output folder. Project output goes here.



16
17
18
# File 'lib/mtbuild/project.rb', line 16

def output_folder
  @output_folder
end

#parent_workspaceObject (readonly)

The project’s parent workspace



19
20
21
# File 'lib/mtbuild/project.rb', line 19

def parent_workspace
  @parent_workspace
end

#project_folderObject (readonly)

The project’s folder. Relative path references are interpreted as relative to this folder.



13
14
15
# File 'lib/mtbuild/project.rb', line 13

def project_folder
  @project_folder
end

#project_nameObject (readonly)

The project’s name



9
10
11
# File 'lib/mtbuild/project.rb', line 9

def project_name
  @project_name
end

Instance Method Details

#add_configuration(configuration_name, configuration) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/mtbuild/project.rb', line 81

def add_configuration(configuration_name, configuration)
  merged_configuration = {}
  unless @default_configuration.nil?
    merged_configuration = @default_configuration
  end
  unless @parent_workspace.nil?
    configuration_defaults = @parent_workspace.configuration_defaults.fetch(configuration_name, {})
    merged_configuration = Utils.merge_configurations(configuration_defaults, merged_configuration)
  end
  merged_configuration = Utils.merge_configurations(merged_configuration, configuration)
  cfg = create_configuration(configuration_name, merged_configuration)
  @configurations[configuration_name] = cfg
  cfg
end

#add_files_to_clean(*filenames) ⇒ Object

Add files to the project’s clean list.



65
66
67
68
# File 'lib/mtbuild/project.rb', line 65

def add_files_to_clean(*filenames)
  @clean_list.include(filenames)
  Cleaner.global_clean_list.include(filenames)
end

#effective_output_folderObject

Returns the effective output folder. If a workspace exists, this will return the workspace’s output folder. If not, it will return the project’s output folder.



73
74
75
76
77
78
79
# File 'lib/mtbuild/project.rb', line 73

def effective_output_folder
  if MTBuild::BuildRegistry.top_workspace.nil?
    File.join(@output_folder, @project_name.to_s.split(':'))
  else
    File.join(MTBuild::BuildRegistry.top_workspace.output_folder, @project_name.to_s.split(':'))
  end
end

#set_default_configuration(configuration) ⇒ Object



96
97
98
# File 'lib/mtbuild/project.rb', line 96

def set_default_configuration(configuration)
  @default_configuration = configuration
end

#set_output_folder(output_folder) ⇒ Object

Set the project’s output folder.



60
61
62
# File 'lib/mtbuild/project.rb', line 60

def set_output_folder(output_folder)
  @output_folder = File.expand_path(File.join(@project_folder, output_folder))
end

#task_for_configuration(config_name) ⇒ Object

Get the fully-qualified task name for a configuration



50
51
52
# File 'lib/mtbuild/project.rb', line 50

def task_for_configuration(config_name)
  "#{@project_name}:#{config_name}"
end

#tasks_for_all_configurationsObject

Get the list of fully-qualified task names for all configurations



55
56
57
# File 'lib/mtbuild/project.rb', line 55

def tasks_for_all_configurations
  @configurations.keys.collect{ |name| "#{@project_name}:#{name}"}
end