Class: Delphi::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/delphi/project.rb

Overview

Class to load and compile dproj files

The RW properties of this class can be changed to modify the compilation behaviour of a project, but they will not be saved back to the dproj file - it is read only.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dproj) ⇒ Project

Returns a new instance of Project.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/delphi/project.rb', line 22

def initialize(dproj)
  @dproj = dproj
  fail "#{dproj} not found" unless File.exist?(dproj)

  load
  @compiler = Delphi::Compiler.new(project_version)
  @config = default_config
  @target = targets[0]
  @platform = platforms[0]
  @outputpath = get('//DCC_ExeOutput').text
end

Instance Attribute Details

#configObject

The configuration to build - e.g. Debug, Release.



14
15
16
# File 'lib/delphi/project.rb', line 14

def config
  @config
end

#dprojObject (readonly)

Returns the value of attribute dproj.



20
21
22
# File 'lib/delphi/project.rb', line 20

def dproj
  @dproj
end

#platformObject

The platform to build for - e.g. Win32, Win64.



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

def platform
  @platform
end

#targetObject

The msbuild target - e.g. Build, Compile, Clean.



18
19
20
# File 'lib/delphi/project.rb', line 18

def target
  @target
end

Instance Method Details

#compileObject



34
35
36
# File 'lib/delphi/project.rb', line 34

def compile
  @compiler.compile(@dproj, @target, @config, @platform)
end

#configsObject

Returns the set of valid configurations as read from the dproj file



53
54
55
56
57
58
59
60
# File 'lib/delphi/project.rb', line 53

def configs
  result = []
  @doc.elements.each('/Project/ItemGroup/BuildConfiguration') do |element|
    config = element.attributes['Include']
    result << config unless config == 'Base'
  end
  result
end

#fail_on_hints_and_warningsObject



44
45
46
# File 'lib/delphi/project.rb', line 44

def fail_on_hints_and_warnings
  @compiler.fail_on_hints_and_warnings
end

#fail_on_hints_and_warnings=(value) ⇒ Object



48
49
50
# File 'lib/delphi/project.rb', line 48

def fail_on_hints_and_warnings=(value)
  @compiler.fail_on_hints_and_warnings = value
end

#out_fileObject

The output file without the path.



63
64
65
# File 'lib/delphi/project.rb', line 63

def out_file
  File.basename(@output)
end

#outputObject



67
68
69
# File 'lib/delphi/project.rb', line 67

def output
  File.expand_path(File.join(subst_path(@outputpath), File.basename(@dproj, '.dproj') + '.exe'))
end

#platformsObject

Returns the set of valid platforms as read from the dproj file



78
79
80
81
82
83
# File 'lib/delphi/project.rb', line 78

def platforms
  path = '/Project/PropertyGroup/Platform'
  result = []
  @doc.elements.each(path) { |element| result << element.text }
  result
end

#project_versionObject



85
86
87
88
89
# File 'lib/delphi/project.rb', line 85

def project_version
  path = 'Project/PropertyGroup/ProjectVersion'
  @project_version = get(path).text.to_f unless @project_version
  @project_version
end

#targetsObject

Returns the set of valid targets



98
99
100
# File 'lib/delphi/project.rb', line 98

def targets
  %w(Build Compile Clean)
end