Class: ASRake::BaseCompiler

Inherits:
BaseExecutable show all
Includes:
Rake::DSL
Defined in:
lib/asrake/base_compiler.rb

Direct Known Subclasses

Compc, Mxmlc

Constant Summary collapse

@@args =

compiler arguments

[
	:source_path,
	:library_path,
	:external_library_path,
	:include_libraries,

	:load_config,
	:target_player,
	:swf_version,

	:debug,

	:dump_config,

	:additional_args
]

Instance Attribute Summary

Attributes inherited from BaseExecutable

#output, #output_dir, #output_file

Instance Method Summary collapse

Methods inherited from BaseExecutable

#merge_in, #output_is_dir?, #pathmap, #to_s, #to_str

Constructor Details

#initialize(file, exe_path) ⇒ BaseCompiler

Returns a new instance of BaseCompiler.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/asrake/base_compiler.rb', line 32

def initialize(file, exe_path)
	super(file)

	@exe = exe_path

	@isAIR = false
	@library_path = []
	@external_library_path = []
	@include_libraries = []
	@source_path = []
	@debug = false
	#include default flex-config
	@load_config = [ FlexSDK::flex_config ]
	@additional_args = ""
	
	# allow setting source_path with '=' instead of '<<'
	# actually, no, this is really bad and confusing we should probably throw when they try to assign
	#self.source_path = [self.source_path] if self.source_path.is_a? String
end

Instance Method Details



61
62
63
# File 'lib/asrake/base_compiler.rb', line 61

def dynamically_link
	external_library_path
end

#executeObject



151
152
153
154
155
156
157
158
159
160
161
# File 'lib/asrake/base_compiler.rb', line 151

def execute
	puts "> #{@exe}#{generate_args}"
	status = run "#{@exe}#{generate_args}", false do |line|
		puts ">    #{line}"
		generate_error_message_tips(line)
	end

	handle_execute_error status.exitstatus

	raise "Operation exited with status #{status.exitstatus}" if status.exitstatus != 0
end

#generate_argsObject

Verify properties and then return build arguments



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/asrake/base_compiler.rb', line 85

def generate_args
	
	# TODO: have this be checked when assigned and throw on string so the user understands the proper syntax
	#self.source_path = [self.source_path] if self.source_path.is_a? String
	#self.load_config = [self.load_config] if self.load_config.is_a? String
	#self.library_path = [self.library_path] if self.library_path.is_a? String
	#self.external_library_path = [self.external_library_path] if self.external_library_path.is_a? String
	#self.include_libraries = [self.include_libraries] if self.include_libraries.is_a? String

	# set to true if the version is defined in one of the referenced configs
	is_target_defined = false
	if self.target_player == nil
		# try to find necessary args in any loaded config files
		unless self.load_config.length == 1 && is_default_config?(self.load_config[0])
			# load config in reverse so last added has priority
			self.load_config.reverse.each do |config|
				flex_config = Nokogiri::XML(File.read(config))
				
				is_target_defined = true if flex_config.at_css('target-player')
			end
		end
	end

	fail "You must define 'target_player' for #{self}" if self.target_player == nil && !is_target_defined

	# TODO: iterate over all non-default config files provided and look for source-path entries
	#fail "You must add at least one path to 'source_path' for #{self}" if source_path.empty? && !configSource?

	#
	# validation complete, generate build args
	#

	args = ""
	# set output as directory if it ends in a trailing slash
	args << " -output=#{Path::forward output}"
	args << " -directory=true" if output_is_dir?

	args << " -target-player=#{target_player}" if self.target_player != nil
	args << " -swf-version=#{swf_version}" if self.swf_version != nil

	args << " +configname=air" if self.isAIR

	args << " -debug=#{debug}"
	args << " -source-path+=#{Path::forward source_path.join(',')}" if !self.source_path.empty?

	# add the -load-config option if it is anything other than the default
	unless self.load_config.length == 1 && is_default_config?(self.load_config[0])
		# if the default flex config is still in the load_config array, then append all config files, otherwise have the first one replace
		op = has_default_config_file? ? "+=" : "="
		self.load_config.each do |config|
			args << " -load-config#{op}#{Path::forward config}" unless is_default_config?(config)
			op = "+="
		end
	end

	args << " -library-path+=#{Path::forward library_path.join(',')}" if !self.library_path.empty?
	args << " -external-library-path+=#{Path::forward external_library_path.join(',')}" if !self.external_library_path.empty?
	args << " -include-libraries+=#{Path::forward include_libraries.join(',')}" if !self.include_libraries.empty?

	args << " -dump-config=#{Path::forward dump_config}" if self.dump_config != nil
	
	args << " #{additional_args}" if self.additional_args != nil && self.additional_args != ""
	
	return args
end

#isAIRObject Also known as: isAir

use the air configs if true



66
67
68
# File 'lib/asrake/base_compiler.rb', line 66

def isAIR
	@isAIR
end

#isAIR=(value) ⇒ Object Also known as: isAir=



69
70
71
72
73
74
75
76
77
# File 'lib/asrake/base_compiler.rb', line 69

def isAIR= value
	@isAIR = value
	# if the default config is in the load-config array, replace it with the proper one based on context
	if @isAIR
		self.load_config.map! {|val| val == FlexSDK::flex_config ? FlexSDK::air_config : val}
	else
		self.load_config.map! {|val| val == FlexSDK::air_config ? FlexSDK::flex_config : val}
	end
end


57
58
59
# File 'lib/asrake/base_compiler.rb', line 57

def statically_link
	include_libraries
end

provide a more understandable alias



53
54
55
# File 'lib/asrake/base_compiler.rb', line 53

def statically_link_only_referenced_classes
	library_path
end