[Laszlo-checkins] r12722 - openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler

hqm@openlaszlo.org hqm at openlaszlo.org
Mon Feb 2 17:55:22 PST 2009


Author: hqm
Date: 2009-02-02 17:55:19 -0800 (Mon, 02 Feb 2009)
New Revision: 12722

Modified:
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
   openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
Log:
Change 20090202-hqm-n by hqm at badtzmaru.home on 2009-02-02 20:50:57 EST
    in /Users/hqm/openlaszlo/trunk5
    for http://svn.openlaszlo.org/openlaszlo/trunk

Summary: set compiler defaults explicitly in one place

New Features:

Bugs Fixed:

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

Documentation:

Release Notes:

Details:

+ Setup all compiler options defaults in one place, in CompilationEnvironment


Tests:

+ demo applications compile; amazon, lzpix, in all runtimes

ant lztest
smokecheck in swf8,swf9,dhtml




Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2009-02-03 01:00:41 UTC (rev 12721)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/CompilationEnvironment.java	2009-02-03 01:55:19 UTC (rev 12722)
@@ -27,14 +27,15 @@
  */
 public class CompilationEnvironment {
     private final Properties mProperties;
-    
+    // Stores the user-supplied compilation properties, either from command line or query args
+    private final Properties mCommandLineOptions;
     // TODO this is suspicious. What if we want to change the build folder?
     public static final String DEFAULT_OUTPUT_DIR = "build";
     
-    public static final String RUNTIME_PROPERTY = "runtime";
-    public static final String PROXIED_PROPERTY           = "lzproxied";
-    public static final String DEBUG_PROPERTY             = "debug";
-    public static final String DEBUG_EVAL_PROPERTY        = "debugEval";
+    public static final String RUNTIME_PROPERTY            = "runtime";
+    public static final String PROXIED_PROPERTY            = "lzproxied";
+    public static final String DEBUG_PROPERTY              = "debug";
+    public static final String DEBUG_EVAL_PROPERTY         = "debugEval";
     public static final String SOURCE_ANNOTATIONS_PROPERTY = "lzsourceannotations";
 
     // matches the values of sc.Compiler.DEBUG_BACKTRACE, NAME_FUNCTIONS, etc.
@@ -54,6 +55,7 @@
     public static final String EMBEDFONTS_PROPERTY    = "embedfonts";
     public static final String SOURCELOCATOR_PROPERTY = "sourcelocators";
 
+
     // Flag used internally, to mark whether the user instantiated a <debug>
     // tag manually. If they didn't, we need to add a call to instantiate one.
     public static final String USER_DEBUG_WINDOW     = "userdebugwindow";
@@ -142,9 +144,6 @@
     private static boolean mDefaultTextWidthInitialized = false;
     private static int mDefaultTextWidth = 100;
 
-    /** Default SWF version to compile to */
-    private String mDefaultRuntime = LPS.getRuntimeDefault();
-
     /** Used for compiling SWF loadable libraries to refer to _level0 */
     private String mGlobalPrefix = "";
 
@@ -165,13 +164,18 @@
      * @param mcache
      */
     CompilationEnvironment(Properties properties, FileResolver resolver, CompilerMediaCache mcache) {
+        mCommandLineOptions = properties;
+        mProperties = new Properties();
+        initCompilerOptionDefaults();
+        // Merge command line options to override defaults
+        mProperties.putAll(properties);
+        
         // Use a local symbol generator so that we recycle method
         // names for each new view, to keep the constant pool small.
         this.methodNameGenerator = new SymbolGenerator("$m");
         this.mSchema = new ViewSchema(this);
         // lzc depends on the properties being shared, because it sets
         // them after creating the environment
-        this.mProperties = properties;
         this.mFileResolver = resolver;
         this.mParser = new Parser();
         this.mParser.setResolver(resolver);
@@ -185,6 +189,7 @@
         // unique names!
         this.methodNameGenerator = srcEnv.methodNameGenerator;
         this.mProperties = (Properties) (srcEnv.getProperties().clone());
+        this.mCommandLineOptions = srcEnv.mCommandLineOptions;
         this.mFileResolver = srcEnv.getFileResolver();
         this.mParser = new Parser();
         this.mParser.setResolver(this.mFileResolver);
@@ -204,7 +209,26 @@
     public CompilationEnvironment() {
         this(new Properties(), FileResolver.DEFAULT_FILE_RESOLVER, null);
     }
-    
+
+    // Compiler option default values
+    public void initCompilerOptionDefaults() {
+        mProperties.put( BACKTRACE_PROPERTY,          "false");
+        mProperties.put( CONSOLEDEBUG_PROPERTY,       "false");
+        mProperties.put( DEBUG_EVAL_PROPERTY,         "false");
+        mProperties.put( DEBUG_PROPERTY,              "false");
+        mProperties.put( EMBEDFONTS_PROPERTY,         "false");
+        mProperties.put( LINK_PROPERTY,               "true" );
+        mProperties.put( LOGDEBUG_PROPERTY,           "false");
+        mProperties.put( NAME_FUNCTIONS,              "false");
+        mProperties.put( PROFILE_PROPERTY,            "false");
+        mProperties.put( PROXIED_PROPERTY,            "true");
+        mProperties.put( REMOTEDEBUG_PROPERTY,        "false");
+        mProperties.put( RUNTIME_PROPERTY,             LPS.getRuntimeDefault());
+        mProperties.put( SOURCELOCATOR_PROPERTY,      "false");
+        mProperties.put( SOURCE_ANNOTATIONS_PROPERTY, "false");
+        mProperties.put( TRACK_LINES,                 "false");
+    }
+
     void setApplicationFile(File file) {
         mApplicationFile = file;
         mCompilerErrors.setFileBase(file.getParent());
@@ -519,9 +543,18 @@
         mProperties.setProperty(name, value);
     }
 
+    void setCommandLineOption(String name, String val) {
+        mCommandLineOptions.setProperty(name,val);
+        setProperty(name, val);
+    }
+
+    String getCommandLineOption(String name) {
+        return mCommandLineOptions.getProperty(name);
+    }
+
     /** Return target Flash version (5, 6, ...) **/
     public String getRuntime() {
-        return getProperty(RUNTIME_PROPERTY, mDefaultRuntime);
+        return getProperty(RUNTIME_PROPERTY);
     }
 
     public boolean isAS3() {

Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2009-02-03 01:00:41 UTC (rev 12721)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/Compiler.java	2009-02-03 01:55:19 UTC (rev 12722)
@@ -124,8 +124,15 @@
     /** Create a CompilationEnvironment with the properties and 
      * FileResolver of this compiler.
      */
-    public CompilationEnvironment makeCompilationEnvironment() {
-        return new CompilationEnvironment(mProperties, mFileResolver, mMediaCache);
+    public CompilationEnvironment makeCompilationEnvironment(Properties options) {
+        Properties props = new Properties();
+        // First copy in properties that were set on the Compiler instance
+        props.putAll(mProperties);
+        // Then merge in properties that were passed into the call to compile()
+        if (options != null) {
+            props.putAll(options);
+        }
+        return new CompilationEnvironment(props, mFileResolver, mMediaCache);
     }
     
     /** Compiles <var>sourceFile</var> to <var>objectFile</var>.  If
@@ -177,14 +184,14 @@
 
         // Compile to a byte-array, and write out to objectFile, and 
         // write a copy into sourceFile.[swf|js] if this is a serverless deployment.
-        CompilationEnvironment env = makeCompilationEnvironment();
+        CompilationEnvironment env = makeCompilationEnvironment(props);
         ByteArrayOutputStream bstream = new ByteArrayOutputStream();
         OutputStream ostream = new FileOutputStream(objectFile);
         env.setObjectFile(objectFile);
 
         boolean success = false;
         try {
-            Canvas canvas = compile(sourceFile, bstream, props, env);
+            Canvas canvas = compile(sourceFile, bstream, env);
             bstream.writeTo(ostream);
             ostream.close();
 
@@ -192,7 +199,7 @@
             if (canvas != null && !canvas.isProxied()) {
 
                 // Create a foo.lzx.[js|swf] serverless deployment file for sourcefile foo.lzx
-                String runtime = props.getProperty(CompilationEnvironment.RUNTIME_PROPERTY);
+                String runtime = env.getRuntime();
                 String soloExtension = getObjectFileExtensionForRuntime(runtime);
 
                 OutputStream fostream = null;
@@ -296,7 +303,7 @@
      *
      */
 
-    public Canvas compile(File file, OutputStream ostr, Properties props, CompilationEnvironment env)
+    public Canvas compile(File file, OutputStream ostr, CompilationEnvironment env)
         throws CompilationError, IOException
     {
         mLogger.info("compiling " + file + "...");
@@ -304,89 +311,9 @@
         CompilationErrorHandler errors = env.getErrorHandler();
         env.setApplicationFile(file);
         
-        // Copy target properties (debug, logdebug, profile, krank,
-        // runtime) from props arg to CompilationEnvironment
-        String runtime = props.getProperty(env.RUNTIME_PROPERTY);
         boolean linking = (! "false".equals(env.getProperty(CompilationEnvironment.LINK_PROPERTY)));
         boolean noCodeGeneration = "true".equals(env.getProperty(CompilationEnvironment.NO_CODE_GENERATION));
 
-        if (runtime != null) {
-            mLogger.info("canvas compiler compiling runtime = " + runtime);
-            env.setProperty(env.RUNTIME_PROPERTY, runtime);
-        }
-
-        String proxied = props.getProperty(CompilationEnvironment.PROXIED_PROPERTY);
-        mLogger.debug(
-/* (non-Javadoc)
- * @i18n.test
- * @org-mes="looking for lzproxied, props= " + p[0]
- */
-            org.openlaszlo.i18n.LaszloMessages.getMessage(
-                Compiler.class.getName(),"051018-257", new Object[] {props.toString()})
-);
-        if (proxied != null) {
-            mLogger.debug(
-/* (non-Javadoc)
- * @i18n.test
- * @org-mes="setting lzproxied to " + p[0]
- */
-            org.openlaszlo.i18n.LaszloMessages.getMessage(
-                Compiler.class.getName(),"051018-266", new Object[] {proxied})
-);
-            env.setProperty(CompilationEnvironment.PROXIED_PROPERTY, proxied);
-        }
-
-        String debug = props.getProperty(CompilationEnvironment.DEBUG_PROPERTY);
-        if (debug != null) {
-            env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, debug);
-        }
-
-        String lzconsoledebug = props.getProperty(CompilationEnvironment.CONSOLEDEBUG_PROPERTY);
-        if (lzconsoledebug != null) {
-            env.setProperty(CompilationEnvironment.CONSOLEDEBUG_PROPERTY, lzconsoledebug);
-        }
-        
-
-
-        String backtrace = props.getProperty(CompilationEnvironment.BACKTRACE_PROPERTY);
-        if (backtrace != null) {
-            if ("true".equals(backtrace)) {
-                env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, "true" );
-            }
-            env.setProperty(CompilationEnvironment.BACKTRACE_PROPERTY, backtrace);
-        }
-
-
-        String profile = props.getProperty(CompilationEnvironment.PROFILE_PROPERTY);
-        if (profile != null) {
-            env.setProperty(CompilationEnvironment.PROFILE_PROPERTY, profile);
-        }
-
-        String logdebug = props.getProperty(CompilationEnvironment.LOGDEBUG_PROPERTY);
-        if (logdebug != null) {
-            env.setProperty(CompilationEnvironment.LOGDEBUG_PROPERTY, logdebug);
-        }
-
-        String sourcelocators = props.getProperty(CompilationEnvironment.SOURCELOCATOR_PROPERTY);
-        if (sourcelocators != null) {
-            env.setProperty(CompilationEnvironment.SOURCELOCATOR_PROPERTY, sourcelocators);
-        }
-
-        String sourceannotations = props.getProperty(CompilationEnvironment.SOURCE_ANNOTATIONS_PROPERTY);
-        if (sourceannotations != null) {
-            env.setProperty(CompilationEnvironment.SOURCE_ANNOTATIONS_PROPERTY, sourceannotations);
-        }
-
-        String trackLines = props.getProperty(CompilationEnvironment.TRACK_LINES);
-        if (trackLines != null) {
-            env.setProperty(CompilationEnvironment.TRACK_LINES, trackLines);
-        }
-
-        String nameFunctions = props.getProperty(CompilationEnvironment.NAME_FUNCTIONS);
-        if (nameFunctions != null) {
-            env.setProperty(CompilationEnvironment.NAME_FUNCTIONS, nameFunctions);
-        }
-        
         try {
             mLogger.debug(
 /* (non-Javadoc)
@@ -414,7 +341,7 @@
             compileTimeConstants.put("$backtrace", new Boolean(
                                          env.getBooleanProperty(CompilationEnvironment.BACKTRACE_PROPERTY)));
 
-            runtime = env.getProperty(env.RUNTIME_PROPERTY);
+            String runtime = env.getProperty(env.RUNTIME_PROPERTY);
             // Must be kept in sync with server/sc/lzsc.py main
             env.setRuntimeConstants(runtime);
 
@@ -424,7 +351,7 @@
             checkKnownRuntime(env.getProperty(env.RUNTIME_PROPERTY));
 
             // cssfile cannot be set in the canvas tag
-            String cssfile = props.getProperty(CompilationEnvironment.CSSFILE_PROPERTY);
+            String cssfile = env.getProperty(CompilationEnvironment.CSSFILE_PROPERTY);
             if (cssfile != null) {
                 mLogger.info("Got cssfile named: " + cssfile);             
                 cssfile = root.getAttributeValue("cssfile");
@@ -525,7 +452,7 @@
 
     public void compileAndWriteToSWF (String script, String seqnum, OutputStream out, String runtime) {
         try {
-            CompilationEnvironment env = makeCompilationEnvironment();
+            CompilationEnvironment env = makeCompilationEnvironment(null);
             env.setProperty(CompilationEnvironment.DEBUG_PROPERTY, true);
             Properties props = (Properties) env.getProperties().clone();
             env.setProperty(env.RUNTIME_PROPERTY, runtime);



More information about the Laszlo-checkins mailing list