Class: Buildr::Scala::Scalac
- Inherits:
-
Compiler::Base
- Object
- Compiler::Base
- Buildr::Scala::Scalac
- Defined in:
- lib/buildr/scala/compiler.rb
Overview
Scalac compiler:
compile.using(:scalac)
Used by default if .scala files are found in the src/main/scala directory (or src/test/scala) and sets the target directory to target/classes (or target/test/classes).
Accepts the following options:
-
:warnings – Generate warnings if true (opposite of -nowarn).
-
:deprecation – Output source locations where deprecated APIs are used.
-
:optimise – Generates faster bytecode by applying optimisations to the program.
-
:target – Class file compatibility with specified release.
-
:debug – Generate debugging info.
-
:other – Array of options to pass to the Scalac compiler as is, e.g. -Xprint-types
Constant Summary collapse
- OPTIONS =
[:warnings, :deprecation, :optimise, :target, :debug, :other]
Instance Attribute Summary
Attributes inherited from Compiler::Base
Class Method Summary collapse
Instance Method Summary collapse
-
#compile(sources, target, dependencies) ⇒ Object
:nodoc:.
-
#initialize(project, options) ⇒ Scalac
constructor
:nodoc:.
Methods inherited from Compiler::Base
applies_to?, #dependencies, #needed?, specify, to_sym
Constructor Details
Class Method Details
.dependencies ⇒ Object
42 43 44 |
# File 'lib/buildr/scala/compiler.rb', line 42 def dependencies [ 'scala-library.jar', 'scala-compiler.jar'].map { |jar| File.("lib/#{jar}", scala_home) } end |
.scala_home ⇒ Object
38 39 40 |
# File 'lib/buildr/scala/compiler.rb', line 38 def scala_home @home ||= ENV['SCALA_HOME'] end |
.use_fsc ⇒ Object
46 47 48 |
# File 'lib/buildr/scala/compiler.rb', line 46 def use_fsc ENV["USE_FSC"] =~ /^(yes|on|true)$/i end |
Instance Method Details
#compile(sources, target, dependencies) ⇒ Object
:nodoc:
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/buildr/scala/compiler.rb', line 64 def compile(sources, target, dependencies) #:nodoc: , OPTIONS cmd_args = [] cmd_args << '-classpath' << (dependencies + Scalac.dependencies).join(File::PATH_SEPARATOR) source_paths = sources.select { |source| File.directory?(source) } cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty? cmd_args << '-d' << File.(target) cmd_args += scalac_args cmd_args += files_from_sources(sources) unless Buildr.application..dryrun Scalac.scala_home or fail 'Are we forgetting something? SCALA_HOME not set.' trace((['scalac'] + cmd_args).join(' ')) if Scalac.use_fsc system(([File.('bin/fsc', Scalac.scala_home)] + cmd_args).join(' ')) or fail 'Failed to compile, see errors above' else Java.load Java.scala.tools.nsc.Main.process(cmd_args.to_java(Java.java.lang.String)) fail 'Failed to compile, see errors above' if Java.scala.tools.nsc.Main.reporter.hasErrors end end end |