Class OpenLaszlo::CommandLineCompiler
In: lib/openlaszlo/compiler.rb
Parent: Object

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.

Methods

Public Class methods

[Source]

     # File lib/openlaszlo/compiler.rb, line 148
148:     def self.executable_path(options={})
149:       home = options[:openlaszlo_home] || ENV['OPENLASZLO_HOME']
150:       raise ":compiler_script or OPENLASZLO_HOME must be specified" unless home
151:       path = bin_directories.
152:         map { |f| File.join(home, f, 'lzc') }.
153:         select { |f| File.exists? f }.
154:         first
155:       raise "couldn't find bin/lzc in #{bin_directories.join(' or ')}" unless path
156:       path += '.bat' if windows?
157:       return path
158:     end

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[‘OPENLASZLO_HOME’].

[Source]

     # File lib/openlaszlo/compiler.rb, line 144
144:     def initialize(options={})
145:       @lzc = options[:compiler_script] || self.class.executable_path(options)
146:     end

Public Instance methods

Invokes the OpenLaszlo command-line compiler on source_file.

See OpenLaszlo.compile for a description of options.

[Source]

     # File lib/openlaszlo/compiler.rb, line 163
163:     def compile(source_file, options={})
164:       default_output = File.join(File.dirname(source_file),
165:                                  File.basename(source_file, '.lzx') + '.swf')
166:       output = options[:output] || default_output
167:       raise "#{source_file} and #{output} do not have the same basename." unless File.basename(source_file, '.lzx') == File.basename(output, '.swf')
168:       args = []
169:       args << "--runtime=#{options[:runtime]}" if options[:runtime]
170:       args << '--debug' if options[:debug]
171:       args << '--profile' if options[:profile]
172:       args << "--dir '#{File.dirname output}'" unless File.dirname(source_file) == File.dirname(output)
173:       args << source_file
174:       command = "\"#{@lzc}\" #{args.join(' ')}"
175:       ENV['LPS_HOME'] ||= ENV['OPENLASZLO_HOME']
176:       begin
177:         #raise NotImplementedError --- for testing Windows
178:         require "open3"
179:         # The compiler writes errors to stdout, warnings to stderr
180:         stdin, stdout, stderr = Open3.popen3(command)
181:         errors = stdout.read
182:         warnings = stderr.readlines
183:         raise warnings.join("\n") if warnings.first =~ /^sh:/
184:         # OpenLaszlo 4.0:
185:         if warnings.first =~ /Compiling:.* to (\S+)/
186:           warnings.shift
187:           File.rename($1, output) if File.exists?($1)
188:         end
189:       rescue NotImplementedError
190:         # Windows doesn't have popen
191:         errors = `#{command}`
192:         warnings = []
193:       end
194:       errors.gsub!(/^\d+\s+/, '') # work around a bug in OpenLaszlo 3.1
195:       if errors =~ /^Compilation errors occurred:\n/
196:         raise CompilationError.new($'.strip)
197:       end
198:       results = {:output => output, :warnings => warnings}
199:       return results
200:     end

[Validate]