-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ianoc/oscar/resident-compiler
Factor out ScalaCInvoker option parsing
- Loading branch information
Showing
4 changed files
with
210 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
load("//scala:scala.bzl", "scala_library") | ||
|
||
|
||
java_import( | ||
name = "scala_xml", | ||
jars = ["@scala//:lib/scala-xml_2.11-1.0.4.jar"] | ||
) | ||
|
||
scala_library(name = "test_reporter", | ||
srcs = ["JUnitXmlReporter.scala"], | ||
deps = ["@scalatest//file"], | ||
deps = ["@scalatest//file", ":scala_xml"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/java/io/bazel/rulesscala/scalac/CompileOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package io.bazel.rulesscala.scalac; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class CompileOptions { | ||
final public String outputName; | ||
final public String manifestPath; | ||
final public String[] scalaOpts; | ||
final public String[] pluginArgs; | ||
final public String classpath; | ||
final public String[] files; | ||
final public String[] sourceJars; | ||
final public boolean iJarEnabled; | ||
final public String ijarOutput; | ||
final public String ijarCmdPath; | ||
|
||
public CompileOptions(List<String> args) { | ||
Map<String, String> argMap = buildArgMap(args); | ||
|
||
outputName = getOrError(argMap, "JarOutput", "Missing required arg JarOutput"); | ||
manifestPath = getOrError(argMap, "Manifest", "Missing required arg Manifest"); | ||
|
||
scalaOpts = getOrEmpty(argMap, "ScalacOpts").split(","); | ||
pluginArgs = buildPluginArgs(getOrEmpty(argMap, "Plugins")); | ||
classpath = getOrError(argMap, "Classpath", "Must supply the classpath arg"); | ||
files = getOrEmpty(argMap, "Files").split(","); | ||
|
||
sourceJars = getOrEmpty(argMap, "SourceJars").split(","); | ||
iJarEnabled = booleanGetOrFalse(argMap, "EnableIjar"); | ||
if(iJarEnabled) { | ||
ijarOutput = getOrError(argMap, "ijarOutput", "Missing required arg ijarOutput when ijar enabled"); | ||
ijarCmdPath = getOrError(argMap, "ijarCmdPath", "Missing required arg ijarCmdPath when ijar enabled"); | ||
} | ||
else { | ||
ijarOutput = null; | ||
ijarCmdPath = null; | ||
} | ||
} | ||
|
||
private static HashMap<String, String> buildArgMap(List<String> lines) { | ||
HashMap hm = new HashMap(); | ||
for(String line: lines) { | ||
String[] lSplit = line.split(": "); | ||
if(lSplit.length > 2) { | ||
throw new RuntimeException("Bad arg, should have at most 1 space/2 spans. arg: " + line); | ||
} | ||
if(lSplit.length > 1) { | ||
hm.put(lSplit[0], lSplit[1]); | ||
} | ||
} | ||
return hm; | ||
} | ||
|
||
private static String getOrEmpty(Map<String, String> m, String k) { | ||
if(m.containsKey(k)) { | ||
return m.get(k); | ||
} else { | ||
return ""; | ||
} | ||
} | ||
private static String getOrError(Map<String, String> m, String k, String errorMessage) { | ||
if(m.containsKey(k)) { | ||
return m.get(k); | ||
} else { | ||
throw new RuntimeException(errorMessage); | ||
} | ||
} | ||
|
||
private static boolean booleanGetOrFalse(Map<String, String> m, String k) { | ||
if(m.containsKey(k)) { | ||
String v = m.get(k); | ||
if(v.trim().equals("True") || v.trim().equals("true")) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
public static String[] buildPluginArgs(String packedPlugins) { | ||
String[] pluginElements = packedPlugins.split(","); | ||
int numPlugins = 0; | ||
for(int i =0; i< pluginElements.length; i++){ | ||
if(pluginElements[i].length() > 0) { | ||
numPlugins += 1; | ||
} | ||
} | ||
|
||
String[] result = new String[numPlugins]; | ||
int idx = 0; | ||
for(int i =0; i< pluginElements.length; i++){ | ||
if(pluginElements[i].length() > 0) { | ||
result[idx] = "-Xplugin:" + pluginElements[i]; | ||
idx += 1; | ||
} | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.