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 2020/08/21 21:58:30 UTC

[royale-compiler] 03/03: COMPJSC: fix issue where .js files from one .swc file on the library-path were not copied to the new .swc file

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

commit fbe3ab86c444ba640ba78cec7d7a32040a7a925e
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Fri Aug 21 14:48:55 2020 -0700

    COMPJSC: fix issue where .js files from one .swc file on the library-path were not copied to the new .swc file
    
    The bytecode was being included, but not the corresponding .js file. Both are required, and this broke the app compiler, which couldn't figure out where to find the .js file. To exclude both the bytecode and .js file, then the .swc file should be added to the external-library-path instead of the library-path.
---
 .../apache/royale/compiler/clients/COMPJSC.java    | 60 ++++++++++++++++++++++
 .../royale/compiler/clients/COMPJSCNative.java     | 60 ++++++++++++++++++++++
 .../royale/compiler/clients/COMPJSCRoyale.java     | 60 ++++++++++++++++++++++
 3 files changed, 180 insertions(+)

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 5c058b9..c61356a 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
@@ -50,6 +50,7 @@ import org.apache.royale.compiler.exceptions.ConfigurationException.MustSpecifyT
 import org.apache.royale.compiler.internal.driver.js.goog.JSGoogCompcConfiguration;
 import org.apache.royale.compiler.internal.projects.CompilerProject;
 import org.apache.royale.compiler.internal.targets.RoyaleSWCTarget;
+import org.apache.royale.compiler.internal.units.SWCCompilationUnit;
 import org.apache.royale.compiler.internal.targets.JSTarget;
 import org.apache.royale.compiler.problems.ICompilerProblem;
 import org.apache.royale.compiler.problems.InternalCompilerProblem;
@@ -59,6 +60,7 @@ import org.apache.royale.compiler.problems.UnexpectedExceptionProblem;
 import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.swc.ISWCFileEntry;
 import org.apache.royale.swc.io.SWCReader;
 import org.apache.royale.utils.ArgumentUtil;
 
@@ -517,6 +519,64 @@ public class COMPJSC extends MXMLJSC
                             writer.close();
                         }
                     }
+                    else if (cuType == ICompilationUnit.UnitType.SWC_UNIT)
+                    {
+                    	String symbol = cu.getQualifiedNames().get(0);
+                    	if (externs.contains(symbol)) continue;
+                    	if (project.isExternalLinkage(cu)) continue;
+                    	if (!packingSWC)
+                    	{
+                            // we probably shouldn't skip this -JT
+                            continue;
+                        }
+
+                        // if another .swc file is on our library-path, we must
+                        // include the .js (and .js.map) files because the
+                        // bytecode will also be included. if we have the
+                        // bytecode, but not the .js files, the compiler won't
+                        // know where to find the .js files. that's really bad.
+
+                        // if the bytecode and .js files should not be included,
+                        // then the developer is expected to use
+                        // external-library-path instead of library-path.
+
+                        SWCCompilationUnit swcCU = (SWCCompilationUnit) cu;
+                        String outputClassFile = getOutputClassFile(
+                                cu.getQualifiedNames().get(0),
+                                jsOut,
+                                false).getPath();
+                        outputClassFile = outputClassFile.replace('\\', '/');
+                        ISWCFileEntry fileEntry = swcCU.getSWC().getFile(outputClassFile);
+                        if (fileEntry == null)
+                        {
+                            continue;
+                        }
+                        if (config.isVerbose())
+                        {
+                            System.out.println("Writing file: " + outputClassFile + " from SWC: " + swcCU.getAbsoluteFilename());
+                        }
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                        InputStream fileStream = fileEntry.createInputStream();
+                        IOUtils.copy(fileStream, baos);
+                        fileStream.close();
+                        writeFileToZip(zipOutputStream, outputClassFile, baos, fileList);
+
+                        String outputMapFile = outputClassFile + ".map";
+                        fileEntry = swcCU.getSWC().getFile(outputMapFile);
+                        if (fileEntry == null)
+                        {
+                            continue;
+                        }
+                        if (config.isVerbose())
+                        {
+                            System.out.println("Writing file: " + outputMapFile + " from SWC: " + swcCU.getAbsoluteFilename());
+                        }
+                        baos = new ByteArrayOutputStream();
+                        fileStream = fileEntry.createInputStream();
+                        IOUtils.copy(fileStream, baos);
+                        fileStream.close();
+                        writeFileToZip(zipOutputStream, outputMapFile, baos, fileList);
+                    }
                 }
                 if (packingSWC)
                 {
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 e2b3d11..125e93d 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
@@ -59,6 +59,7 @@ import org.apache.royale.compiler.internal.parsing.as.RoyaleASDocDelegate;
 import org.apache.royale.compiler.internal.projects.CompilerProject;
 import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
 import org.apache.royale.compiler.internal.targets.RoyaleSWCTarget;
+import org.apache.royale.compiler.internal.units.SWCCompilationUnit;
 import org.apache.royale.compiler.internal.targets.JSTarget;
 import org.apache.royale.compiler.internal.workspaces.Workspace;
 import org.apache.royale.compiler.problems.ICompilerProblem;
@@ -68,6 +69,7 @@ import org.apache.royale.compiler.problems.UnableToBuildSWFProblem;
 import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
+import org.apache.royale.swc.ISWCFileEntry;
 import org.apache.royale.swc.io.SWCReader;
 
 /**
@@ -382,6 +384,64 @@ public class COMPJSCNative extends MXMLJSCNative
                             writer.close();
                         }
                     }
+                    else if (cuType == ICompilationUnit.UnitType.SWC_UNIT)
+                    {
+                    	String symbol = cu.getQualifiedNames().get(0);
+                    	if (externs.contains(symbol)) continue;
+                    	if (project.isExternalLinkage(cu)) continue;
+                    	if (!packingSWC)
+                    	{
+                            // we probably shouldn't skip this -JT
+                            continue;
+                        }
+
+                        // if another .swc file is on our library-path, we must
+                        // include the .js (and .js.map) files because the
+                        // bytecode will also be included. if we have the
+                        // bytecode, but not the .js files, the compiler won't
+                        // know where to find the .js files. that's really bad.
+
+                        // if the bytecode and .js files should not be included,
+                        // then the developer is expected to use
+                        // external-library-path instead of library-path.
+
+                        SWCCompilationUnit swcCU = (SWCCompilationUnit) cu;
+                        String outputClassFile = getOutputClassFile(
+                                cu.getQualifiedNames().get(0),
+                                jsOut,
+                                false).getPath();
+                        outputClassFile = outputClassFile.replace('\\', '/');
+                        ISWCFileEntry fileEntry = swcCU.getSWC().getFile(outputClassFile);
+                        if (fileEntry == null)
+                        {
+                            continue;
+                        }
+                        if (config.isVerbose())
+                        {
+                            System.out.println("Writing file: " + outputClassFile + " from SWC: " + swcCU.getAbsoluteFilename());
+                        }
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                        InputStream fileStream = fileEntry.createInputStream();
+                        IOUtils.copy(fileStream, baos);
+                        fileStream.close();
+                        writeFileToZip(zipOutputStream, outputClassFile, baos, fileList);
+
+                        String outputMapFile = outputClassFile + ".map";
+                        fileEntry = swcCU.getSWC().getFile(outputMapFile);
+                        if (fileEntry == null)
+                        {
+                            continue;
+                        }
+                        if (config.isVerbose())
+                        {
+                            System.out.println("Writing file: " + outputMapFile + " from SWC: " + swcCU.getAbsoluteFilename());
+                        }
+                        baos = new ByteArrayOutputStream();
+                        fileStream = fileEntry.createInputStream();
+                        IOUtils.copy(fileStream, baos);
+                        fileStream.close();
+                        writeFileToZip(zipOutputStream, outputMapFile, baos, fileList);
+                    }
                 }
                 if (packingSWC)
                 {
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 4ed9d8c..366de7e 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
@@ -51,6 +51,7 @@ import org.apache.royale.compiler.internal.parsing.as.RoyaleASDocDelegate;
 import org.apache.royale.compiler.internal.projects.CompilerProject;
 import org.apache.royale.compiler.internal.projects.RoyaleJSProject;
 import org.apache.royale.compiler.internal.targets.RoyaleSWCTarget;
+import org.apache.royale.compiler.internal.units.SWCCompilationUnit;
 import org.apache.royale.compiler.internal.targets.JSTarget;
 import org.apache.royale.compiler.internal.workspaces.Workspace;
 import org.apache.royale.compiler.problems.ICompilerProblem;
@@ -61,6 +62,7 @@ import org.apache.royale.compiler.targets.ITarget.TargetType;
 import org.apache.royale.compiler.targets.ITargetSettings;
 import org.apache.royale.compiler.units.ICompilationUnit;
 import org.apache.royale.compiler.units.ICompilationUnit.UnitType;
+import org.apache.royale.swc.ISWCFileEntry;
 import org.apache.royale.swc.io.SWCReader;
 
 /**
@@ -404,6 +406,64 @@ public class COMPJSCRoyale extends MXMLJSCRoyale
 	                        writer.close();
                     	}
                     }
+                    else if (cuType == ICompilationUnit.UnitType.SWC_UNIT)
+                    {
+                    	String symbol = cu.getQualifiedNames().get(0);
+                    	if (externs.contains(symbol)) continue;
+                    	if (project.isExternalLinkage(cu)) continue;
+                    	if (!packingSWC)
+                    	{
+                            // we probably shouldn't skip this -JT
+                            continue;
+                        }
+
+                        // if another .swc file is on our library-path, we must
+                        // include the .js (and .js.map) files because the
+                        // bytecode will also be included. if we have the
+                        // bytecode, but not the .js files, the compiler won't
+                        // know where to find the .js files. that's really bad.
+
+                        // if the bytecode and .js files should not be included,
+                        // then the developer is expected to use
+                        // external-library-path instead of library-path.
+
+                        SWCCompilationUnit swcCU = (SWCCompilationUnit) cu;
+                        String outputClassFile = getOutputClassFile(
+                                cu.getQualifiedNames().get(0),
+                                jsOut,
+                                false).getPath();
+                        outputClassFile = outputClassFile.replace('\\', '/');
+                        ISWCFileEntry fileEntry = swcCU.getSWC().getFile(outputClassFile);
+                        if (fileEntry == null)
+                        {
+                            continue;
+                        }
+                        if (config.isVerbose())
+                        {
+                            System.out.println("Writing file: " + outputClassFile + " from SWC: " + swcCU.getAbsoluteFilename());
+                        }
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                        InputStream fileStream = fileEntry.createInputStream();
+                        IOUtils.copy(fileStream, baos);
+                        fileStream.close();
+                        writeFileToZip(zipOutputStream, outputClassFile, baos, fileList);
+
+                        String outputMapFile = outputClassFile + ".map";
+                        fileEntry = swcCU.getSWC().getFile(outputMapFile);
+                        if (fileEntry == null)
+                        {
+                            continue;
+                        }
+                        if (config.isVerbose())
+                        {
+                            System.out.println("Writing file: " + outputMapFile + " from SWC: " + swcCU.getAbsoluteFilename());
+                        }
+                        baos = new ByteArrayOutputStream();
+                        fileStream = fileEntry.createInputStream();
+                        IOUtils.copy(fileStream, baos);
+                        fileStream.close();
+                        writeFileToZip(zipOutputStream, outputMapFile, baos, fileList);
+                    }
                 }
                 if (!config.getCreateTargetWithErrors())
                 {