From 938ebb69e07f411d1413964b106e8115ad808c9b Mon Sep 17 00:00:00 2001 From: Benjamin Russell Date: Wed, 14 Sep 2016 10:29:34 -0700 Subject: [PATCH] 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 --- .gitignore | 4 + build.cake | 153 +++++++++++------- build.cmd | 1 + scripts/cake-bootstrap.ps1 | 4 +- scripts/packages.config | 1 + sqltoolsservice.sln | 21 +++ .../project.json | 7 +- 7 files changed, 133 insertions(+), 58 deletions(-) create mode 100644 build.cmd diff --git a/.gitignore b/.gitignore index 0f32c2ea..a52a0fe0 100644 --- a/.gitignore +++ b/.gitignore @@ -276,3 +276,7 @@ Session.vim # Visual Studio Code .vscode/ + +# Stuff from cake +/artifacts/ +/.tools/ \ No newline at end of file diff --git a/build.cake b/build.cake index 61047b05..1b7c3b80 100644 --- a/build.cake +++ b/build.cake @@ -81,7 +81,8 @@ Task("Cleanup") /// Pre-build setup tasks. /// 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. /// Task("PopulateRuntimes") - .IsDependentOn("BuildEnvironment") .Does(() => { buildPlan.Rids = new string[] @@ -112,43 +112,65 @@ Task("PopulateRuntimes") }); /// -/// Install/update build environment. +/// Install dotnet if it isn't already installed /// -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"); + } + } +}); +/// +/// 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(() =>{}); -/// -/// Run all tests for Travis CI .NET Desktop and .NET Core -/// -Task("TravisTestAll") - .IsDependentOn("Cleanup") - .IsDependentOn("TestAll") - .Does(() =>{}); - /// /// Run tests for .NET Core (using .NET CLI). /// @@ -345,6 +359,7 @@ Task("RestrictToLocalRuntime") /// Task("LocalPublish") .IsDependentOn("Restore") + .IsDependentOn("SrGen") .IsDependentOn("RestrictToLocalRuntime") .IsDependentOn("OnlyPublish") .Does(() => @@ -451,20 +466,6 @@ Task("Local") { }); -/// -/// Build centered around producing the final artifacts for Travis -/// -/// The tests are run as a different task "TestAll" -/// -Task("Travis") - .IsDependentOn("Cleanup") - .IsDependentOn("Restore") - .IsDependentOn("AllPublish") - // .IsDependentOn("TestPublished") - .Does(() => -{ -}); - /// /// Update the package versions within project.json files. /// Uses depversion.json file as input. @@ -492,6 +493,46 @@ Task("SetPackageVersions") } }); +/// +/// Executes SRGen to create a resx file and associated designer C# file +/// +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); + } +}); + /// /// Default Task aliases to Local. /// diff --git a/build.cmd b/build.cmd new file mode 100644 index 00000000..9a7e5104 --- /dev/null +++ b/build.cmd @@ -0,0 +1 @@ +powershell -File build.ps1 %* \ No newline at end of file diff --git a/scripts/cake-bootstrap.ps1 b/scripts/cake-bootstrap.ps1 index a87c1478..7f0bc382 100644 --- a/scripts/cake-bootstrap.ps1 +++ b/scripts/cake-bootstrap.ps1 @@ -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 diff --git a/scripts/packages.config b/scripts/packages.config index c4feb50f..296eeb59 100644 --- a/scripts/packages.config +++ b/scripts/packages.config @@ -2,4 +2,5 @@ + diff --git a/sqltoolsservice.sln b/sqltoolsservice.sln index cd55b538..15ece77f 100644 --- a/sqltoolsservice.sln +++ b/sqltoolsservice.sln @@ -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 diff --git a/src/Microsoft.SqlTools.ServiceLayer/project.json b/src/Microsoft.SqlTools.ServiceLayer/project.json index 25466abd..d698cec0 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/project.json +++ b/src/Microsoft.SqlTools.ServiceLayer/project.json @@ -24,7 +24,12 @@ }, "frameworks": { "netcoreapp1.0": { - "imports": "dnxcore50" + "dependencies": { + "Microsoft.NETCore.App": { + "version": "1.0.0" + } + }, + "imports": "dnxcore50" } }, "runtimes": {