You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2018/11/06 19:04:13 UTC
[royale-compiler] branch develop updated: compiler-jx: compc can
generate source map files and add them to SWCs
This is an automated email from the ASF dual-hosted git repository.
joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
The following commit(s) were added to refs/heads/develop by this push:
new 8689005 compiler-jx: compc can generate source map files and add them to SWCs
8689005 is described below
commit 8689005506168b76502fdc62f91ddf2eeccc754c
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Tue Nov 6 11:04:00 2018 -0800
compiler-jx: compc can generate source map files and add them to SWCs
---
.../apache/royale/compiler/clients/COMPJSC.java | 84 ++++++++++++++++----
.../royale/compiler/clients/COMPJSCNative.java | 89 +++++++++++++++++----
.../royale/compiler/clients/COMPJSCRoyale.java | 91 ++++++++++++++++++----
3 files changed, 220 insertions(+), 44 deletions(-)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java
index 8fe75a6..21df1b0 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSC.java
@@ -40,7 +40,7 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.royale.compiler.clients.problems.ProblemPrinter;
import org.apache.royale.compiler.clients.problems.WorkspaceProblemFormatter;
-import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.js.IJSWriter;
import org.apache.royale.compiler.config.CompilerDiagnosticsConstants;
import org.apache.royale.compiler.driver.js.IJSApplication;
import org.apache.royale.compiler.exceptions.ConfigurationException;
@@ -399,25 +399,40 @@ public class COMPJSC extends MXMLJSC
ICompilationUnit unit = cu;
- IASWriter writer;
+ IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = (IJSWriter) project.getBackend().createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) project.getBackend().createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
problems.addAll(errors);
- BufferedOutputStream out = new BufferedOutputStream(
+
+ BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(outputClassFile));
- writer.writeTo(out);
+ BufferedOutputStream sourceMapOut = null;
+ File outputSourceMapFile = null;
+ if (project.config.getSourceMap())
+ {
+ outputSourceMapFile = getOutputSourceMapFile(
+ cu.getQualifiedNames().get(0), outputFolder);
+ sourceMapOut = new BufferedOutputStream(
+ new FileOutputStream(outputSourceMapFile));
+ }
+ writer.writeTo(out, sourceMapOut, outputSourceMapFile);
out.flush();
out.close();
+ if (sourceMapOut != null)
+ {
+ sourceMapOut.flush();
+ sourceMapOut.close();
+ }
writer.close();
}
else
@@ -426,23 +441,29 @@ public class COMPJSC extends MXMLJSC
ICompilationUnit unit = cu;
- IASWriter writer;
+ IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = (IJSWriter) project.getBackend().createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) project.getBackend().createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
problems.addAll(errors);
ByteArrayOutputStream temp = new ByteArrayOutputStream();
- writer.writeTo(temp);
- boolean isExterns = false;
+ ByteArrayOutputStream sourceMapTemp = null;
+ if (project.config.getSourceMap())
+ {
+ sourceMapTemp = new ByteArrayOutputStream();
+ }
+ writer.writeTo(temp, sourceMapTemp, null);
+
+ boolean isExterns = false;
if (writer instanceof JSWriter)
isExterns = ((JSWriter)writer).isExterns();
String outputClassFile = getOutputClassFile(
@@ -452,9 +473,20 @@ public class COMPJSC extends MXMLJSC
temp.writeTo(zipOutputStream);
zipOutputStream.flush();
zipOutputStream.closeEntry();
- writer.close();
fileList.append(" <file path=\"" + outputClassFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
- }
+ if(sourceMapTemp != null)
+ {
+ String sourceMapFile = getOutputSourceMapFile(
+ cu.getQualifiedNames().get(0), isExterns ? externsOut : jsOut).getPath();
+ System.out.println("Writing file: " + sourceMapFile);
+ zipOutputStream.putNextEntry(new ZipEntry(sourceMapFile));
+ sourceMapTemp.writeTo(zipOutputStream);
+ zipOutputStream.flush();
+ zipOutputStream.closeEntry();
+ fileList.append(" <file path=\"" + sourceMapFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+ }
+ writer.close();
+ }
}
}
if (packingSWC)
@@ -597,6 +629,32 @@ public class COMPJSC extends MXMLJSC
}
/**
+ * @param qname
+ * @param outputFolder
+ * @return output source map file path
+ */
+ private File getOutputSourceMapFile(String qname, File outputFolder)
+ {
+ String[] cname = qname.split("\\.");
+ String sdirPath = outputFolder + File.separator;
+ if (cname.length > 0)
+ {
+ for (int i = 0, n = cname.length - 1; i < n; i++)
+ {
+ sdirPath += cname[i] + File.separator;
+ }
+
+ File sdir = new File(sdirPath);
+ if (!sdir.exists())
+ sdir.mkdirs();
+
+ qname = cname[cname.length - 1];
+ }
+
+ return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension() + ".map");
+ }
+
+ /**
* Mxmlc uses target file as the main compilation unit and derive the output
* SWF file name from this file.
*
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java
index ec69b6c..6f57322 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCNative.java
@@ -39,7 +39,7 @@ import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.royale.compiler.clients.problems.ProblemQuery;
-import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.js.IJSWriter;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
import org.apache.royale.compiler.exceptions.ConfigurationException;
@@ -262,25 +262,40 @@ public class COMPJSCNative extends MXMLJSCNative
ICompilationUnit unit = cu;
- IASWriter writer;
+ IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = (IJSWriter) project.getBackend().createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) project.getBackend().createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
problems.addAll(errors);
- BufferedOutputStream out = new BufferedOutputStream(
- new FileOutputStream(outputClassFile));
- writer.writeTo(out);
+
+ BufferedOutputStream out = new BufferedOutputStream(
+ new FileOutputStream(outputClassFile));
+ BufferedOutputStream sourceMapOut = null;
+ File outputSourceMapFile = null;
+ if (project.config.getSourceMap())
+ {
+ outputSourceMapFile = getOutputSourceMapFile(
+ cu.getQualifiedNames().get(0), outputFolder);
+ sourceMapOut = new BufferedOutputStream(
+ new FileOutputStream(outputSourceMapFile));
+ }
+ writer.writeTo(out, sourceMapOut, outputSourceMapFile);
out.flush();
out.close();
+ if (sourceMapOut != null)
+ {
+ sourceMapOut.flush();
+ sourceMapOut.close();
+ }
writer.close();
}
else
@@ -289,23 +304,30 @@ public class COMPJSCNative extends MXMLJSCNative
ICompilationUnit unit = cu;
- IASWriter writer;
+ IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = (IJSWriter) project.getBackend().createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) project.getBackend().createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
problems.addAll(errors);
- ByteArrayOutputStream temp = new ByteArrayOutputStream();
- writer.writeTo(temp);
- boolean isExterns = false;
+
+ ByteArrayOutputStream temp = new ByteArrayOutputStream();
+ ByteArrayOutputStream sourceMapTemp = null;
+ if (project.config.getSourceMap())
+ {
+ sourceMapTemp = new ByteArrayOutputStream();
+ }
+ writer.writeTo(temp, sourceMapTemp, null);
+
+ boolean isExterns = false;
if (writer instanceof JSWriter)
isExterns = ((JSWriter)writer).isExterns();
String outputClassFile = getOutputClassFile(
@@ -315,9 +337,20 @@ public class COMPJSCNative extends MXMLJSCNative
temp.writeTo(zipOutputStream);
zipOutputStream.flush();
zipOutputStream.closeEntry();
- writer.close();
fileList.append(" <file path=\"" + outputClassFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
- }
+ if(sourceMapTemp != null)
+ {
+ String sourceMapFile = getOutputSourceMapFile(
+ cu.getQualifiedNames().get(0), isExterns ? externsOut : jsOut).getPath();
+ System.out.println("Writing file: " + sourceMapFile);
+ zipOutputStream.putNextEntry(new ZipEntry(sourceMapFile));
+ sourceMapTemp.writeTo(zipOutputStream);
+ zipOutputStream.flush();
+ zipOutputStream.closeEntry();
+ fileList.append(" <file path=\"" + sourceMapFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+ }
+ writer.close();
+ }
}
}
if (packingSWC)
@@ -460,6 +493,32 @@ public class COMPJSCNative extends MXMLJSCNative
}
/**
+ * @param qname
+ * @param outputFolder
+ * @return output source map file path
+ */
+ private File getOutputSourceMapFile(String qname, File outputFolder)
+ {
+ String[] cname = qname.split("\\.");
+ String sdirPath = outputFolder + File.separator;
+ if (cname.length > 0)
+ {
+ for (int i = 0, n = cname.length - 1; i < n; i++)
+ {
+ sdirPath += cname[i] + File.separator;
+ }
+
+ File sdir = new File(sdirPath);
+ if (!sdir.exists())
+ sdir.mkdirs();
+
+ qname = cname[cname.length - 1];
+ }
+
+ return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension() + ".map");
+ }
+
+ /**
* Mxmlc uses target file as the main compilation unit and derive the output
* SWF file name from this file.
*
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java
index 033954a..b2568ff 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/clients/COMPJSCRoyale.java
@@ -39,7 +39,7 @@ import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.royale.compiler.clients.problems.ProblemQuery;
-import org.apache.royale.compiler.codegen.as.IASWriter;
+import org.apache.royale.compiler.codegen.js.IJSWriter;
import org.apache.royale.compiler.driver.IBackend;
import org.apache.royale.compiler.driver.js.IJSApplication;
import org.apache.royale.compiler.exceptions.ConfigurationException;
@@ -263,26 +263,41 @@ public class COMPJSCRoyale extends MXMLJSCRoyale
ICompilationUnit unit = cu;
- IASWriter writer;
+ IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = (IJSWriter) project.getBackend().createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) project.getBackend().createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
problems.addAll(errors);
- BufferedOutputStream out = new BufferedOutputStream(
+
+ BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(outputClassFile));
- writer.writeTo(out);
- out.flush();
+ BufferedOutputStream sourceMapOut = null;
+ File outputSourceMapFile = null;
+ if (project.config.getSourceMap())
+ {
+ outputSourceMapFile = getOutputSourceMapFile(
+ cu.getQualifiedNames().get(0), outputFolder);
+ sourceMapOut = new BufferedOutputStream(
+ new FileOutputStream(outputSourceMapFile));
+ }
+ writer.writeTo(out, sourceMapOut, outputSourceMapFile);
+ out.flush();
out.close();
- writer.close();
+ if (sourceMapOut != null)
+ {
+ sourceMapOut.flush();
+ sourceMapOut.close();
+ }
+ writer.close();
}
else
{
@@ -290,23 +305,30 @@ public class COMPJSCRoyale extends MXMLJSCRoyale
ICompilationUnit unit = cu;
- IASWriter writer;
+ IJSWriter writer;
if (cuType == ICompilationUnit.UnitType.AS_UNIT)
{
- writer = project.getBackend().createWriter(project,
+ writer = (IJSWriter) project.getBackend().createWriter(project,
(List<ICompilerProblem>) errors, unit,
false);
}
else
{
- writer = project.getBackend().createMXMLWriter(
+ writer = (IJSWriter) project.getBackend().createMXMLWriter(
project, (List<ICompilerProblem>) errors,
unit, false);
}
problems.addAll(errors);
- ByteArrayOutputStream temp = new ByteArrayOutputStream();
- writer.writeTo(temp);
- boolean isExterns = false;
+
+ ByteArrayOutputStream temp = new ByteArrayOutputStream();
+ ByteArrayOutputStream sourceMapTemp = null;
+ if (project.config.getSourceMap())
+ {
+ sourceMapTemp = new ByteArrayOutputStream();
+ }
+ writer.writeTo(temp, sourceMapTemp, null);
+
+ boolean isExterns = false;
if (writer instanceof JSWriter)
isExterns = ((JSWriter)writer).isExterns();
String outputClassFile = getOutputClassFile(
@@ -315,9 +337,20 @@ public class COMPJSCRoyale extends MXMLJSCRoyale
zipOutputStream.putNextEntry(new ZipEntry(outputClassFile));
temp.writeTo(zipOutputStream);
zipOutputStream.flush();
- zipOutputStream.closeEntry();
- writer.close();
+ zipOutputStream.closeEntry();
fileList.append(" <file path=\"" + outputClassFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+ if(sourceMapTemp != null)
+ {
+ String sourceMapFile = getOutputSourceMapFile(
+ cu.getQualifiedNames().get(0), isExterns ? externsOut : jsOut).getPath();
+ System.out.println("Writing file: " + sourceMapFile);
+ zipOutputStream.putNextEntry(new ZipEntry(sourceMapFile));
+ sourceMapTemp.writeTo(zipOutputStream);
+ zipOutputStream.flush();
+ zipOutputStream.closeEntry();
+ fileList.append(" <file path=\"" + sourceMapFile + "\" mod=\"" + System.currentTimeMillis() + "\"/>\n");
+ }
+ writer.close();
}
}
}
@@ -461,6 +494,32 @@ public class COMPJSCRoyale extends MXMLJSCRoyale
}
/**
+ * @param qname
+ * @param outputFolder
+ * @return output source map file path
+ */
+ private File getOutputSourceMapFile(String qname, File outputFolder)
+ {
+ String[] cname = qname.split("\\.");
+ String sdirPath = outputFolder + File.separator;
+ if (cname.length > 0)
+ {
+ for (int i = 0, n = cname.length - 1; i < n; i++)
+ {
+ sdirPath += cname[i] + File.separator;
+ }
+
+ File sdir = new File(sdirPath);
+ if (!sdir.exists())
+ sdir.mkdirs();
+
+ qname = cname[cname.length - 1];
+ }
+
+ return new File(sdirPath + qname + "." + project.getBackend().getOutputExtension() + ".map");
+ }
+
+ /**
* Mxmlc uses target file as the main compilation unit and derive the output
* SWF file name from this file.
*