{
CompilerAPI.disableBenchmark();
}
// make sure targetFile abstract pathname is an absolute path...
VirtualFile targetFile = CompilerAPI.getVirtualFile(configuration.getTargetFile());
WebTierAPI.checkSupportedTargetMimeType(targetFile);
// mxmlc only wants to take one file.
List<String> fileList = configuration.getFileList();
if (fileList == null || fileList.size() != 1)
{
throw new ConfigurationException.OnlyOneSource( "filespec", null, -1);
}
List<VirtualFile> virtualFileList = CompilerAPI.getVirtualFileList(fileList);
CompilerConfiguration compilerConfig = configuration.getCompilerConfiguration();
NameMappings mappings = CompilerAPI.getNameMappings(configuration);
// create a FileSpec... can reuse based on targetFile, debug settings, etc...
FileSpec fileSpec = new FileSpec(Collections.<VirtualFile>emptyList(), WebTierAPI.getFileSpecMimeTypes());
// create a SourcePath...
VirtualFile[] asClasspath = compilerConfig.getSourcePath();
SourceList sourceList = new SourceList(virtualFileList,
asClasspath,
targetFile,
WebTierAPI.getSourcePathMimeTypes());
SourcePath sourcePath = new SourcePath(asClasspath,
targetFile,
WebTierAPI.getSourcePathMimeTypes(),
compilerConfig.allowSourcePathOverlap());
ResourceContainer resources = new ResourceContainer();
ResourceBundlePath bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), targetFile);
ArrayList<Source> sources = new ArrayList<Source>();
List<CompilationUnit> units = new ArrayList<CompilationUnit>();
if (benchmark != null)
{
benchmark.benchmark(l10n.getLocalizedTextString(new InitialSetup()));
}
// load SWCs
CompilerSwcContext swcContext = new CompilerSwcContext();
SwcCache cache = new SwcCache();
// lazy read should only be set by mxmlc/compc
cache.setLazyRead(true);
swcContext.load( compilerConfig.getLibraryPath(),
Configuration.getAllExcludedLibraries(compilerConfig, configuration),
compilerConfig.getThemeFiles(),
compilerConfig.getIncludeLibraries(),
mappings,
I18nUtils.getTranslationFormat(compilerConfig),
cache );
configuration.addExterns( swcContext.getExterns() );
configuration.addIncludes( swcContext.getIncludes() );
configuration.getCompilerConfiguration().addThemeCssFiles( swcContext.getThemeStyleSheets() );
// Figure out the name of the output file.
File outputFile = getOutputFile(configuration, targetFile);
// Checksums to figure out if incremental compile can be done.
String incrementalFileName = null;
SwcChecksums swcChecksums = null;
// Should we attempt to build incrementally using the incremental file?
boolean recompile = true;
// If incremental compilation is enabled and the output file exists,
// use the persisted store to figure out if a compile/link is necessary.
// link without a compile is not supported without changes to the
// persistantStore since units for Sources of type isSwcScriptOwner()
// aren't stored/restored properly. units contains null entries for those
// type of Source. To force a rebuild, with -incremental specified, delete the
// incremental file.
if (configuration.getCompilerConfiguration().getIncremental())
{
swcChecksums = new SwcChecksums(swcContext, cfgbuf, configuration);
// If incremental compilation is enabled, read the cached
// compilation units... Do not include the checksum in the file name so that
// cache files don't pile up as the configuration changes. There needs
// to be a 1-to-1 mapping between the swc file and the cache file.
incrementalFileName = outputFile.getPath() + ".cache";
// If the output file doesn't exist don't bother loading the
// cache since a recompile is needed.
if (outputFile.exists())
{
RandomAccessFile incrementalFile = null;
try
{
incrementalFile = new RandomAccessFile(incrementalFileName, "r");
// For loadCompilationUnits, loadedChecksums[1] must match
// the cached value else IOException is thrown.
int[] loadedChecksums = swcChecksums.copy();
CompilerAPI.loadCompilationUnits(configuration, fileSpec, sourceList, sourcePath, resources, bundlePath, null, /* sources */
null, /*units */
loadedChecksums, swcChecksums.getSwcDefSignatureChecksums(), swcChecksums.getSwcFileChecksums(), null, /* archiveFiles */
incrementalFile, incrementalFileName, null /* font manager */);
if (!(swcChecksums.isRecompilationNeeded(loadedChecksums) && !swcChecksums.isRelinkNeeded(loadedChecksums)))
{
recompile = false;
}
}
catch (FileNotFoundException ex)
{
// the incremental file doesn't exist
ThreadLocalToolkit.logDebug(ex.getLocalizedMessage());
}
catch (IOException ex)
{
// error loading the incremental file - most likely checksum
// mismatch or format mismatch
ThreadLocalToolkit.logInfo(ex.getLocalizedMessage());
}
finally
{
if (incrementalFile != null)
{
try
{
incrementalFile.close();
}
catch (IOException ex)
{
}
// If the load failed, or recompilation is needed, reset
// all the variables to their original state.
if (recompile)
{
fileSpec = new FileSpec(Collections.<VirtualFile>emptyList(), WebTierAPI.getFileSpecMimeTypes());
sourceList = new SourceList(virtualFileList,
asClasspath,
targetFile,
WebTierAPI.getSourcePathMimeTypes());
sourcePath = new SourcePath(asClasspath,
targetFile,
WebTierAPI.getSourcePathMimeTypes(),
compilerConfig.allowSourcePathOverlap());
resources = new ResourceContainer();
bundlePath = new ResourceBundlePath(configuration.getCompilerConfiguration(), targetFile);
}
}
}
}
}
VirtualFile projector = configuration.getProjector();
boolean createProjector = (projector != null && projector.getName().endsWith("avmplus.exe"));
// Validate CompilationUnits in FileSpec and SourcePath. If
// count > 0 something changed.
int count = CompilerAPI.validateCompilationUnits(
fileSpec, sourceList, sourcePath, bundlePath, resources,