[Laszlo-checkins] r8856 - in openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo: compiler sc

dda@openlaszlo.org dda at openlaszlo.org
Fri Apr 25 11:07:11 PDT 2008


Author: dda
Date: 2008-04-25 11:07:04 -0700 (Fri, 25 Apr 2008)
New Revision: 8856

Modified:
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ScriptCompiler.java
Log:
Change 20080425-dda-f by dda at lester.local on 2008-04-25 10:44:15 EDT
    in /Users/dda/laszlo/src/svn/openlaszlo/trunk-a
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: -S and --script options now redirect to a .lzs file

New Features:

Bugs Fixed: LPP-5754

Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)

Documentation:

Release Notes:

Details:
    lzc -S foo.lzx now writes to foo.lzs.  This used to be
    achieved by lzc -S foo.lzx > foo.lzs .  There are some oddities
    (that were present before) which make the file need to be editted if it is to be used as
    input for the script compiler.  For example, a simple test case might end its
    script output with:

canvas.resourcetable["scrollDragDimples_rsc"]={ width : 5, height :11};
canvas.resourcetable["scrollDragTop_rsc"]={ width : 13, height :2};
canvas.resourcetable["scrollDrag_rsc"]={ width : 13, height :1};
__LzDebug.makeDebugWindow()canvas.initDone()

     It appears that __LzDebug.makeDebugWindow() and convas.initDone() are separate statements
     that should have semicolon separators.

Tests:
   smokecheck x (swf8,dhtml) + swf9 hello



Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java	2008-04-25 14:55:44 UTC (rev 8855)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Main.java	2008-04-25 18:07:04 UTC (rev 8856)
@@ -124,6 +124,7 @@
         boolean flushScriptCache = true;
         Boolean forceTransCode = null;
         String outFileArg = null;
+        boolean saveScriptOption = false;
 
         for (int i = 0; i < args.length; i++) {
             String arg = args[i].intern();
@@ -170,9 +171,7 @@
                       return 1;
                     }
                 } else if (arg == "-S" || arg == "--script") {
-                    // TODO: [2007-05-25 ptw] This is bogus -- should write out a .lzs file
-                    Logger.getLogger(org.openlaszlo.sc.ScriptCompiler.class)
-                        .setLevel(Level.ALL);
+                    saveScriptOption = true;
                 } else if (arg == "--script-cache-dir") {
                     scriptCacheDir = safeArg("--script-cache-dir", args, ++i);
                     if (scriptCacheDir == null) {
@@ -290,9 +289,17 @@
         int status = 0;
         for (Iterator iter = files.iterator(); iter.hasNext(); ) {
             String sourceName = (String) iter.next();
-            if (files.size() > 1)
-                System.err.println("Compiling " + sourceName);
-            status += compile(compiler, logger, sourceName, outFileName, outDir);
+            String intermediateName = null;
+
+            if (saveScriptOption) {
+                if (sourceName.endsWith(".lzx")) {
+                    intermediateName = sourceName.replaceAll(".lzx$", ".lzs");
+                }
+                else {
+                    intermediateName = sourceName + ".lzs";
+                }
+            }
+            status += compile(compiler, logger, sourceName, intermediateName, outFileName, outDir);
         }
         return status;
     }
@@ -320,6 +327,7 @@
     static private int compile(Compiler compiler,
                                 Logger logger,
                                 String sourcePath,
+                                String intermediateName,
                                 String outName,
                                 String outDir)
     {
@@ -345,7 +353,13 @@
           outDir = sourceFile.getParent();
         }
         File objectFile = new File(outDir, outName);
+        BufferedWriter intermediate = null;
         try {
+          if (intermediateName != null) {
+            intermediate = new BufferedWriter(new FileWriter(intermediateName));
+            org.openlaszlo.sc.ScriptCompiler.setIntermediateWriter(intermediate);
+          }
+
           System.err.println("Compiling: " + sourceFile + " to " + objectFile);
             compiler.compile(sourceFile, objectFile, new Properties());
             if (finalName != null) {
@@ -379,6 +393,19 @@
                 );
             return 3;
         }
+        finally {
+            if (intermediate != null) {
+                org.openlaszlo.sc.ScriptCompiler.setIntermediateWriter(null);
+                try {
+                    // The output often does not end with a newline
+                    intermediate.write("\n");
+                    intermediate.close();
+                }
+                catch (IOException ioe) {
+                    throw new CompilationError("Could not create intermediate script file: " + ioe);
+                }
+            }
+        }
         return 0;
     }
 }

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ScriptCompiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ScriptCompiler.java	2008-04-25 14:55:44 UTC (rev 8855)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ScriptCompiler.java	2008-04-25 18:07:04 UTC (rev 8856)
@@ -28,7 +28,8 @@
  */
 public class ScriptCompiler extends Cache {
     private static Logger mLogger = Logger.getLogger(ScriptCompiler.class);
-    
+    private static Writer intermediateWriter = null;
+
     static public final String SCRIPT_CACHE_NAME = "scache";
 
     /** Map(String properties+script, byte[] bytes), or null if the
@@ -47,6 +48,10 @@
         return mScriptCache;
     }
 
+    public static void setIntermediateWriter(Writer writer) {
+        intermediateWriter = writer;
+    }
+
     public static synchronized ScriptCompiler initScriptCompilerCache(File cacheDirectory, Properties initprops)
       throws IOException {
         if (mScriptCache != null) {
@@ -148,8 +153,23 @@
         return propstring;
     }
 
+    /** Collects the script into an intermediate output file
+     * if we are configured to do so.
+     *
+     * @param script a script
+     */
+    private static void writeIntermediateFile(String script)
+    {
+        if (intermediateWriter != null) {
+            try {
+                intermediateWriter.write(script);
+            }
+            catch (IOException ioe) {
+                throw new CompilationError("Could not create intermediate script file: " + ioe);
+            }
+        }
+    }
 
-
     /** Compiles the specified script into bytecode
      *
      * @param script a script
@@ -158,9 +178,8 @@
     public static byte[] compileToByteArray(String script,
                                             Properties properties) {
 
-        if (mLogger.getLevel() == Level.ALL) {
-            System.out.println(script);
-        }
+        writeIntermediateFile(script);
+
         // We only want to keep off the properties that affect the
         // compilation.  Currently, "filename" is the only property
         // that tends to change and that the script compiler ignores,



More information about the Laszlo-checkins mailing list