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 160
    def self.executable_path(options={})
      home = options[: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

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 147
    def initialize(options={})
      @lzc = options[:compiler_script]
      unless @lzc
        home = options[: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

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 175
    def compile(source_file, options={})
      runtime = options[:runtime] || 'swf8'
      default_output = File.join(File.dirname(source_file),
                                 File.basename(source_file, '.lzx') + '.swf')
      output = options[:output] || default_output
      args = []
      args << "--runtime=#{options[:runtime]}" if options[:runtime]
      args << '--debug' if options[:debug]
      args << '--profile' if options[: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

[Validate]