[Laszlo-dev] [Laszlo-checkins] r11983 - in openlaszlo/trunk: WEB-INF/lps/server/src/org/openlaszlo/compiler WEB-INF/lps/server/src/org/openlaszlo/sc test/snippets
P T Withington
ptw at pobox.com
Fri Dec 5 09:13:14 PST 2008
Did you forget an add?
[javac] /Users/ptw/OpenLaszlo/trunk/WEB-INF/lps/server/src/org/
openlaszlo/compiler/CompilationEnvironment.java:739: cannot find symbol
[javac] symbol : class LibraryCompilation
On 2008-12-05, at 11:51EST, hqm at openlaszlo.org wrote:
> Author: hqm
> Date: 2008-12-05 08:51:21 -0800 (Fri, 05 Dec 2008)
> New Revision: 11983
>
> Added:
> openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> ScriptCompilerInfo.java
> openlaszlo/trunk/test/snippets/case1-lib.lzx
> openlaszlo/trunk/test/snippets/case1.lzx
> openlaszlo/trunk/test/snippets/case2-lib.lzx
> openlaszlo/trunk/test/snippets/case2.lzx
> 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
> openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> ImportCompiler.java
> openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> ObjectWriter.java
> openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> SWF9Writer.java
> openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> Compiler.java
> openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> SWF9External.java
> Log:
> Change 20081204-hqm-K by hqm at badtzmaru.home on 2008-12-04 23:20:15 EST
> in /Users/hqm/openlaszlo/trunk
> for http://svn.openlaszlo.org/openlaszlo/trunk
>
> Summary: allow classes in <import> libraries to extend classes from
> main app
>
> New Features:
>
> Bugs Fixed: LPP-740
>
> Technical Reviewer: ptw
> QA Reviewer: promanik
> Doc Reviewer: (pending)
>
> Documentation:
>
> Release Notes:
>
> Details:
>
> + In order to allow classes in an <import> (loadable library) to
> subclass
> classes in the main app, the flex compiler must be given a pointer
> to the main
> app's as3 working dir, so it can resolve links with the superclasses.
>
> This change addresses this issue:
>
> 1) Main app defines class A, library defines "class B extends A"
>
> This change reorders the compilations in the tag compiler, so the main
> app is compiled first, and any <import> libraries are compiled
> afterwards. A pointer to the main application's as3 tmp working dir is
> passed to any compilations of <import> libraries. The flex compiler
> is given these extra args
>
> cmd.add("-compiler.source-path+="+mInfo.mainAppWorkDir);
> cmd.add("-external-library-path+="+mInfo.mainAppWorkDir);
>
> which tells it to check links against the main app dir, but not to
> include
> any of those classes into the library it is compiling.
>
> + Note, this change does not addresss these cases:
>
> 2) Library defines class A, main app defines "class B extends A"
>
> 3) Main app defines class A, library defines "class B extends A",
> main app defines "class C extends B"
>
> Cases 2) and 3) actually happen to produce running code, but the code
> for the subclasses all gets put into the main app, not the library (I
> think the tag compiler is doing that automatically).
>
> Tests:
>
> + test case from bug, with slight variants, are in
> test/snippets/case1.lzx
> test/snippets/case2.lzx
>
> Both examples should display two buttons, one titles "Main" and the
> other titled "Library"
>
>
>
> 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 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> CompilationEnvironment.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -17,6 +17,7 @@
> import org.openlaszlo.utils.ChainedException;
> import org.openlaszlo.utils.FileUtils;
> import org.openlaszlo.xml.internal.XMLUtils;
> +import org.openlaszlo.sc.ScriptCompilerInfo;
>
> /** Encapsulates all the context that script compilation needs to
> * refer to. Instances of this class are threaded through the calls
> @@ -147,6 +148,15 @@
> /** Used for compiling SWF loadable libraries to refer to
> _level0 */
> private String mGlobalPrefix = "";
>
> + private List mLibraryCompilations = new ArrayList();
> +
> + /** Information about where the ScriptCompiler put intermediate
> + * working files. This is used for linking loadable libraries for
> + * as3 runtime */
> + private ScriptCompilerInfo mMainAppInfo;
> +
> + private CompilationEnvironment mMainCompilationEnv;
> +
> /** Constructs an instance.
> * @param properties compilation properties
> * @param resolver
> @@ -183,6 +193,7 @@
> this.mImportedLibraryFiles = new
> HashSet(srcEnv.getImportedLibraryFiles());
> this.mLoadableImportedLibraryFiles =
> srcEnv.getLoadableImportedLibraryFiles();
> this.mResourceNames = srcEnv.getResourceNames();
> + this.mMainCompilationEnv = srcEnv;
> }
>
> /** Use this constructor for unit testing. The Compiler uses the
> @@ -725,4 +736,25 @@
> }
> }
>
> + public void queueLibraryCompilation(LibraryCompilation lc) {
> + mLibraryCompilations.add(lc);
> + }
> +
> + public List libraryCompilationQueue () {
> + return mLibraryCompilations;
> + }
> +
> + public void setScriptCompilerInfo(ScriptCompilerInfo info) {
> + mMainAppInfo = info;
> + }
> +
> + public ScriptCompilerInfo getScriptCompilerInfo() {
> + return mMainAppInfo;
> + }
> +
> + public CompilationEnvironment getMainCompilationEnv() {
> + return mMainCompilationEnv;
> + }
> +
> +
> }
>
> 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 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> Compiler.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -201,6 +201,13 @@
> }
> }
> }
> +
> + List libs = env.libraryCompilationQueue();
> + for (int i = 0; i < libs.size(); i++) {
> + LibraryCompilation lc = (LibraryCompilation)
> libs.get(i);
> + lc.importCompiler.compileLibrary(lc.infile,
> lc.outfile, lc.liburl, lc.element);
> + }
> +
> success = true;
> return canvas;
> } catch (java.lang.OutOfMemoryError e) {
>
> Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/
> compiler/ImportCompiler.java
> ===================================================================
> --- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> ImportCompiler.java 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> ImportCompiler.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -115,7 +115,7 @@
> throw new CompilationError(element, e);
> }
>
> - compileLibrary(libsrcfile, objfilename, objpath, module);
> + queueLibraryCompilation(libsrcfile, objfilename,
> objpath, module);
>
> // Emit code into main app to instantiate a LzLibrary
> // object, which implements the load() method.
> @@ -134,7 +134,20 @@
> }
> }
>
> +
> +
> /**
> + * Queue this library to be compiled. The actual compilation must
> + * be done after the main application is compiled, so that the
> AS3
> + * compiler can use it to link against (actually, just to check
> + * the links).
> + */
> + void queueLibraryCompilation(File infile, String outfile,
> String liburl, Element element) {
> + LibraryCompilation lc = new LibraryCompilation(this,
> infile, outfile, liburl, element);
> + mEnv.queueLibraryCompilation(lc);
> + }
> +
> + /**
> * Compile a standalone binary library file with no canvas.
> */
> void compileLibrary(File infile, String outfile, String liburl,
> Element element) throws CompilationError{
> @@ -226,18 +239,6 @@
>
> ViewCompiler.checkUnresolvedResourceReferences (env);
>
> - // Need to emit a copy of the globals declarations
> - // into the library app code we're building, because
> - // the swf9 compiler needs to be able to have
> - // declarations for them to compile references to
> - // them.
> - String globals = "";
> - for (Iterator v =
> mEnv.getIds().keySet().iterator(); v.hasNext(); ) {
> - String id = (String)v.next();
> - globals += ("var " +id + " = null;\n");
> - }
> - env.compileScript(globals);
> -
> writer.closeSnippet();
> env.compileScript("// FINISH compiling <IMPORT>
> Library "+liburl+"\n");
> } finally {
> @@ -274,3 +275,4 @@
>
> }
> }
> +
>
> Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/
> compiler/ObjectWriter.java
> ===================================================================
> --- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> ObjectWriter.java 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> ObjectWriter.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -540,5 +540,9 @@
> this.mExecutionTimeout = timeout;
> }
>
> +
> + public CompilationEnvironment getCompilationEnvironment () {
> + return mEnv;
> + }
> }
>
>
> Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/
> compiler/SWF9Writer.java
> ===================================================================
> --- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> SWF9Writer.java 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/compiler/
> SWF9Writer.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -10,6 +10,7 @@
> package org.openlaszlo.compiler;
>
> import org.openlaszlo.sc.ScriptCompiler;
> +import org.openlaszlo.sc.ScriptCompilerInfo;
> import org.openlaszlo.sc.Compiler;
> import org.openlaszlo.server.LPS;
> import org.openlaszlo.utils.ChainedException;
> @@ -392,10 +393,23 @@
>
> */
>
> + ScriptCompilerInfo compilerInfo = new ScriptCompilerInfo();
> + props.put(org.openlaszlo.sc.Compiler.COMPILER_INFO,
> compilerInfo);
> +
> +
> try {
> scriptWriter.close();
> byte[] objcode =
> ScriptCompiler.compileToByteArray(scriptBuffer.toString(), props);
> InputStream input = new ByteArrayInputStream(objcode);
> +
> + // Make a note of the location of the as3 working file
> dir
> + // used for compiling the main app. This is needed so the
> + // flex compiler can link any loadable libraries
> + // (<import>'s) against it.
> + File workdir = compilerInfo.workDir;
> + compilerInfo.mainAppWorkDir = workdir;
> + mEnv.setScriptCompilerInfo(compilerInfo);
> +
> FileUtils.send(input, mStream);
> } catch (org.openlaszlo.sc.CompilerException e) {
> throw new CompilationError(e);
> @@ -502,6 +516,10 @@
>
> */
>
> + // This will contain a pointer to the working dir created
> by compiling the main app
> + ScriptCompilerInfo compilerInfo =
> mEnv.getMainCompilationEnv().getScriptCompilerInfo();
> + props.put(org.openlaszlo.sc.Compiler.COMPILER_INFO,
> compilerInfo);
> +
> try {
>
> scriptWriter.close();
>
> Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> Compiler.java
> ===================================================================
> --- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> Compiler.java 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> Compiler.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -457,6 +457,7 @@
> public static String CATCH_FUNCTION_EXCEPTIONS =
> "catchFunctionExceptions";
> public static String COMPILE_TRACE = "compileTrace";
> public static String COMPILE_TIME_CONSTANTS =
> "compileTimeConstants";
> + public static String COMPILER_INFO = "compilerInfo";
> public static String CONSTRAINT_FUNCTION = "constraintFunction";
> public static String DEBUG = "debug";
> public static String DEBUG_BACKTRACE = "debugBacktrace";
>
> Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> SWF9External.java
> ===================================================================
> --- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> SWF9External.java 2008-12-05 16:31:11 UTC (rev 11982)
> +++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> SWF9External.java 2008-12-05 16:51:21 UTC (rev 11983)
> @@ -50,8 +50,9 @@
> */
> public static final String WORK_DIR_PREFIX = "lzgen";
>
> - private File workdir = createCompilationWorkDir();
> + private File workdir;
> private Compiler.OptionMap options;
> + private ScriptCompilerInfo mInfo;
>
> /*
> * Used by getFileNameForClassName to prevent filename conflicts.
> @@ -70,6 +71,11 @@
>
> public SWF9External(Compiler.OptionMap options) {
> this.options = options;
> + mInfo = (ScriptCompilerInfo) options.get(Compiler.COMPILER_INFO);
> + if (mInfo == null) {
> + mInfo = new ScriptCompilerInfo();
> + }
> + workdir = createCompilationWorkDir();
> }
>
> /**
> @@ -138,6 +144,8 @@
> catch (IOException ioe) {
> throw new CompilerError("getCompilationWorkDir: cannot get
> temp directory: " + ioe);
> }
> + // Copy the pointer to our work directory to the
> ScriptCompilerInfo object
> + this.mInfo.workDir = f;
> return f;
> }
>
> @@ -905,11 +913,7 @@
> cmd.add(options.get(Compiler.CANVAS_HEIGHT, "600"));
> if (options.getBoolean(Compiler.SWF9_USE_RUNTIME_SHARED_LIB))
> { //
> // TODO [hqm 2008-11] This usage of the Flash
> - // "runtime-shared-library" feature does not work yet. No
> matter
> - // what I try, when the app loads, it cannot find or load the
> - // LFC as a runtime shared library. When this does work, it
> - // will be a good option to reduce app download size when
> - // multiple Laszlo apps are served from the same server.
> + // "runtime-shared-library" feature does not work yet. See
> LPP-7387
> cmd.add("-runtime-shared-library-path="+
> getLFCLibrary(debug) + "," +
> "lib" + File.separator +
> getLFCLibraryRelativeURL(debug) +
> ",," // specifies explicitly empty policy file arg
> @@ -924,6 +928,15 @@
> cmd.add("-external-library-path+="+getLFCLibrary(debug));
> }
>
> + if (options.getBoolean(Compiler.SWF9_LOADABLE_LIB)) {
> + // If it's a loadable lib, check links against the main app,
> + // but don't link those classes in. We do this by declaring
> the main app
> + // source working directory as a external-library-path
> + cmd.add("-compiler.source-path+="+mInfo.mainAppWorkDir);
> + cmd.add("-external-library-path+="+mInfo.mainAppWorkDir);
> +
> + }
> +
> // Add in WEB-INF/flexlib and APPDIR/flexlib to flex library
> search paths if they exist
> if ((new File(getFlexPathname("flexlib"))).isDirectory()) {
> cmd.add("-compiler.library-path+=" +
> getFlexPathname("flexlib"));
>
> Added: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/
> ScriptCompilerInfo.java
>
>
> Property changes on: openlaszlo/trunk/WEB-INF/lps/server/src/org/
> openlaszlo/sc/ScriptCompilerInfo.java
> ___________________________________________________________________
> Name: svn:mime-type
> + text/plain
> Name: svn:eol-style
> + native
>
> Added: openlaszlo/trunk/test/snippets/case1-lib.lzx
>
>
> Property changes on: openlaszlo/trunk/test/snippets/case1-lib.lzx
> ___________________________________________________________________
> Name: svn:mime-type
> + text/plain
> Name: svn:eol-style
> + native
>
> Added: openlaszlo/trunk/test/snippets/case1.lzx
>
>
> Property changes on: openlaszlo/trunk/test/snippets/case1.lzx
> ___________________________________________________________________
> Name: svn:mime-type
> + text/plain
> Name: svn:eol-style
> + native
>
> Added: openlaszlo/trunk/test/snippets/case2-lib.lzx
>
>
> Property changes on: openlaszlo/trunk/test/snippets/case2-lib.lzx
> ___________________________________________________________________
> Name: svn:mime-type
> + text/plain
> Name: svn:eol-style
> + native
>
> Added: openlaszlo/trunk/test/snippets/case2.lzx
>
>
> Property changes on: openlaszlo/trunk/test/snippets/case2.lzx
> ___________________________________________________________________
> Name: svn:mime-type
> + text/plain
> Name: svn:eol-style
> + native
>
>
> _______________________________________________
> Laszlo-checkins mailing list
> Laszlo-checkins at openlaszlo.org
> http://www.openlaszlo.org/mailman/listinfo/laszlo-checkins
More information about the Laszlo-dev
mailing list