Fixed #521: MSIL should support separate compilation
- The output directory must be specified by "-d" (default: ".") - There is a new switch -Xkeep-msil-files (default: false). This switch must be explicitly enabled if you want to keep the generated .msil files git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@14758 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
parent
dff00c63a1
commit
4248beed94
13
build.xml
13
build.xml
|
@ -1002,7 +1002,13 @@ MSIL
|
|||
<condition><not><isset property="ilasm.cmd"/></not></condition>
|
||||
</fail>
|
||||
<!-- Sets ilasm arguments (either Windows or Unix) -->
|
||||
<property name="ilasm.infile" value="${msil.dir}/predef.msil"/>
|
||||
<!-- property name="ilasm.infile" value="${msil.dir}/predef.msil" -->
|
||||
<path id="ilasm.infiles">
|
||||
<fileset dir="${msil.dir}" includes="*.msil"/>
|
||||
</path>
|
||||
<pathconvert property="ilasm.infile" pathsep=" ">
|
||||
<path refid="ilasm.infiles" />
|
||||
</pathconvert>
|
||||
<property name="ilasm.outfile" value="${msil.dir}/predef.dll"/>
|
||||
<if>
|
||||
<isset property="os.win"/>
|
||||
|
@ -1032,8 +1038,8 @@ MSIL
|
|||
</target>
|
||||
|
||||
<target name="msil.libraries" depends="setup.quick, msil.sources">
|
||||
<quick srcdir="${msil.dir}/src" target="msil"
|
||||
assemname="${msil.dir}/predef" assemrefs="${lib.dir}"
|
||||
<quick srcdir="${msil.dir}/src" destdir="${msil.dir}" target="msil"
|
||||
assemname="predef" assemrefs="${lib.dir}"
|
||||
failonerror="false">
|
||||
<include name="**/*.scala"/>
|
||||
<exclude name="scala/ScalaObject.scala"/>
|
||||
|
@ -1069,7 +1075,6 @@ MSIL
|
|||
<include name="scala/testing/*.scala"/>
|
||||
<include name="scala/text/*.scala"/> -->
|
||||
</quick>
|
||||
|
||||
<exec
|
||||
executable="${ilasm.cmd}" vmlauncher="no">
|
||||
<!--
|
||||
|
|
|
@ -102,6 +102,7 @@ class Settings(error: String => Unit) {
|
|||
|
||||
val assemname = StringSetting ("-Xassem", "file", "Name of the output assembly (only relevant with -target:msil)", "").dependsOn(target, "msil")
|
||||
val assemrefs = StringSetting ("-Xassem-path", "path", "List of assemblies referenced by the program (only relevant with -target:msil)", ".").dependsOn(target, "msil")
|
||||
val keepMsilFiles = BooleanSetting ("-Xkeep-msil-files", "Keep .msil files after calling ilasm").dependsOn(target, "msil").hideToIDE
|
||||
val Xchecknull = BooleanSetting ("-Xcheck-null", "Emit warning on selection of nullable reference")
|
||||
val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions and assumptions")
|
||||
val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions")
|
||||
|
|
|
@ -51,7 +51,6 @@ abstract class GenMSIL extends SubComponent {
|
|||
classes.values foreach codeGenerator.createTypeBuilder
|
||||
classes.values foreach codeGenerator.createClassMembers
|
||||
|
||||
|
||||
try {
|
||||
classes.values foreach codeGenerator.genClass
|
||||
} finally {
|
||||
|
@ -217,12 +216,13 @@ abstract class GenMSIL extends SubComponent {
|
|||
var assemName: String = _
|
||||
var firstSourceName = ""
|
||||
var outDir: File = _
|
||||
var moduleName: String = _
|
||||
|
||||
def initAssembly() {
|
||||
|
||||
assemName = settings.assemname.value
|
||||
if (assemName == "") {
|
||||
|
||||
if (assemName == "") {
|
||||
if (entryPoint != null) {
|
||||
assemName = msilName(entryPoint.enclClass)
|
||||
// remove the $ at the end (from module-name)
|
||||
|
@ -238,18 +238,16 @@ abstract class GenMSIL extends SubComponent {
|
|||
if (assemName.endsWith(".il"))
|
||||
assemName = assemName.substring(0, assemName.length()-3)
|
||||
val f: File = new File(assemName)
|
||||
outDir = f.getParentFile()
|
||||
assemName = f.getName()
|
||||
}
|
||||
if (outDir == null)
|
||||
outDir = new File(".")
|
||||
|
||||
outDir = new File(settings.outdir.value)
|
||||
|
||||
val assemblyName = new AssemblyName()
|
||||
assemblyName.Name = assemName
|
||||
massembly = AssemblyBuilder.DefineDynamicAssembly(assemblyName)
|
||||
|
||||
val moduleName = assemName + (if (entryPoint == null) ".dll" else ".exe")
|
||||
moduleName = assemName + (if (entryPoint == null) ".dll" else ".exe")
|
||||
// filename here: .dll or .exe (in both parameters), second: give absolute-path
|
||||
mmodule = massembly.DefineDynamicModule(moduleName,
|
||||
new File(outDir, moduleName).getAbsolutePath())
|
||||
|
@ -450,18 +448,22 @@ abstract class GenMSIL extends SubComponent {
|
|||
code.Emit(OpCodes.Ret)
|
||||
}
|
||||
createTypes()
|
||||
val filename = new File(outDir, assemName + ".msil").getPath()
|
||||
if (settings.debug.value)
|
||||
log("Output file name: " + filename)
|
||||
log("Output path: " + outDir.getPath)
|
||||
try {
|
||||
massembly.Save(filename)
|
||||
massembly.Save(outDir.getPath)
|
||||
val ilasm = Properties.msilILasm
|
||||
if (ilasm != "") {
|
||||
val cmd = ilasm + " " + filename
|
||||
val generatedFiles = List.fromArray(massembly.GetGeneratedFiles)
|
||||
val cmd = ilasm + " " + (if(entryPoint == null) "/dll" else "/exe") + " /output:" + moduleName + " " + generatedFiles.mkString(" ")
|
||||
if (settings.debug.value)
|
||||
log("Executing command: " + cmd)
|
||||
try {
|
||||
Runtime.getRuntime().exec(cmd)
|
||||
val p = Runtime.getRuntime().exec(cmd)
|
||||
p.waitFor() // wait until ilasm is done
|
||||
if(!settings.keepMsilFiles.value) {
|
||||
generatedFiles.foreach(f => new File(f).delete())
|
||||
}
|
||||
} catch {
|
||||
case _ =>
|
||||
Console.println("Cannot run command: " + cmd)
|
||||
|
@ -469,7 +471,7 @@ abstract class GenMSIL extends SubComponent {
|
|||
}
|
||||
}
|
||||
} catch {
|
||||
case _: Error => abort("Could not save file " + filename)
|
||||
case _: Error => abort("Could not save files in " + outDir.getPath)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue