Class: OpenLaszlo::CommandLineCompiler
- Inherits:
-
Object
- Object
- OpenLaszlo::CommandLineCompiler
- Defined in:
- lib/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.
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.
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/compiler.rb', line 134 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 |
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.
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 181 182 183 184 |
# File 'lib/compiler.rb', line 150 def compile(source_file, ={}) runtime = [:runtime] || 'swf8' output_suffix = ".lzr=#{runtime}.swf" default_output = File.join(File.dirname(source_file), File.basename(source_file, '.lzx') + output_suffix) output = [:output] || default_output raise "#{source_file} and #{output} do not have the same basename." unless File.basename(source_file, '.lzx') == File.basename(output, output_suffix) 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 warnings.shift if warnings.first and warnings.first =~ /^Compiling:/ 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} return results end |