Class: Bozo::Compilers::Project

Inherits:
Object
  • Object
show all
Includes:
Runner
Defined in:
lib/bozo/compilers/msbuild.rb

Direct Known Subclasses

ClassLibrary, WebProject2008, WebProject2010

Instance Method Summary collapse

Constructor Details

#initialize(project_file, project_name) ⇒ Project

Returns a new instance of Project.



152
153
154
155
# File 'lib/bozo/compilers/msbuild.rb', line 152

def initialize(project_file, project_name)
  @project_file = project_file
  @project_name = project_name
end

Instance Method Details

#build(configuration) ⇒ Object



161
162
163
164
165
# File 'lib/bozo/compilers/msbuild.rb', line 161

def build(configuration)
  populate_config(configuration)
  args = generate_args configuration
  execute_command :msbuild, args
end

#clean(configuration) ⇒ Object



167
168
169
170
171
172
173
174
# File 'lib/bozo/compilers/msbuild.rb', line 167

def clean(configuration)
  configuration.delete(:max_cores)
  configuration[:targets] = [:clean]
  args = generate_args configuration
  execute_command :msbuild, args

  remove_obj_directory
end

#framework_versionObject



176
177
178
179
180
181
182
183
184
185
# File 'lib/bozo/compilers/msbuild.rb', line 176

def framework_version
  framework_version = 'unknown'

  File.open(@project_file) do |f|
    framework_version = Nokogiri::XML(f).css('Project PropertyGroup TargetFrameworkVersion').first.content
    framework_version = framework_version.sub('v', 'net').sub('.', '')
  end

  framework_version
end

#generate_args(config) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/bozo/compilers/msbuild.rb', line 187

def generate_args(config)
  args = []

  args << File.join(ENV['WINDIR'], 'Microsoft.NET', config[:framework], config[:version], 'msbuild.exe')
  args << '/nologo'
  args << '/verbosity:normal'
  args << '/nodeReuse:false'
  args << "/target:#{config[:targets].map{|t| t.to_s}.join(';')}"
  args << "/p:StyleCopEnabled=false" if config[:without_stylecop]
  args << "/maxcpucount" if config[:max_cores].nil? # let msbuild decide how many cores to use
  args << "/maxcpucount:#{config[:max_cores]}" unless config[:max_cores].nil? # specifying the number of cores

  config[:properties].each do |key, value|
    args << "/property:#{key}=\"#{value}\""
  end

  args << "\"#{@project_file}\""
end

#locationObject



214
215
216
# File 'lib/bozo/compilers/msbuild.rb', line 214

def location
  File.expand_path(File.join(temp_project_path, framework_version))
end

#nameObject



157
158
159
# File 'lib/bozo/compilers/msbuild.rb', line 157

def name
  @project_name
end

#project_pathObject



218
219
220
# File 'lib/bozo/compilers/msbuild.rb', line 218

def project_path
  File.dirname(@project_file)
end

#temp_project_pathObject



210
211
212
# File 'lib/bozo/compilers/msbuild.rb', line 210

def temp_project_path
  File.expand_path(File.join('temp', 'msbuild', @project_name))
end

#windowsize_path(path) ⇒ Object



206
207
208
# File 'lib/bozo/compilers/msbuild.rb', line 206

def windowsize_path(path)
  path.gsub(/\//, '\\')
end