Class: Buildr::AS3::Alchemy::Compiler::AlcGcc

Inherits:
Compiler::Base
  • Object
show all
Includes:
Compiler::CompilerUtils
Defined in:
lib/buildr/as3/alchemy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Compiler::CompilerUtils

#append_args, #get_last_modified, get_output, #is_output_outdated?, #move_dependency_dirs_to_source, #needed?, #older, #reserved_options, #timestamp_from_file

Constructor Details

#initialize(project, options) ⇒ AlcGcc

Returns a new instance of AlcGcc.



139
140
141
142
# File 'lib/buildr/as3/alchemy.rb', line 139

def initialize(project, options)
  super
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



137
138
139
# File 'lib/buildr/as3/alchemy.rb', line 137

def project
  @project
end

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/buildr/as3/alchemy.rb', line 146

def compile(sources, target, dependencies)
  alchemy_tk = options[:alchemy].invoke
  flex_sdk = alchemy_tk.flex_sdk
  output = Buildr::AS3::Compiler::CompilerUtils::get_output(project, target, :swc, options)

  # gcc stringecho.c -O3 -Wall -swc -o stringecho.swc
  cmd_args = []
  cmd_args << "gcc"
  cmd_args << File.basename(options[:main])
  cmd_args << "-O3 -Wall -swc"
  cmd_args << "-o #{File.basename output}"

  reserved = [:flexsdk, :main, :alchemy]
  options.to_hash.reject { |key, value| reserved.include?(key) }.
      each do |key, value|
    cmd_args << "-#{key}=#{value}"
  end

  unless Buildr.application.options.dryrun
    ENV["ALCHEMY_HOME"]= alchemy_tk.home
    ENV["ALCHEMY_VER"] = "0.4a"
    ENV["PATH"] = "#{alchemy_tk.bin}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
    ENV["ASC"]="#{alchemy_tk.home}/bin/asc.jar"
    ENV["ADL"]=alchemy_tk.flex_sdk.adl
    ENV["SWFBRIDGE"]=alchemy_tk.swfbridge
    ENV["PATH"] = "#{alchemy_tk.achacks}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
    ENV["PATH"] = "#{ENV["PATH"]}:#{flex_sdk.bin}"
    project_dir = Dir.getwd
    Dir.chdir File.dirname options[:main]
    system(cmd_args.join(" "))
    File.copy(File.basename(output), output)
    File.delete File.basename(output)
    Dir.chdir project_dir
  end
end