private void AddLibraries() { MxmlcOptions options = project.CompilerOptions; string absPath; if (options.IncludeLibraries.Length > 0) { WriteStartElement("include-libraries"); foreach (string path in options.IncludeLibraries) { absPath = project.GetAbsolutePath(path); if (File.Exists(absPath)) { WriteElementPathString("library", absPath); } else if (Directory.Exists(absPath)) { string[] libs = Directory.GetFiles(absPath, "*.swc"); foreach (string lib in libs) { WriteElementPathString("library", lib); } } } WriteEndElement(); } if (options.ExternalLibraryPaths.Length > 0) { WriteStartElement("external-library-path"); WriteAttributeString("append", "true"); foreach (string path in options.ExternalLibraryPaths) { absPath = project.GetAbsolutePath(path); if (File.Exists(absPath) || Directory.Exists(absPath)) { WriteElementPathString("path-element", absPath); } } WriteEndElement(); } if (options.LibraryPaths.Length > 0) { WriteStartElement("library-path"); WriteAttributeString("append", "true"); foreach (string path in options.LibraryPaths) { absPath = project.GetAbsolutePath(path); if (File.Exists(absPath) || Directory.Exists(absPath)) { WriteElementPathString("path-element", absPath); } } WriteEndElement(); } }
protected override void DoBuild(string[] extraClasspaths, bool noTrace) { string tempFile = null; Environment.CurrentDirectory = project.Directory; try { string objDir = "obj"; if (!Directory.Exists(objDir)) { Directory.CreateDirectory(objDir); } tempFile = GetTempProjectFile(project); //create new config file double sdkVersion = ParseVersion(FDBuild.Program.BuildOptions.CompilerVersion ?? "4.0"); // create compiler configuration file string projectName = project.Name.Replace(" ", ""); string backupConfig = Path.Combine(objDir, projectName + "Config.old"); string configFileTmp = Path.Combine(objDir, projectName + "Config.tmp"); string configFile = Path.Combine(objDir, projectName + "Config.xml"); // backup the old Config.xml to Config.old so we can reference it if (File.Exists(configFile)) { File.Copy(configFile, backupConfig, true); } //write "new" config to tmp FlexConfigWriter config = new FlexConfigWriter(project.GetAbsolutePath(configFileTmp)); config.WriteConfig(project, sdkVersion, extraClasspaths, noTrace == false, asc2Mode); //compare tmp to current bool configChanged = !File.Exists(backupConfig) || !File.Exists(configFile) || !FileComparer.IsEqual(configFileTmp, configFile); //copy temp file to config if there is a change if (configChanged) { File.Copy(configFileTmp, configFile, true); } //remove temp File.Delete(configFileTmp); MxmlcArgumentBuilder mxmlc = new MxmlcArgumentBuilder(project, sdkVersion, asc2Mode); mxmlc.AddConfig(configFile); mxmlc.AddOptions(noTrace, fcsh != null); mxmlc.AddOutput(tempFile); string mxmlcArgs = mxmlc.ToString(); if (asc2Mode) { mxmlcArgs = AddBaseConfig(mxmlcArgs); Console.WriteLine("mxmlc-cli " + mxmlcArgs); } else { Console.WriteLine("mxmlc " + mxmlcArgs); } CompileWithMxmlc(project.Directory, mxmlcArgs, configChanged); // if we get here, the build was successful string output = project.FixDebugReleasePath(project.OutputPathAbsolute); string outputDir = Path.GetDirectoryName(output); if (!Directory.Exists(outputDir)) { Directory.CreateDirectory(outputDir); } File.Copy(tempFile, output, true); } finally { if (tempFile != null && File.Exists(tempFile)) { File.Delete(tempFile); } } }
/// <summary> /// Exports FD project setting to COLTRemoteProject instance. /// </summary> /// <returns></returns> private COLTRemoteProject ExportCOLTProject() { // our options: parse project.ProjectPath (xml file) or use api AS3Project project = (AS3Project)PluginBase.CurrentProject; String configCopy = ""; if (settingObject.FullConfig) { // Construct flex config file name (see AS3ProjectBuilder, line 140) String projectName = project.Name.Replace(" ", ""); String configFile = Path.Combine("obj", projectName + "Config.xml"); if (!File.Exists(project.GetAbsolutePath(configFile))) { TraceManager.Add("Required file (" + projectName + "Config.xml) does not exist, project must be built first...", -1); try { allowBuildInterception = false; EventManager.DispatchEvent(this, new DataEvent(EventType.Command, "ProjectManager.BuildProject", null)); } finally { allowBuildInterception = true; } return(null); } // Create config copy with <file-specs>...</file-specs> commented out configCopy = Path.Combine("obj", projectName + "ConfigCopy.xml"); File.WriteAllText(project.GetAbsolutePath(configCopy), File.ReadAllText(project.GetAbsolutePath(configFile)) .Replace("<file-specs", "<!-- file-specs") .Replace("/file-specs>", "/file-specs -->")); } // Export COLT project COLTRemoteProject result = new COLTRemoteProject(); result.path = project.GetAbsolutePath(Path.Combine(settingObject.WorkingFolder, System.Guid.NewGuid() + ".colt")); result.name = project.Name; List <String> libraryPathsList = new List <String>(project.CompilerOptions.LibraryPaths); for (int i = 0; i < libraryPathsList.Count; i++) { if (libraryPathsList[i].ToLower().EndsWith(".swc")) { libraryPathsList[i] = @"..\" + libraryPathsList[i]; } else { // workaround (FD saves empty paths for missing libs) libraryPathsList.RemoveAt(i); i--; } } result.libraries = libraryPathsList.ToArray(); result.targetPlayerVersion = project.MovieOptions.Version + ".0"; result.mainClass = project.GetAbsolutePath(project.CompileTargets[0]); result.flexSDKPath = project.CurrentSDK; if (settingObject.FullConfig) { result.customConfigPath = project.GetAbsolutePath(configCopy); } String outputPath = project.OutputPath; int lastSlash = outputPath.LastIndexOf(@"\"); if (lastSlash > -1) { result.outputPath = project.GetAbsolutePath(outputPath.Substring(0, lastSlash)); result.outputFileName = outputPath.Substring(lastSlash + 1); } else { result.outputPath = project.GetAbsolutePath(""); result.outputFileName = outputPath; } String[] sourcePaths = project.SourcePaths.Clone() as String[]; for (int i = 0; i < sourcePaths.Length; i++) { sourcePaths[i] = @"..\" + sourcePaths[i]; } result.sources = sourcePaths; result.assets = AssetFolders; for (int i = 0; i < result.assets.Length; i++) { result.assets[i] = @"..\" + project.GetRelativePath(result.assets[i]); } // size, frame rate and background color String[] coltAdditionalOptionsKeys = { "-default-size", "-default-frame-rate", "-default-background-color" }; String[] coltAdditionalOptions = { coltAdditionalOptionsKeys[0] + " " + project.MovieOptions.Width + " " + project.MovieOptions.Height, coltAdditionalOptionsKeys[1] + " " + project.MovieOptions.Fps, coltAdditionalOptionsKeys[2] + " " + project.MovieOptions.BackgroundColorInt }; String additionalOptions = ""; foreach (String option in project.CompilerOptions.Additional) { for (int i = 0; i < coltAdditionalOptionsKeys.Length; i++) { if (option.Contains(coltAdditionalOptionsKeys[i])) { coltAdditionalOptions[i] = ""; } } additionalOptions += option + " "; } foreach (String option in coltAdditionalOptions) { additionalOptions += option + " "; } // compiler constants // see AddCompilerConstants in FDBuild's Building.AS3.FlexConfigWriter Boolean debugMode = project.TraceEnabled; Boolean isMobile = (project.MovieOptions.Platform == AS3MovieOptions.AIR_MOBILE_PLATFORM); Boolean isDesktop = (project.MovieOptions.Platform == AS3MovieOptions.AIR_PLATFORM); additionalOptions += "-define+=CONFIG::debug," + (debugMode ? "true" : "false") + " "; additionalOptions += "-define+=CONFIG::release," + (debugMode ? "false" : "true") + " "; additionalOptions += "-define+=CONFIG::timeStamp,\"'" + DateTime.Now.ToString("d") + "'\" "; additionalOptions += "-define+=CONFIG::air," + (isMobile || isDesktop ? "true" : "false") + " "; additionalOptions += "-define+=CONFIG::mobile," + (isMobile ? "true" : "false") + " "; additionalOptions += "-define+=CONFIG::desktop," + (isDesktop ? "true" : "false") + " "; if (project.CompilerOptions.CompilerConstants != null) { foreach (string define in project.CompilerOptions.CompilerConstants) { if (define.IndexOf(',') >= 0) { additionalOptions += "-define+=" + define + " "; } } } result.compilerOptions = additionalOptions.Trim() + (debugMode ? " -debug" : ""); return(result); }