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
.vscode/
# Stuff from cake
/artifacts/
/.tools/

View File

@@ -81,7 +81,8 @@ Task("Cleanup")
/// Pre-build setup tasks.
/// </summary>
Task("Setup")
.IsDependentOn("BuildEnvironment")
.IsDependentOn("InstallDotnet")
.IsDependentOn("InstallXUnit")
.IsDependentOn("PopulateRuntimes")
.Does(() =>
{
@@ -92,7 +93,6 @@ Task("Setup")
/// Use default RID (+ win7-x86 on Windows) for now.
/// </summary>
Task("PopulateRuntimes")
.IsDependentOn("BuildEnvironment")
.Does(() =>
{
buildPlan.Rids = new string[]
@@ -112,43 +112,65 @@ Task("PopulateRuntimes")
});
/// <summary>
/// Install/update build environment.
/// Install dotnet if it isn't already installed
/// </summary>
Task("BuildEnvironment")
Task("InstallDotnet")
.Does(() =>
{
var installScript = $"dotnet-install.{shellExtension}";
System.IO.Directory.CreateDirectory(dotnetFolder);
var scriptPath = System.IO.Path.Combine(dotnetFolder, installScript);
using (WebClient client = new WebClient())
{
client.DownloadFile($"{buildPlan.DotNetInstallScriptURL}/{installScript}", scriptPath);
}
if (!IsRunningOnWindows())
{
Run("chmod", $"+x '{scriptPath}'");
}
var installArgs = $"-Channel {buildPlan.DotNetChannel}";
if (!String.IsNullOrEmpty(buildPlan.DotNetVersion))
{
installArgs = $"{installArgs} -Version {buildPlan.DotNetVersion}";
}
if (!buildPlan.UseSystemDotNetPath)
{
installArgs = $"{installArgs} -InstallDir {dotnetFolder}";
}
Run(shell, $"{shellArgument} {scriptPath} {installArgs}");
try
{
Run(dotnetcli, "--info");
}
catch (Win32Exception)
{
throw new Exception(".NET CLI binary cannot be found.");
}
// 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;
}
System.IO.Directory.CreateDirectory(toolsFolder);
// Install dotnet if it isn't already installed
if (!dotnetInstalled)
{
var installScript = $"dotnet-install.{shellExtension}";
System.IO.Directory.CreateDirectory(dotnetFolder);
var scriptPath = System.IO.Path.Combine(dotnetFolder, installScript);
using (WebClient client = new WebClient())
{
client.DownloadFile($"{buildPlan.DotNetInstallScriptURL}/{installScript}", scriptPath);
}
if (!IsRunningOnWindows())
{
Run("chmod", $"+x '{scriptPath}'");
}
var installArgs = $"-Channel {buildPlan.DotNetChannel}";
if (!String.IsNullOrEmpty(buildPlan.DotNetVersion))
{
installArgs = $"{installArgs} -Version {buildPlan.DotNetVersion}";
}
if (!buildPlan.UseSystemDotNetPath)
{
installArgs = $"{installArgs} -InstallDir {dotnetFolder}";
}
Run(shell, $"{shellArgument} {scriptPath} {installArgs}");
try
{
Run(dotnetcli, "--info");
}
catch (Win32Exception)
{
throw new Exception(".NET CLI failed to be installed");
}
}
});
/// <summary>
/// Installs XUnit nuget package
Task("InstallXUnit")
.Does(() =>
{
// Install the tools
var nugetPath = Environment.GetEnvironmentVariable("NUGET_EXE");
var arguments = $"install xunit.runner.console -ExcludeVersion -NoCache -Prerelease -OutputDirectory \"{toolsFolder}\"";
if (IsRunningOnWindows())
@@ -208,14 +230,6 @@ Task("TestAll")
.IsDependentOn("TestCore")
.Does(() =>{});
/// <summary>
/// Run all tests for Travis CI .NET Desktop and .NET Core
/// </summary>
Task("TravisTestAll")
.IsDependentOn("Cleanup")
.IsDependentOn("TestAll")
.Does(() =>{});
/// <summary>
/// Run tests for .NET Core (using .NET CLI).
/// </summary>
@@ -345,6 +359,7 @@ Task("RestrictToLocalRuntime")
/// </summary>
Task("LocalPublish")
.IsDependentOn("Restore")
.IsDependentOn("SrGen")
.IsDependentOn("RestrictToLocalRuntime")
.IsDependentOn("OnlyPublish")
.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>
/// Update the package versions within project.json files.
/// 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>
/// Default Task aliases to Local.
/// </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
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

View File

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

View File

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

View File

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