From 3488e349727decc7448213790139ce33a01d44f0 Mon Sep 17 00:00:00 2001 From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498> Date: Fri, 15 Jun 2012 01:54:58 +0000 Subject: [PATCH] X# to builder. --- .../Build/Cosmos.Build.Builder/CosmosTask.cs | 32 +++++++++++++--- .../Cosmos.Build.Builder/MainWindow.xaml | 5 ++- .../Cosmos.Build.Builder/MainWindow.xaml.cs | 17 +++++++-- source2/Build/Cosmos.Build.Installer/Task.cs | 2 + .../Cosmos.Compiler.XSharp.XSC/Program.cs | 18 ++++----- source2/Compiler/Cosmos.XSharp/Generator.cs | 23 ++++++++---- .../Tests/XSharpCompilerTester/MainForm.cs | 4 +- .../VSIP/Cosmos.VS.XSharp/FileGenerator.cs | 4 +- source2/XSharp.sln | 37 +++++++++++++------ 9 files changed, 97 insertions(+), 45 deletions(-) diff --git a/source2/Build/Cosmos.Build.Builder/CosmosTask.cs b/source2/Build/Cosmos.Build.Builder/CosmosTask.cs index 1857f01fa..43cc05cd3 100644 --- a/source2/Build/Cosmos.Build.Builder/CosmosTask.cs +++ b/source2/Build/Cosmos.Build.Builder/CosmosTask.cs @@ -9,22 +9,42 @@ namespace Cosmos.Build.Builder { public class CosmosTask : Task { protected string mCosmosPath; public bool ResetHive { get; set; } + protected string mOutputPath; public CosmosTask(string aCosmosPath) { mCosmosPath = aCosmosPath; } - protected override void DoRun() { - string xOutputPath = mCosmosPath + @"\Build\VSIP"; + protected void MsBuild(string aSlnFile, string aBuildCfg) { + StartConsole(Paths.Windows + @"\Microsoft.NET\Framework\v4.0.30319\msbuild.exe", Quoted(aSlnFile) + @" /maxcpucount /verbosity:normal /nologo /p:Configuration=" + aBuildCfg + " /p:Platform=x86 /p:OutputPath=" + Quoted(mOutputPath)); + } - if (!Directory.Exists(xOutputPath)) { - Directory.CreateDirectory(xOutputPath); + protected override void DoRun() { + mOutputPath = mCosmosPath + @"\Build\VSIP"; + if (!Directory.Exists(mOutputPath)) { + Directory.CreateDirectory(mOutputPath); + } + + Section("Compiling X# Compiler"); + MsBuild(mCosmosPath + @"\source2\XSharp.sln", "Debug"); + + Section("Compiling X# Sources"); + var xFiles = Directory.GetFiles(mCosmosPath + @"\source2\Compiler\Cosmos.Compiler.DebugStub\", "*.xs"); + foreach (var xFile in xFiles) { + Echo("Compiling " + Path.GetFileName(xFile)); + string xDest = Path.ChangeExtension(xFile, ".cs"); + if (File.Exists(xDest)) { + ResetReadOnly(xDest); + } + // We dont ref the X# asm directly because then we could not compile it without dynamic loading. + // This way we can build it and call it directly. + StartConsole(mOutputPath + @"\xsc.exe", Quoted(xFile) + @" Cosmos.Debug.DebugStub"); } Section("Compiling Cosmos"); - StartConsole(Paths.Windows + @"\Microsoft.NET\Framework\v4.0.30319\msbuild.exe", mCosmosPath + @"\source\Cosmos.sln /maxcpucount /verbosity:normal /nologo /p:Configuration=Builder /p:Platform=x86 /p:OutputPath=" + Quoted(xOutputPath)); + MsBuild(mCosmosPath + @"\source\Cosmos.sln", "Builder"); - CD(xOutputPath); + CD(mOutputPath); Section("Copying Templates"); // Copy templates diff --git a/source2/Build/Cosmos.Build.Builder/MainWindow.xaml b/source2/Build/Cosmos.Build.Builder/MainWindow.xaml index afbe65630..a599ae8fb 100644 --- a/source2/Build/Cosmos.Build.Builder/MainWindow.xaml +++ b/source2/Build/Cosmos.Build.Builder/MainWindow.xaml @@ -6,7 +6,10 @@ - + + + + diff --git a/source2/Build/Cosmos.Build.Builder/MainWindow.xaml.cs b/source2/Build/Cosmos.Build.Builder/MainWindow.xaml.cs index 8affa7c87..f4615eb29 100644 --- a/source2/Build/Cosmos.Build.Builder/MainWindow.xaml.cs +++ b/source2/Build/Cosmos.Build.Builder/MainWindow.xaml.cs @@ -63,9 +63,16 @@ namespace Cosmos.Build.Builder { }); } + void ClearTail() { + tblkTail1.Text = ""; + tblkTail2.Text = ""; + tblkTail3.Text = ""; + tblkTail4.Text = ""; + } + void Log_LogError() { Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - tblkCurrent.Text = ""; + ClearTail(); mSection.Foreground = Brushes.Red; mContent.Visibility = Visibility.Visible; @@ -75,7 +82,7 @@ namespace Cosmos.Build.Builder { void Log_LogSection(string aLine) { Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - tblkCurrent.Text = ""; + ClearTail(); mClipboard.AppendLine(); mClipboard.AppendLine(new string('=', aLine.Length)); @@ -108,7 +115,11 @@ namespace Cosmos.Build.Builder { void Log_LogLine(string aLine) { Dispatcher.Invoke(DispatcherPriority.Normal, (Action)delegate() { - tblkCurrent.Text = aLine; + tblkTail1.Text = tblkTail2.Text; + tblkTail2.Text = tblkTail3.Text; + tblkTail3.Text = tblkTail4.Text; + tblkTail4.Text = aLine; + mClipboard.AppendLine(aLine); mContent.Inlines.Add(aLine); diff --git a/source2/Build/Cosmos.Build.Installer/Task.cs b/source2/Build/Cosmos.Build.Installer/Task.cs index 9364bb2cd..97a5d8626 100644 --- a/source2/Build/Cosmos.Build.Installer/Task.cs +++ b/source2/Build/Cosmos.Build.Installer/Task.cs @@ -44,6 +44,7 @@ namespace Cosmos.Build.Installer { xProcess.WaitForExit(); if (xProcess.ExitCode != 0) { Log.SetError(); + throw new Exception("Console returned exit code."); } } } @@ -65,6 +66,7 @@ namespace Cosmos.Build.Installer { xProcess.WaitForExit(); if (xProcess.ExitCode != 0) { Log.SetError(); + throw new Exception("Application returned exit code."); } } } diff --git a/source2/Compiler/Cosmos.Compiler.XSharp.XSC/Program.cs b/source2/Compiler/Cosmos.Compiler.XSharp.XSC/Program.cs index d51f12877..99b480113 100644 --- a/source2/Compiler/Cosmos.Compiler.XSharp.XSC/Program.cs +++ b/source2/Compiler/Cosmos.Compiler.XSharp.XSC/Program.cs @@ -7,17 +7,15 @@ using System.Text; namespace Cosmos.Compiler.XSharp.XSC { class Program { static void Main(string[] aArgs) { - string xSrc = aArgs[1]; - string xDest = Path.ChangeExtension(xSrc, ".cs"); - string xNamespace = aArgs[2]; + try { + string xSrc = aArgs[0]; + string xNamespace = aArgs[1]; - using (var xInput = new StreamReader(xSrc)) { - using (var xOutput = new StreamWriter(xDest)) { - var xGenerator = new Generator(); - xGenerator.Name = Path.GetFileNameWithoutExtension(xSrc); - xGenerator.Namespace = xNamespace; - xGenerator.Execute(xInput, xOutput); - } + var xGenerator = new Generator(); + xGenerator.Execute(xNamespace, xSrc); + } catch (Exception ex) { + Console.WriteLine(ex.Message); + Environment.Exit(1); } } } diff --git a/source2/Compiler/Cosmos.XSharp/Generator.cs b/source2/Compiler/Cosmos.XSharp/Generator.cs index ac2f80eb2..36d0223ef 100644 --- a/source2/Compiler/Cosmos.XSharp/Generator.cs +++ b/source2/Compiler/Cosmos.XSharp/Generator.cs @@ -10,14 +10,21 @@ namespace Cosmos.Compiler.XSharp { protected TextReader mInput; protected TextWriter mOutput; protected TokenPatterns mPatterns = new TokenPatterns(); - public string Namespace { get; set; } - public string Name { get; set; } - public void Execute(TextReader aInput, TextWriter aOutput) { + public void Execute(string aNamespace, string aSrcPathname) { + using (var xInput = new StreamReader(aSrcPathname)) { + using (var xOutput = new StreamWriter(Path.ChangeExtension(aSrcPathname, ".cs"))) { + var xGenerator = new Generator(); + xGenerator.Execute(aNamespace, Path.GetFileNameWithoutExtension(aSrcPathname), xInput, xOutput); + } + } + } + + public void Execute(string aNamespace, string aClassname, TextReader aInput, TextWriter aOutput) { mInput = aInput; mOutput = aOutput; - EmitHeader(); + EmitHeader(aNamespace, aClassname); while (true) { string xLine = aInput.ReadLine(); if (xLine == null) { @@ -30,18 +37,18 @@ namespace Cosmos.Compiler.XSharp { EmitFooter(); } - private void EmitHeader() { + protected void EmitHeader(string aNamespace, string aClassname) { mOutput.WriteLine("using System;"); mOutput.WriteLine("using System.Linq;"); mOutput.WriteLine("using Cosmos.Assembler;"); mOutput.WriteLine("using Cosmos.Assembler.x86;"); mOutput.WriteLine(); - mOutput.WriteLine("namespace {0} {{", Namespace); - mOutput.WriteLine("\tpublic class {0} : Cosmos.Assembler.Code {{", Name); + mOutput.WriteLine("namespace {0} {{", aNamespace); + mOutput.WriteLine("\tpublic class {0} : Cosmos.Assembler.Code {{", aClassname); mOutput.WriteLine("\t\tpublic override void Assemble() {"); } - private void EmitFooter() { + protected void EmitFooter() { mOutput.WriteLine("\t\t}"); mOutput.WriteLine("\t}"); mOutput.WriteLine("}"); diff --git a/source2/Tests/XSharpCompilerTester/MainForm.cs b/source2/Tests/XSharpCompilerTester/MainForm.cs index c973b9b81..37a952ca5 100644 --- a/source2/Tests/XSharpCompilerTester/MainForm.cs +++ b/source2/Tests/XSharpCompilerTester/MainForm.cs @@ -29,9 +29,7 @@ namespace XSharpCompilerTester { using (var xOutput = new StringWriter()) { var xGenerator = new Cosmos.Compiler.XSharp.Generator(); - xGenerator.Name = "InputFileName"; - xGenerator.Namespace = "Default.Namespace"; - xGenerator.Execute(xInput, xOutput); + xGenerator.Execute("DefaultNamespace", "InputFileName", xInput, xOutput); textOutput.Text = xOutput.ToString(); } diff --git a/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs b/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs index ad9fab3f0..c3b28cdaa 100644 --- a/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs +++ b/source2/VSIP/Cosmos.VS.XSharp/FileGenerator.cs @@ -35,9 +35,7 @@ namespace Cosmos.VS.XSharp { using (var xInput = new StringReader(aInputFileContents)) { using (var xOutput = new StringWriter()) { var xGenerator = new Cosmos.Compiler.XSharp.Generator(); - xGenerator.Name = aInputFileName; - xGenerator.Namespace = aDefaultNamespace; - xGenerator.Execute(xInput, xOutput); + xGenerator.Execute(aDefaultNamespace, aInputFileName, xInput, xOutput); return xOutput.ToString(); } } diff --git a/source2/XSharp.sln b/source2/XSharp.sln index 9a968beb0..2263e11d6 100644 --- a/source2/XSharp.sln +++ b/source2/XSharp.sln @@ -7,21 +7,26 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Compiler.XSharp.Test EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.Compiler.XSharp.XSC", "Compiler\Cosmos.Compiler.XSharp.XSC\Cosmos.Compiler.XSharp.XSC.csproj", "{7B8499A7-0A8D-44FC-8181-9666CC198025}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.VS.XSharp", "VSIP\Cosmos.VS.XSharp\Cosmos.VS.XSharp.csproj", "{FB71E8EF-E229-4D81-984A-B9170D752BF9}" +EndProject Global GlobalSection(TeamFoundationVersionControl) = preSolution - SccNumberOfProjects = 4 + SccNumberOfProjects = 5 SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs04 - SccProjectUniqueName0 = Compiler\\Cosmos.XSharp\\Cosmos.Compiler.XSharp.csproj - SccProjectName0 = Compiler/Cosmos.XSharp - SccLocalPath0 = Compiler\\Cosmos.XSharp - SccProjectUniqueName1 = Tests\\XSharpCompilerTester\\Cosmos.Compiler.XSharp.Test.csproj - SccProjectName1 = Tests/XSharpCompilerTester - SccLocalPath1 = Tests\\XSharpCompilerTester - SccProjectUniqueName2 = Compiler\\Cosmos.Compiler.XSharp.XSC\\Cosmos.Compiler.XSharp.XSC.csproj - SccProjectName2 = Compiler/Cosmos.Compiler.XSharp.XSC - SccLocalPath2 = Compiler\\Cosmos.Compiler.XSharp.XSC - SccLocalPath3 = . + SccLocalPath0 = . + SccProjectUniqueName1 = Compiler\\Cosmos.XSharp\\Cosmos.Compiler.XSharp.csproj + SccProjectName1 = Compiler/Cosmos.XSharp + SccLocalPath1 = Compiler\\Cosmos.XSharp + SccProjectUniqueName2 = Tests\\XSharpCompilerTester\\Cosmos.Compiler.XSharp.Test.csproj + SccProjectName2 = Tests/XSharpCompilerTester + SccLocalPath2 = Tests\\XSharpCompilerTester + SccProjectUniqueName3 = Compiler\\Cosmos.Compiler.XSharp.XSC\\Cosmos.Compiler.XSharp.XSC.csproj + SccProjectName3 = Compiler/Cosmos.Compiler.XSharp.XSC + SccLocalPath3 = Compiler\\Cosmos.Compiler.XSharp.XSC + SccProjectUniqueName4 = VSIP\\Cosmos.VS.XSharp\\Cosmos.VS.XSharp.csproj + SccProjectName4 = VSIP/Cosmos.VS.XSharp + SccLocalPath4 = VSIP\\Cosmos.VS.XSharp EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -62,6 +67,16 @@ Global {7B8499A7-0A8D-44FC-8181-9666CC198025}.Release|Mixed Platforms.Build.0 = Release|x86 {7B8499A7-0A8D-44FC-8181-9666CC198025}.Release|x86.ActiveCfg = Release|x86 {7B8499A7-0A8D-44FC-8181-9666CC198025}.Release|x86.Build.0 = Release|x86 + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Debug|x86.ActiveCfg = Debug|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Release|Any CPU.Build.0 = Release|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {FB71E8EF-E229-4D81-984A-B9170D752BF9}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE