X# to builder.

This commit is contained in:
kudzu_cp 2012-06-15 01:54:58 +00:00
parent 3d0ee77433
commit 3488e34972
9 changed files with 97 additions and 45 deletions

View file

@ -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

View file

@ -6,7 +6,10 @@
<WrapPanel DockPanel.Dock="Top">
<Button Name="butnCopy" Click="butnCopy_Click">Copy</Button>
</WrapPanel>
<TextBlock DockPanel.Dock="Top" Name="tblkCurrent" FontSize="16" />
<TextBlock DockPanel.Dock="Top" Name="tblkTail1" FontSize="16" />
<TextBlock DockPanel.Dock="Top" Name="tblkTail2" FontSize="16" />
<TextBlock DockPanel.Dock="Top" Name="tblkTail3" FontSize="16" />
<TextBlock DockPanel.Dock="Top" Name="tblkTail4" FontSize="16" />
<ScrollViewer HorizontalScrollBarVisibility="Visible">
<StackPanel Name="spnlLog" />
</ScrollViewer>

View file

@ -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);

View file

@ -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.");
}
}
}

View file

@ -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);
}
}
}

View file

@ -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("}");

View file

@ -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();
}

View file

@ -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();
}
}

View file

@ -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