Adding SRGen to build scripts (#45)

* Adding SRGen to build scripts

Adding support for sr.strings files. sr.strings files can be converted
into .resx and designer cs files by running the SRGen Cake target
Adding a new target to Cake script to run SRGen. SRGen is pulled down as a
nuget package for Cake and executes from the .tools folder.
Adding Cake temp environment to the gitignore
Adding the cake scripts to the sqltoolsservice solution file

* Fixes from pull request comments

* Fix as per @llali

* Actual changes as per @llali

* removing platform type from netcore dependency
This commit is contained in:
Benjamin Russell
2016-09-14 10:29:34 -07:00
committed by GitHub
parent f2a5654a20
commit 938ebb69e0
7 changed files with 133 additions and 58 deletions

4
.gitignore vendored
View File

@@ -276,3 +276,7 @@ Session.vim
# Visual Studio Code # Visual Studio Code
.vscode/ .vscode/
# Stuff from cake
/artifacts/
/.tools/

View File

@@ -81,7 +81,8 @@ Task("Cleanup")
/// Pre-build setup tasks. /// Pre-build setup tasks.
/// </summary> /// </summary>
Task("Setup") Task("Setup")
.IsDependentOn("BuildEnvironment") .IsDependentOn("InstallDotnet")
.IsDependentOn("InstallXUnit")
.IsDependentOn("PopulateRuntimes") .IsDependentOn("PopulateRuntimes")
.Does(() => .Does(() =>
{ {
@@ -92,7 +93,6 @@ Task("Setup")
/// Use default RID (+ win7-x86 on Windows) for now. /// Use default RID (+ win7-x86 on Windows) for now.
/// </summary> /// </summary>
Task("PopulateRuntimes") Task("PopulateRuntimes")
.IsDependentOn("BuildEnvironment")
.Does(() => .Does(() =>
{ {
buildPlan.Rids = new string[] buildPlan.Rids = new string[]
@@ -112,11 +112,27 @@ Task("PopulateRuntimes")
}); });
/// <summary> /// <summary>
/// Install/update build environment. /// Install dotnet if it isn't already installed
/// </summary> /// </summary>
Task("BuildEnvironment") Task("InstallDotnet")
.Does(() => .Does(() =>
{ {
// Determine if `dotnet` is installed
var dotnetInstalled = true;
try
{
Run(dotnetcli, "--info");
Information("dotnet is already installed, will skip download/install");
}
catch(Win32Exception)
{
// If we get this exception, dotnet isn't installed
dotnetInstalled = false;
}
// Install dotnet if it isn't already installed
if (!dotnetInstalled)
{
var installScript = $"dotnet-install.{shellExtension}"; var installScript = $"dotnet-install.{shellExtension}";
System.IO.Directory.CreateDirectory(dotnetFolder); System.IO.Directory.CreateDirectory(dotnetFolder);
var scriptPath = System.IO.Path.Combine(dotnetFolder, installScript); var scriptPath = System.IO.Path.Combine(dotnetFolder, installScript);
@@ -144,11 +160,17 @@ Task("BuildEnvironment")
} }
catch (Win32Exception) catch (Win32Exception)
{ {
throw new Exception(".NET CLI binary cannot be found."); throw new Exception(".NET CLI failed to be installed");
} }
}
});
System.IO.Directory.CreateDirectory(toolsFolder); /// <summary>
/// Installs XUnit nuget package
Task("InstallXUnit")
.Does(() =>
{
// Install the tools
var nugetPath = Environment.GetEnvironmentVariable("NUGET_EXE"); var nugetPath = Environment.GetEnvironmentVariable("NUGET_EXE");
var arguments = $"install xunit.runner.console -ExcludeVersion -NoCache -Prerelease -OutputDirectory \"{toolsFolder}\""; var arguments = $"install xunit.runner.console -ExcludeVersion -NoCache -Prerelease -OutputDirectory \"{toolsFolder}\"";
if (IsRunningOnWindows()) if (IsRunningOnWindows())
@@ -208,14 +230,6 @@ Task("TestAll")
.IsDependentOn("TestCore") .IsDependentOn("TestCore")
.Does(() =>{}); .Does(() =>{});
/// <summary>
/// Run all tests for Travis CI .NET Desktop and .NET Core
/// </summary>
Task("TravisTestAll")
.IsDependentOn("Cleanup")
.IsDependentOn("TestAll")
.Does(() =>{});
/// <summary> /// <summary>
/// Run tests for .NET Core (using .NET CLI). /// Run tests for .NET Core (using .NET CLI).
/// </summary> /// </summary>
@@ -345,6 +359,7 @@ Task("RestrictToLocalRuntime")
/// </summary> /// </summary>
Task("LocalPublish") Task("LocalPublish")
.IsDependentOn("Restore") .IsDependentOn("Restore")
.IsDependentOn("SrGen")
.IsDependentOn("RestrictToLocalRuntime") .IsDependentOn("RestrictToLocalRuntime")
.IsDependentOn("OnlyPublish") .IsDependentOn("OnlyPublish")
.Does(() => .Does(() =>
@@ -451,20 +466,6 @@ Task("Local")
{ {
}); });
/// <summary>
/// Build centered around producing the final artifacts for Travis
///
/// The tests are run as a different task "TestAll"
/// </summary>
Task("Travis")
.IsDependentOn("Cleanup")
.IsDependentOn("Restore")
.IsDependentOn("AllPublish")
// .IsDependentOn("TestPublished")
.Does(() =>
{
});
/// <summary> /// <summary>
/// Update the package versions within project.json files. /// Update the package versions within project.json files.
/// Uses depversion.json file as input. /// Uses depversion.json file as input.
@@ -492,6 +493,46 @@ Task("SetPackageVersions")
} }
}); });
/// <summary>
/// Executes SRGen to create a resx file and associated designer C# file
/// </summary>
Task("SRGen")
.Does(() =>
{
var projects = System.IO.Directory.GetFiles(sourceFolder, "project.json", SearchOption.AllDirectories).ToList();
foreach(var project in projects) {
var projectDir = System.IO.Path.GetDirectoryName(project);
var projectName = (new System.IO.DirectoryInfo(projectDir)).Name;
var projectStrings = System.IO.Path.Combine(projectDir, "sr.strings");
if (!System.IO.File.Exists(projectStrings))
{
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
continue;
}
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.DataTools.SrGen", "lib", "netcoreapp1.0", "srgen.dll");
var outputResx = System.IO.Path.Combine(projectDir, "sr.resx");
var outputCs = System.IO.Path.Combine(projectDir, "sr.cs");
// Delete preexisting resx and designer files
if (System.IO.File.Exists(outputResx))
{
System.IO.File.Delete(outputResx);
}
if (System.IO.File.Exists(outputCs))
{
System.IO.File.Delete(outputCs);
}
// Run SRGen
var dotnetArgs = string.Format("{0} -or \"{1}\" -oc \"{2}\" -ns \"{3}\" -an \"{4}\" -cn SR -l CS \"{5}\"",
srgenPath, outputResx, outputCs, projectName, projectName, projectStrings);
Information("{0}", dotnetArgs);
Run(dotnetcli, dotnetArgs);
}
});
/// <summary> /// <summary>
/// Default Task aliases to Local. /// Default Task aliases to Local.
/// </summary> /// </summary>

1
build.cmd Normal file
View File

@@ -0,0 +1 @@
powershell -File build.ps1 %*

View File

@@ -106,5 +106,7 @@ if (!(Test-Path $CAKE_EXE)) {
# Start Cake # Start Cake
Write-Host "Running build script..." Write-Host "Running build script..."
Invoke-Expression "& `"$CAKE_EXE`" `"$Script`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $ScriptArgs" $v = "& `"$CAKE_EXE`" `"$Script`" -verbosity=`"$Verbosity`" $UseMono $UseDryRun $ScriptArgs"
Write-Host $v
Invoke-Expression $v
exit $LASTEXITCODE exit $LASTEXITCODE

View File

@@ -2,4 +2,5 @@
<packages> <packages>
<package id="Cake" version="0.10.1" /> <package id="Cake" version="0.10.1" />
<package id="Newtonsoft.Json" version="8.0.3" /> <package id="Newtonsoft.Json" version="8.0.3" />
<package id="Microsoft.DataTools.SrGen" version="1.0.0" />
</packages> </packages>

View File

@@ -9,6 +9,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32DC973E-9EEA-4694-B1C2-B031167AB945}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32DC973E-9EEA-4694-B1C2-B031167AB945}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore .gitignore = .gitignore
BUILD.md = BUILD.md
global.json = global.json global.json = global.json
nuget.config = nuget.config nuget.config = nuget.config
README.md = README.md README.md = README.md
@@ -18,6 +19,25 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceL
EndProject EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.Test", "test\Microsoft.SqlTools.ServiceLayer.Test\Microsoft.SqlTools.ServiceLayer.Test.xproj", "{2D771D16-9D85-4053-9F79-E2034737DEEF}" Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.SqlTools.ServiceLayer.Test", "test\Microsoft.SqlTools.ServiceLayer.Test\Microsoft.SqlTools.ServiceLayer.Test.xproj", "{2D771D16-9D85-4053-9F79-E2034737DEEF}"
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "scripts", "scripts", "{B7D21727-2926-452B-9610-3ADB0BB6D789}"
ProjectSection(SolutionItems) = preProject
scripts\archiving.cake = scripts\archiving.cake
scripts\artifacts.cake = scripts\artifacts.cake
scripts\cake-bootstrap.ps1 = scripts\cake-bootstrap.ps1
scripts\cake-bootstrap.sh = scripts\cake-bootstrap.sh
scripts\packages.config = scripts\packages.config
scripts\runhelpers.cake = scripts\runhelpers.cake
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{F9978D78-78FE-4E92-A7D6-D436B7683EF6}"
ProjectSection(SolutionItems) = preProject
build.cake = build.cake
build.cmd = build.cmd
build.json = build.json
build.ps1 = build.ps1
build.sh = build.sh
EndProjectSection
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -39,5 +59,6 @@ Global
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{0D61DC2B-DA66-441D-B9D0-F76C98F780F9} = {2BBD7364-054F-4693-97CD-1C395E3E84A9} {0D61DC2B-DA66-441D-B9D0-F76C98F780F9} = {2BBD7364-054F-4693-97CD-1C395E3E84A9}
{2D771D16-9D85-4053-9F79-E2034737DEEF} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4} {2D771D16-9D85-4053-9F79-E2034737DEEF} = {AB9CA2B8-6F70-431C-8A1D-67479D8A7BE4}
{B7D21727-2926-452B-9610-3ADB0BB6D789} = {F9978D78-78FE-4E92-A7D6-D436B7683EF6}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@@ -24,6 +24,11 @@
}, },
"frameworks": { "frameworks": {
"netcoreapp1.0": { "netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0"
}
},
"imports": "dnxcore50" "imports": "dnxcore50"
} }
}, },