Class: OpenLaszlo::CommandLineCompiler
- Inherits:
-
Object
- Object
- OpenLaszlo::CommandLineCompiler
- Defined in:
- lib/openlaszlo/compiler.rb
Overview
This class implements a bridge to the command-line compiler.
If you don’t need multiple compilers, you can use the methods in the OpenLaszlo module instead.
CommandLineCompiler is slower than CompileServer, but, unlike the server, it can compile files in any location.
Class Method Summary collapse
Instance Method Summary collapse
-
#compile(source_file, options = {}) ⇒ Object
Invokes the OpenLaszlo command-line compiler on
source_file. -
#initialize(options = {}) ⇒ CommandLineCompiler
constructor
Creates a new compiler.
Constructor Details
#initialize(options = {}) ⇒ CommandLineCompiler
Creates a new compiler.
Options are:
-
:compiler_script- the path to the shell script that
invokes the compiler. This defaults to a standard location inside the value specified by :home.
-
:openlaszlo_home- the home directory of the OpenLaszlo SDK.
This defaults to ENV.
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/openlaszlo/compiler.rb', line 147 def initialize(={}) @lzc = [:compiler_script] unless @lzc home = [:openlaszlo_home] || ENV['OPENLASZLO_HOME'] raise ":compiler_script or :openlaszlo_home must be specified" unless home search = bin_directories.map {|f| File.join(home, f, 'lzc')} found = search.select {|f| File.exists? f} raise "couldn't find bin/lzc in #{bin_directories.join(' or ')}" if found.empty? @lzc = found.first @lzc += '.bat' if windows? end end |
Class Method Details
.executable_path(options = {}) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/openlaszlo/compiler.rb', line 160 def self.executable_path(={}) home = [:openlaszlo_home] || ENV['OPENLASZLO_HOME'] raise ":compiler_script or OPENLASZLO_HOME must be specified" unless home path = bin_directories. map { |f| File.join(home, f, 'lzc') }. select { |f| File.exists? f }. first raise "couldn't find bin/lzc in #{bin_directories.join(' or ')}" unless path path += '.bat' if windows? return path end |
Instance Method Details
#compile(source_file, options = {}) ⇒ Object
Invokes the OpenLaszlo command-line compiler on source_file.
See OpenLaszlo.compile for a description of options.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/openlaszlo/compiler.rb', line 175 def compile(source_file, ={}) runtime = [:runtime] || 'swf8' default_output = File.join(File.dirname(source_file), File.basename(source_file, '.lzx') + '.swf') output = [:output] || default_output args = [] args << "--runtime=#{options[:runtime]}" if [:runtime] args << '--debug' if [:debug] args << '--profile' if [:profile] args << "--dir '#{File.dirname output}'" unless File.dirname(source_file) == File.dirname(output) args << source_file command = "\"#{@lzc}\" #{args.join(' ')}" ENV['LPS_HOME'] ||= ENV['OPENLASZLO_HOME'] begin #raise NotImplementedError --- for testing Windows require "open3" # The compiler writes errors to stdout, warnings to stderr stdin, stdout, stderr = Open3.popen3(command) errors = stdout.read warnings = stderr.readlines # OpenLaszlo >= 4.0 if warnings.first and warnings.first =~ /^Compiling:.* to (.+)/ real_output = $1 warnings.shift FileUtils.mv(real_output, output) if File.exists?(real_output) and real_output != output end rescue NotImplementedError # Windows doesn't have popen errors = `#{command}` warnings = [] end errors.gsub!(/^\d+\s+/, '') # work around a bug in OpenLaszlo 3.1 if errors =~ /^Compilation errors occurred:\n/ raise CompilationError.new($'.strip) end results = {:output => output, :warnings => warnings, :compiler => self} return results end |