From 6e6c2ab01f26d3552189cceb53125a4288102a3c Mon Sep 17 00:00:00 2001 From: Daniel Jeong Date: Mon, 3 Apr 2017 02:44:41 +0900 Subject: [PATCH] Match higher target player version to sdk version If the specified target player version is higher than the current SDK version, lower the target player version to match the current SDK version. Update some code to the new C# 7.0 syntax. Set the default target player version to 99.0 to target the highest available version. --- .../Project.as3proj | 2 +- .../Project.txt | 2 +- SwcBuild/Program.cs | 50 +- SwcBuild/Properties/AssemblyInfo.cs | 6 +- SwcBuild/SwcBuild.csproj | 2 +- SwcBuild/src/ActionScriptCompiler.cs | 272 ++-- SwcBuild/src/AsdocCreator.cs | 128 +- SwcBuild/src/BuildOptions.cs | 392 +++--- SwcBuild/src/CompilerArguments.cs | 112 +- SwcBuild/src/CompilerProcess.cs | 148 +- SwcBuild/src/ConfigWriter.cs | 518 +++---- SwcBuild/src/Constants.cs | 166 +-- SwcBuild/src/ExitCodes.cs | 34 +- SwcBuild/src/Helper.cs | 322 ++--- SwcBuild/src/SwcBuild.cs | 1215 +++++++++-------- SwcBuild/src/Utilities.cs | 295 ++-- 16 files changed, 1825 insertions(+), 1839 deletions(-) diff --git a/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.as3proj b/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.as3proj index f7f7c38..2ceb27f 100644 --- a/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.as3proj +++ b/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.as3proj @@ -8,7 +8,7 @@ - + diff --git a/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.txt b/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.txt index 228f2fe..236c120 100644 --- a/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.txt +++ b/External/Raw/Projects/132 ActionScript 3 - AS3 Library Project/Project.txt @@ -1 +1 @@ -An ActionScript 3 library project to compile as a SWC file \ No newline at end of file +An ActionScript 3 library project to compile as a SWC file (SWCBuild) \ No newline at end of file diff --git a/SwcBuild/Program.cs b/SwcBuild/Program.cs index 9f8b0c3..2024147 100644 --- a/SwcBuild/Program.cs +++ b/SwcBuild/Program.cs @@ -3,36 +3,36 @@ namespace SwcBuild { - using static Attribute; - using static Console; + using static Attribute; + using static Console; internal static class Program - { + { private static int Main(string[] args) - { - using (var swcBuild = new SwcBuild()) - { - int exitCode = (int) swcBuild.Run(args); - WriteLine($"{Assembly.Description} exited with code: {exitCode}"); + { + using (var swcBuild = new SwcBuild()) + { + int exitCode = (int) swcBuild.Run(args); + WriteLine($"{Assembly.Description} exited with code: {exitCode}"); - return exitCode; - } - } + return exitCode; + } + } - internal static class Assembly - { - private static readonly System.Reflection.Assembly assembly = typeof(Program).Assembly; + internal static class Assembly + { + private static readonly System.Reflection.Assembly assembly = typeof(Program).Assembly; - public static string Title { get; } = Get().Title; - public static string Description { get; } = Get().Description; - public static string Configuration { get; } = Get().Configuration; - public static string Company { get; } = Get().Company; - public static string Product { get; } = Get().Product; - public static string Copyright { get; } = Get().Copyright; - public static string Trademark { get; } = Get().Trademark; - public static Version Version { get; } = assembly.GetName().Version; + public static string Title { get; } = Get().Title; + public static string Description { get; } = Get().Description; + public static string Configuration { get; } = Get().Configuration; + public static string Company { get; } = Get().Company; + public static string Product { get; } = Get().Product; + public static string Copyright { get; } = Get().Copyright; + public static string Trademark { get; } = Get().Trademark; + public static Version Version { get; } = assembly.GetName().Version; - private static T Get() where T : class => GetCustomAttribute(assembly, typeof(T)) as T; - } - } + private static T Get() where T : class => GetCustomAttribute(assembly, typeof(T)) as T; + } + } } diff --git a/SwcBuild/Properties/AssemblyInfo.cs b/SwcBuild/Properties/AssemblyInfo.cs index 748a09d..3e246f4 100644 --- a/SwcBuild/Properties/AssemblyInfo.cs +++ b/SwcBuild/Properties/AssemblyInfo.cs @@ -9,7 +9,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Daniel Jeong")] [assembly: AssemblyProduct("swcbuild.exe")] -[assembly: AssemblyCopyright("Copyright © Daniel Jeong 2016")] +[assembly: AssemblyCopyright("Copyright © Daniel Jeong 2017")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.*")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.1.*")] +[assembly: AssemblyFileVersion("1.5.1.0")] diff --git a/SwcBuild/SwcBuild.csproj b/SwcBuild/SwcBuild.csproj index 8c0160e..1cde2cc 100644 --- a/SwcBuild/SwcBuild.csproj +++ b/SwcBuild/SwcBuild.csproj @@ -53,7 +53,7 @@ Auto false false - 6 + default false diff --git a/SwcBuild/src/ActionScriptCompiler.cs b/SwcBuild/src/ActionScriptCompiler.cs index 4043da8..942990f 100644 --- a/SwcBuild/src/ActionScriptCompiler.cs +++ b/SwcBuild/src/ActionScriptCompiler.cs @@ -3,154 +3,154 @@ namespace SwcBuild { - using static Platform; - using static Utilities; + using static Platform; + using static Utilities; internal class ActionScriptCompiler : CompilerProcess - { - public static ActionScriptCompiler ASC1 => new ActionScriptCompiler(ASCVersions.ASC1); + { + public static ActionScriptCompiler ASC1 => new ActionScriptCompiler(ASCVersions.ASC1); - public static ActionScriptCompiler ASC2 => new ActionScriptCompiler(ASCVersions.ASC2); + public static ActionScriptCompiler ASC2 => new ActionScriptCompiler(ASCVersions.ASC2); private ActionScriptCompiler(ASCVersions v) : base(true, true) - { - Version = v; - } + { + Version = v; + } - public Version SdkVersion { get; set; } + public Version SdkVersion { get; set; } - public Version TargetPlayer { get; set; } + public Version TargetPlayer { get; set; } - public ASCVersions Version { get; } + public ASCVersions Version { get; } - public bool BuildArguments(BuildOptions options, bool debug, bool incremental, out ExitCodes exitCode) - { - if (string.IsNullOrEmpty(options.Path)) - return ErrorHelper.InvalidPathToOutput(out exitCode); - - Output = FixOutputPath(options.Path, debug); - - string configname = GetConfigname(options.Platform); - //string defaultConfig = Path.Combine(CompilerDirectory, "frameworks", $"{configname}-config.xml"); - - string[] additional = ParseArguments(options.Additional); - bool isConfignameDefined = false; - bool isSwfVersionDefined = false; - - foreach (string argument in additional) - { - if (!isConfignameDefined && argument.Length > 12 && argument.Substring(0, 12) == "+configname=") - { - isConfignameDefined = true; - if (isSwfVersionDefined) break; - continue; - } - if (!isSwfVersionDefined && argument.Length > 13 && argument.Substring(0, 13) == "-swf-version=") - { - isSwfVersionDefined = true; - if (isConfignameDefined) break; - } - } - - if (!isConfignameDefined && configname != "flex") - Arguments.Configname = configname; - - //if (File.Exists(defaultConfig)) - // Arguments.LoadConfig = Q(defaultConfig); - - if (File.Exists(options.LoadConfig)) - Arguments.LoadConfig = Q(options.LoadConfig); - - Arguments.LoadConfig = Q(ConfigFile); - - if (debug) - Arguments.Debug = true; - - switch (Version) - { - case ASCVersions.ASC1: - if (incremental) - Arguments.Incremental = true; - break; - - case ASCVersions.ASC2: - if (options.AdvancedTelemetry) - { - Arguments.AdvancedTelemetry = true; - - if (!string.IsNullOrEmpty(options.AdvancedTelemetryPassword)) - Arguments.AdvancedTelemetryPassword = Q(options.AdvancedTelemetryPassword); - } - - if (options.Inline) - Arguments.Inline = true; - break; - } - - if (!string.IsNullOrEmpty(options.LinkReport)) - Arguments.LinkReport = options.LinkReport; - - if (!string.IsNullOrEmpty(options.LoadExterns)) - Arguments.LoadExterns = options.LoadExterns; - - if (!isSwfVersionDefined) - { - int swfVersion = ResolveSwfVersion(TargetPlayer, options.Platform != FlashPlayer); - - if (swfVersion != -1) - Arguments.SwfVersion = swfVersion; - } - - if (options.Classpaths != null) - foreach (string classpath in options.Classpaths) - Arguments.Sources = Q(classpath); - - foreach (string arg in additional) - Arguments.Additionals = arg; - - Arguments.Output = Q(Output); - - exitCode = 0; - return false; - } - - public bool Run(out ExitCodes exitCode) - { - try - { - Run(Arguments.CompcArgs); - - exitCode = ExitCode == 0 ? 0 : ExitCodes.ErrorRunningCompiler; - return false; - } - catch (Exception e) - { - return ErrorHelper.ErrorRunningCompiler(out exitCode, e); - } - } - - public string GetAsDocPath() - { + public bool BuildArguments(BuildOptions options, bool debug, bool incremental, out ExitCodes exitCode) + { + if (string.IsNullOrEmpty(options.Path)) + return ErrorHelper.InvalidPathToOutput(out exitCode); + + Output = FixOutputPath(options.Path, debug); + + string configname = GetConfigname(options.Platform); + //string defaultConfig = Path.Combine(CompilerDirectory, "frameworks", $"{configname}-config.xml"); + + string[] additional = ParseArguments(options.Additional); + bool isConfignameDefined = false; + bool isSwfVersionDefined = false; + + foreach (string argument in additional) + { + if (!isConfignameDefined && argument.Length > 12 && argument.Substring(0, 12) == "+configname=") + { + isConfignameDefined = true; + if (isSwfVersionDefined) break; + continue; + } + if (!isSwfVersionDefined && argument.Length > 13 && argument.Substring(0, 13) == "-swf-version=") + { + isSwfVersionDefined = true; + if (isConfignameDefined) break; + } + } + + if (!isConfignameDefined && configname != "flex") + Arguments.Configname = configname; + + //if (File.Exists(defaultConfig)) + // Arguments.LoadConfig = Q(defaultConfig); + + if (File.Exists(options.LoadConfig)) + Arguments.LoadConfig = Q(options.LoadConfig); + + Arguments.LoadConfig = Q(ConfigFile); + + if (debug) + Arguments.Debug = true; + + switch (Version) + { + case ASCVersions.ASC1: + if (incremental) + Arguments.Incremental = true; + break; + + case ASCVersions.ASC2: + if (options.AdvancedTelemetry) + { + Arguments.AdvancedTelemetry = true; + + if (!string.IsNullOrEmpty(options.AdvancedTelemetryPassword)) + Arguments.AdvancedTelemetryPassword = Q(options.AdvancedTelemetryPassword); + } + + if (options.Inline) + Arguments.Inline = true; + break; + } + + if (!string.IsNullOrEmpty(options.LinkReport)) + Arguments.LinkReport = options.LinkReport; + + if (!string.IsNullOrEmpty(options.LoadExterns)) + Arguments.LoadExterns = options.LoadExterns; + + if (!isSwfVersionDefined) + { + int swfVersion = ResolveSwfVersion(TargetPlayer, options.Platform != FlashPlayer); + + if (swfVersion != -1) + Arguments.SwfVersion = swfVersion; + } + + if (options.Classpaths != null) + foreach (string classpath in options.Classpaths) + Arguments.Sources = Q(classpath); + + foreach (string arg in additional) + Arguments.Additionals = arg; + + Arguments.Output = Q(Output); + + exitCode = 0; + return false; + } + + public bool Run(out ExitCodes exitCode) + { + try + { + Run(Arguments.CompcArgs); + + exitCode = ExitCode == 0 ? 0 : ExitCodes.ErrorRunningCompiler; + return false; + } + catch (Exception e) + { + return ErrorHelper.ErrorRunningCompiler(out exitCode, e); + } + } + + public string GetAsDocPath() + { string path = Path.Combine(Path.GetDirectoryName(CompilerPath), String.AsDoc); - switch (Version) - { - case ASCVersions.ASC1: - return $"{path}{String.Exe}"; - case ASCVersions.ASC2: - return $"{path}{String.Bat}"; - default: - return null; - } - } + switch (Version) + { + case ASCVersions.ASC1: + return $"{path}{String.Exe}"; + case ASCVersions.ASC2: + return $"{path}{String.Bat}"; + default: + return null; + } + } - private static string Q(string text) => WrapWithQuotes(text); - } + private static string Q(string text) => WrapWithQuotes(text); + } internal enum ASCVersions - { - None, - ASC1, - ASC2, - } + { + None, + ASC1, + ASC2, + } } diff --git a/SwcBuild/src/AsdocCreator.cs b/SwcBuild/src/AsdocCreator.cs index 1b0b716..2a0dea8 100644 --- a/SwcBuild/src/AsdocCreator.cs +++ b/SwcBuild/src/AsdocCreator.cs @@ -5,83 +5,83 @@ namespace SwcBuild { - using static ExitCodes; - using static FileMode; - using static ZipArchiveMode; + using static ExitCodes; + using static FileMode; + using static ZipArchiveMode; internal class AsDocCreator : CompilerProcess - { - public AsDocCreator() : base(true, false) { } + { + public AsDocCreator() : base(true, false) { } - public string[] Exclude { get; set; } + public string[] Exclude { get; set; } - public void BuildArguments() - { - if (File.Exists(ConfigFile)) - Arguments.LoadConfig = ConfigFile; + public void BuildArguments() + { + if (File.Exists(ConfigFile)) + Arguments.LoadConfig = ConfigFile; - Arguments.Lenient = true; - Arguments.KeepXml = true; - Arguments.SkipXsl = true; - } + Arguments.Lenient = true; + Arguments.KeepXml = true; + Arguments.SkipXsl = true; + } - public bool Run(out ExitCodes exitCode) - { - try - { - Run($"{Arguments.AsdocArgs}-output={Output}"); + public bool Run(out ExitCodes exitCode) + { + try + { + Run($"{Arguments.AsdocArgs}-output={Output}"); - if (ExitCode == 0) - { - exitCode = 0; - return false; - } + if (ExitCode == 0) + { + exitCode = 0; + return false; + } - exitCode = ErrorRunningAsDoc; - return true; - } - catch (Exception e) - { - return ErrorHelper.ErrorRunningAsDoc(out exitCode, e); - } - } + exitCode = ErrorRunningAsDoc; + return true; + } + catch (Exception e) + { + return ErrorHelper.ErrorRunningAsDoc(out exitCode, e); + } + } - public bool AddToSwc(string target, bool keepXml, out ExitCodes exitCode) - { - try - { - using (var swcFile = new FileStream(target, Open)) - using (var archive = new ZipArchive(swcFile, Update)) - { - string directory = Path.Combine(Output, "tempdita"); + public bool AddToSwc(string target, bool keepXml, out ExitCodes exitCode) + { + try + { + using (var swcFile = new FileStream(target, Open)) + using (var archive = new ZipArchive(swcFile, Update)) + { + string directory = Path.Combine(Output, "tempdita"); - foreach (string file in Directory.GetFiles(directory)) - { - string filename = Path.GetFileName(file); + foreach (string file in Directory.GetFiles(directory)) + { + string filename = Path.GetFileName(file); - if (filename == null || Exclude.Contains(filename)) - continue; + if (filename == null || Exclude.Contains(filename)) + continue; - string destination = Path.Combine("docs", filename); + string destination = Path.Combine("docs", filename); - using (var original = File.OpenRead(file)) - using (var compressed = archive.CreateEntry(destination).Open()) - { - original.CopyTo(compressed); - } - } - } + using (var original = File.OpenRead(file)) + using (var compressed = archive.CreateEntry(destination).Open()) + { + original.CopyTo(compressed); + } + } + } - if (!keepXml) - Directory.Delete(Output, true); + if (!keepXml) + Directory.Delete(Output, true); - exitCode = 0; - return false; - } - catch (Exception e) - { - return ErrorHelper.ErrorRunningAsDoc(out exitCode, e); - } - } - } + exitCode = 0; + return false; + } + catch (Exception e) + { + return ErrorHelper.ErrorRunningAsDoc(out exitCode, e); + } + } + } } diff --git a/SwcBuild/src/BuildOptions.cs b/SwcBuild/src/BuildOptions.cs index 308f4f1..8a1edf2 100644 --- a/SwcBuild/src/BuildOptions.cs +++ b/SwcBuild/src/BuildOptions.cs @@ -3,226 +3,226 @@ namespace SwcBuild { - using A = BuildOptionAttributes; - using E = BuildOptionElements; - using G = BuildOptionGroups; - using list = XmlNodeList; - using xml = XmlElement; + using A = BuildOptionAttributes; + using E = BuildOptionElements; + using G = BuildOptionGroups; + using list = XmlNodeList; + using xml = XmlElement; internal class BuildOptions - { - public string OutputType = null; - public string Input = null; - public string Path = null; - public string Fps = null; - public string Width = null; - public string Height = null; - public string Version = null; - public string MinorVersion = null; - public string Platform = null; - public string Background = null; - - public bool Accessible = false; - public bool AdvancedTelemetry = false; - public bool AllowSourcePathOverlap = false; - public bool Benchmark = false; - public bool Es = false; - public bool Inline = false; - public bool Optimize = false; - public bool OmitTraces = false; - public bool ShowActionScriptWarnings = true; - public bool ShowBindingWarnings = true; - public bool ShowDeprecationWarnings = true; - public bool ShowInvalidCss = true; - public bool ShowUnusedTypeSelectorWarnings = true; - public bool StaticLinkRSL = false; - public bool Strict = true; - public bool UseNetwork = true; - public bool UseResourceBundleMetadata = true; - public bool VerboseStackTraces = false; - public bool Warnings = true; - - public string AdvancedTelemetryPassword = null; - public string Locale = null; - public string LoadConfig = null; - public string LinkReport = null; - public string LoadExterns = null; - public string Additional = null; - public string MinorVersion2 = null; - public string CompilerConstants = null; - - public string[] Classpaths = null; - public string[] ExternalLibraryPaths = null; - public string[] IncludeLibraries = null; - public string[] LibraryPaths = null; - public string[] RslPaths = null; - - public BuildOptions() { } - - public bool Parse(xml data, out ExitCodes exitCode) - { - try - { - // - var group = data[G.Output]; - var elements = group?.GetElementsByTagName(E.Movie); - ParseOutputOptions(elements); - - //