protected int compile()

in modules/compiler/src/java/flex2/tools/oem/Application.java [823:1103]


    protected int compile(boolean incremental)
    {
        try 
        {
            messages.clear();
    
            // if there is no configuration, use the default... but don't populate this.configuration.
            OEMConfiguration tempOEMConfiguration;
            if (oemConfiguration == null)
            {
                tempOEMConfiguration = (OEMConfiguration) getDefaultConfiguration(true);
            }
            else
            {
                tempOEMConfiguration = OEMUtil.getApplicationConfiguration(constructCommandLine(oemConfiguration),
                                                                           oemConfiguration.keepLinkReport(),
                                                                           oemConfiguration.keepSizeReport(),
                                                                           OEMUtil.getLogger(logger, messages),
                                                                           resolver, mimeMappings);
            }
    
            // if c is null, which indicates problems, this method will return.
            if (tempOEMConfiguration == null)
            {
                clean(false /* cleanData */,
                      false /* cleanCache */,
                      false /* cleanOutput */,
                      true /* cleanConfig */,
                      false /* cleanMessages */,
                      false /* cleanThreadLocals */);
                return FAIL;
            }
            else if (oemConfiguration != null && oemConfiguration.keepConfigurationReport())
            {
                configurationReport = OEMUtil.formatConfigurationBuffer(tempOEMConfiguration.cfgbuf);
            }
    
            setupFontManager(tempOEMConfiguration);
    
            if (oemConfiguration != null)
            {
                oemConfiguration.cfgbuf = tempOEMConfiguration.cfgbuf;
            }
    
            if (tempOEMConfiguration.configuration.benchmark())
            {
                benchmark = CompilerAPI.runBenchmark();
                benchmark.setTimeFilter(tempOEMConfiguration.configuration.getBenchmarkTimeFilter());
                benchmark.startTime(Benchmark.PRECOMPILE);
            }
            else
            {
                CompilerAPI.disableBenchmark();
            }
    
            // initialize some ThreadLocal variables...
            cc.run();
            OEMUtil.init(OEMUtil.getLogger(logger, messages), mimeMappings, meter, resolver, cc);
    
            Map licenseMap = OEMUtil.getLicenseMap(tempOEMConfiguration.configuration);
    
            if (data == null || !incremental)
            {
                String compilationType = (cacheName != null) ? "inactive" : "full";
    
                if (benchmark != null)
                {
                    benchmark.benchmark2("Starting " + compilationType + " compile for " + getOutput(), true);
                }
    
                int returnValue = recompile(false, licenseMap, tempOEMConfiguration);
    
                if (benchmark != null)
                {
                    benchmark.benchmark2("Ending " + compilationType + " compile for " + getOutput(), true);
                }
    
                clean(returnValue == FAIL /* cleanData */,
                      false /* cleanCache */,
                      false /* cleanOutput */,
                      true /* cleanConfig */,
                      false /* cleanMessages */,
                      false /* cleanThreadLocals */);
                return returnValue;
            }

            CompilerAPI.setupHeadless(tempOEMConfiguration.configuration);
    
            CompilerConfiguration compilerConfig = tempOEMConfiguration.configuration.getCompilerConfiguration();
            NameMappings mappings = CompilerAPI.getNameMappings(tempOEMConfiguration.configuration);
    
            Transcoder[] transcoders = WebTierAPI.getTranscoders(tempOEMConfiguration.configuration);
            SubCompiler[] compilers = WebTierAPI.getCompilers(compilerConfig, mappings, transcoders);
    
            CompilerSwcContext swcContext = new CompilerSwcContext(true);
            try
            {
                swcContext.load( compilerConfig.getLibraryPath(),
                                 flex2.compiler.common.Configuration.getAllExcludedLibraries(compilerConfig, tempOEMConfiguration.configuration),
                                 compilerConfig.getThemeFiles(),
                                 compilerConfig.getIncludeLibraries(),
                                 mappings,
                                 I18nUtils.getTranslationFormat(compilerConfig),
                                 data.swcCache );
            }
            catch (SwcException ex)
            {
                clean(false /* cleanData */,
                      false /* cleanCache */,
                      false /* cleanOutput */,
                      true /* cleanConfig */,
                      false /* cleanMessages */,
                      false /* cleanThreadLocals */);
                return FAIL;
            }
    
            // save the generated cache if the caller provided a libraryCache.
            if (libraryCache != null)
            {
                libraryCache.setSwcCache(data.swcCache);
            }
    
            data.includes = new HashSet<String>(swcContext.getIncludes());
            data.excludes = new HashSet<String>(swcContext.getExterns());
            tempOEMConfiguration.configuration.addExterns( swcContext.getExterns() );
            tempOEMConfiguration.configuration.addIncludes( swcContext.getIncludes() );
            tempOEMConfiguration.configuration.getCompilerConfiguration().addThemeCssFiles( swcContext.getThemeStyleSheets() );
    
            // recompile or incrementally compile...
            if (OEMUtil.isRecompilationNeeded(data, swcContext, tempOEMConfiguration))
            {
                data.resources = new ResourceContainer();
    
                if (benchmark != null)
                {
                    benchmark.benchmark2("Starting full compile for " + getOutput(), true);
                }
    
                clean(true /* cleanData */,
                      false /* cleanCache */,
                      false /* cleanOutput */,
                      true /* cleanConfig */,
                      false /* cleanMessages */,
                      false /* cleanThreadLocals */);
                int returnValue = recompile(true, licenseMap, tempOEMConfiguration);
    
                if (benchmark != null)
                {
                    benchmark.benchmark2("Ending full compile for " + getOutput(), true);
                }
    
                clean(returnValue == FAIL /* cleanData */,
                      false /* cleanCache */,
                      false /* cleanOutput */,
                      true /* cleanConfig */,
                      false /* cleanMessages */,
                      false /* cleanThreadLocals */);
                return returnValue;
            }
    
            if (benchmark != null)
            {
                // We aren't really starting the compile here, but it's
                // the earliest that we know that it's going to be an
                // active compilation.
                benchmark.benchmark2("Starting active compile for " + getOutput(), true);
            }

            boolean relink = false;

            if (applicationCache != null)
            {
                ContextStatics contextStatics = applicationCache.getContextStatics();
                data.perCompileData = contextStatics;

                if (applicationCache.isConsistent(tempOEMConfiguration.configuration))
                {
                    relink = (loadCachedSources(data.resources.sources()) ||
                              loadCachedSources(data.sourceList.sources()) ||
                              loadCachedSources(data.sourcePath.sources()));
                }
                else
                {
                    applicationCache.clear();
                }
            }

            // Clear out ASC's userDefined, so definitions from a
            // previous compilation don't spill over into this one.
            data.perCompileData.userDefined.clear();
    
            data.sourcePath.clearCache();
            data.bundlePath.clearCache();
            data.resources.refresh();
    
            // validate CompilationUnits
            final int count = CompilerAPI.validateCompilationUnits(data.fileSpec, data.sourceList, data.sourcePath, data.bundlePath,
                                                                   data.resources, swcContext, data.perCompileData, tempOEMConfiguration.configuration);
    
            if ((count > 0) || (data.swcChecksum != swcContext.checksum()))
            {
                data.configuration = tempOEMConfiguration.configuration;
                data.linkChecksum = tempOEMConfiguration.cfgbuf.link_checksum_ts();
                data.swcChecksum = swcContext.checksum();
    
                // create a symbol table
                SymbolTable symbolTable = new SymbolTable(tempOEMConfiguration.configuration, data.perCompileData);
    
                data.sources = new ArrayList<Source>();
                data.units = compile(compilers, swcContext, symbolTable, mappings, licenseMap, data.sources);
    
                boolean forcedToStop = CompilerAPI.forcedToStop();
                if (data.units == null || forcedToStop)
                {
                    data.sources = null;
                }

                if (benchmark != null)
                {
                    benchmark.benchmark2("Ending active compile for " + getOutput(), true);
                }
    
                clean(false /* cleanData */,
                      false /* cleanCache */,
                      false /* cleanOutput */,
                      true /* cleanConfig */,
                      false /* cleanMessages */,
                      false /* cleanThreadLocals */);
    
                return (data.units != null && !forcedToStop) ? OK : FAIL;
            }
            else
            {
                if (benchmark != null)
                {
                    benchmark.stopTime(Benchmark.PRECOMPILE, false);
                    benchmark.startTime(Benchmark.POSTCOMPILE);
                }
    
                int retVal = SKIP;
                if (data != null)
                {
                    CompilerAPI.displayWarnings(data.units);
                    if ((data.linkChecksum != tempOEMConfiguration.cfgbuf.link_checksum_ts()) || relink)
                    {
                        retVal = LINK;
                    }
                }
                else
                {
                    retVal = LINK;
                }

                data.linkChecksum = tempOEMConfiguration.cfgbuf.link_checksum_ts();
                data.swcChecksum = swcContext.checksum();
    
                if (benchmark != null)
                {
                    benchmark.benchmark2("Ending active compile for " + getOutput(), true);
                }
    
                if (CompilerAPI.forcedToStop()) retVal = FAIL;
                if (retVal != LINK)
                {
                    clean(false /* cleanData */,
                          false /* cleanCache */,
                          false /* cleanOutput */,
                          true /* cleanConfig */,
                          false /* cleanMessages */,
                          false /* cleanThreadLocals */);
                }
    
                return retVal;
            }
        }
        finally
        {
            // clean thread locals
            OEMUtil.clean();
        }
    }