mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Remove .Net Core 1.0 requirement for Loc and fix mac build (#841)
* Remove .Net Core 1.0 requirement for Loc and fix mac build Use StringResourceTool to remove .Net Core 1.0 dependency for Loc Fixed Mac build by copying the code used in internal repo for build. - This now mostly matches internal, so expect this should work OK.
This commit is contained in:
Binary file not shown.
163
build.cake
163
build.cake
@@ -554,87 +554,106 @@ Task("SetPackageVersions")
|
||||
Task("SRGen")
|
||||
.Does(() =>
|
||||
{
|
||||
var projects = System.IO.Directory.GetFiles(sourceFolder, "*.csproj", SearchOption.AllDirectories).ToList();
|
||||
var locTemplateDir = System.IO.Path.Combine(sourceFolder, "../localization");
|
||||
// save current working directory to restore at end of task
|
||||
var taskStartedWorkingDirectory = System.IO.Directory.GetCurrentDirectory();
|
||||
try
|
||||
{
|
||||
var projects = System.IO.Directory.GetFiles(sourceFolder, "*.csproj", SearchOption.AllDirectories).ToList();
|
||||
var locTemplateDir = System.IO.Path.Combine(sourceFolder, "../localization");
|
||||
|
||||
foreach(var project in projects) {
|
||||
var projectDir = System.IO.Path.GetDirectoryName(project);
|
||||
var localizationDir = System.IO.Path.Combine(projectDir, "Localization");
|
||||
var projectName = (new System.IO.DirectoryInfo(projectDir)).Name;
|
||||
var projectNameSpace = projectName + ".Localization";
|
||||
var projectStrings = System.IO.Path.Combine(localizationDir, "sr.strings");
|
||||
foreach(var project in projects) {
|
||||
var projectDir = System.IO.Path.GetDirectoryName(project);
|
||||
|
||||
if (!System.IO.File.Exists(projectStrings))
|
||||
{
|
||||
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
|
||||
continue;
|
||||
}
|
||||
// set current directory to this project so relative paths can be reliably
|
||||
// used. This is to address an issue with quoting differences between Windows
|
||||
// and MacOS. On MacOS the dotnet command ends up calling SRGen with quotations around
|
||||
// the arguments stripped off. This causes SRGen to interpret the arg values as options
|
||||
System.IO.Directory.SetCurrentDirectory(projectDir);
|
||||
|
||||
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.DataTools.SrGen", "lib", "netcoreapp1.0", "srgen.dll");
|
||||
var outputResx = System.IO.Path.Combine(localizationDir, "sr.resx");
|
||||
var inputXliff = System.IO.Path.Combine(localizationDir, "transXliff");
|
||||
var outputXlf = System.IO.Path.Combine(localizationDir, "sr.xlf");
|
||||
var outputCs = System.IO.Path.Combine(localizationDir, "sr.cs");
|
||||
// build remaining paths relative to the project directory
|
||||
var localizationDir = System.IO.Path.Combine(".", "Localization");
|
||||
var projectName = (new System.IO.DirectoryInfo(projectDir)).Name;
|
||||
var projectNameSpace = projectName + ".Localization";
|
||||
var projectStrings = System.IO.Path.Combine(localizationDir, "sr.strings");
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
if (!System.IO.Directory.Exists(inputXliff))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(inputXliff);
|
||||
}
|
||||
|
||||
// Run SRGen
|
||||
var dotnetArgs = string.Format("{0} -or \"{1}\" -oc \"{2}\" -ns \"{3}\" -an \"{4}\" -cn SR -l CS -dnx \"{5}\"",
|
||||
srgenPath, outputResx, outputCs, projectName, projectNameSpace, projectStrings);
|
||||
Information("{0}", dotnetArgs);
|
||||
Run(dotnetcli, dotnetArgs)
|
||||
.ExceptionOnError("Failed to run SRGen.");
|
||||
|
||||
// Update XLF file from new Resx file
|
||||
var doc = new XliffParser.XlfDocument(outputXlf);
|
||||
doc.UpdateFromSource();
|
||||
var outputXlfFile = doc.Files.Single();
|
||||
foreach (var unit in outputXlfFile.TransUnits)
|
||||
{
|
||||
unit.Target = unit.Source;
|
||||
}
|
||||
doc.Save();
|
||||
|
||||
// Update ResX files from new xliff files
|
||||
var xlfDocNames = System.IO.Directory.GetFiles(inputXliff, "*.xlf", SearchOption.AllDirectories).ToList();
|
||||
foreach(var docName in xlfDocNames)
|
||||
{
|
||||
// load our language XLIFF
|
||||
var xlfDoc = new XliffParser.XlfDocument(docName);
|
||||
var xlfFile = xlfDoc.Files.Single();
|
||||
|
||||
// load a language template
|
||||
var templateFileLocation = System.IO.Path.Combine(locTemplateDir, System.IO.Path.GetFileName(docName) + ".template");
|
||||
var templateDoc = new XliffParser.XlfDocument(templateFileLocation);
|
||||
var templateFile = templateDoc.Files.Single();
|
||||
|
||||
// iterate through our tranlation units and prune invalid units
|
||||
foreach (var unit in xlfFile.TransUnits)
|
||||
if (!System.IO.File.Exists(projectStrings))
|
||||
{
|
||||
// if a unit does not have a target it is invalid
|
||||
if (unit.Target != null) {
|
||||
templateFile.AddTransUnit(unit.Id, unit.Source, unit.Target, 0, 0);
|
||||
}
|
||||
Information("Project {0} doesn't contain 'sr.strings' file", projectName);
|
||||
continue;
|
||||
}
|
||||
|
||||
// export modified template to RESX
|
||||
var newPath = System.IO.Path.Combine(localizationDir, System.IO.Path.GetFileName(docName));
|
||||
templateDoc.SaveAsResX(newPath.Replace("xlf","resx"));
|
||||
var srgenPath = System.IO.Path.Combine(toolsFolder, "Microsoft.Data.Tools.StringResourceTool", "tools", "netcoreapp2.2", "any", "srgen.dll");
|
||||
var outputResx = System.IO.Path.Combine(localizationDir, "sr.resx");
|
||||
var inputXliff = System.IO.Path.Combine(localizationDir, "transXliff");
|
||||
var outputXlf = System.IO.Path.Combine(localizationDir, "sr.xlf");
|
||||
var outputCs = System.IO.Path.Combine(localizationDir, "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);
|
||||
}
|
||||
|
||||
if (!System.IO.Directory.Exists(inputXliff))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(inputXliff);
|
||||
}
|
||||
|
||||
// Run SRGen
|
||||
var dotnetArgs = string.Format("{0} -or \"{1}\" -oc \"{2}\" -ns \"{3}\" -an \"{4}\" -cn SR -l CS -dnx \"{5}\"",
|
||||
srgenPath, outputResx, outputCs, projectName, projectNameSpace, projectStrings);
|
||||
Information("{0}", dotnetcli);
|
||||
Information("{0}", dotnetArgs);
|
||||
Run(dotnetcli, dotnetArgs)
|
||||
.ExceptionOnError("Failed to run SRGen.");
|
||||
|
||||
// Update XLF file from new Resx file
|
||||
var doc = new XliffParser.XlfDocument(outputXlf);
|
||||
doc.UpdateFromSource();
|
||||
var outputXlfFile = doc.Files.Single();
|
||||
foreach (var unit in outputXlfFile.TransUnits)
|
||||
{
|
||||
unit.Target = unit.Source;
|
||||
}
|
||||
doc.Save();
|
||||
|
||||
// Update ResX files from new xliff files
|
||||
var xlfDocNames = System.IO.Directory.GetFiles(inputXliff, "*.xlf", SearchOption.AllDirectories).ToList();
|
||||
foreach(var docName in xlfDocNames)
|
||||
{
|
||||
// load our language XLIFF
|
||||
var xlfDoc = new XliffParser.XlfDocument(docName);
|
||||
var xlfFile = xlfDoc.Files.Single();
|
||||
|
||||
// load a language template
|
||||
var templateFileLocation = System.IO.Path.Combine(locTemplateDir, System.IO.Path.GetFileName(docName) + ".template");
|
||||
var templateDoc = new XliffParser.XlfDocument(templateFileLocation);
|
||||
var templateFile = templateDoc.Files.Single();
|
||||
|
||||
// iterate through our tranlation units and prune invalid units
|
||||
foreach (var unit in xlfFile.TransUnits)
|
||||
{
|
||||
// if a unit does not have a target it is invalid
|
||||
if (unit.Target != null) {
|
||||
templateFile.AddTransUnit(unit.Id, unit.Source, unit.Target, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// export modified template to RESX
|
||||
var newPath = System.IO.Path.Combine(localizationDir, System.IO.Path.GetFileName(docName));
|
||||
templateDoc.SaveAsResX(newPath.Replace("xlf","resx"));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
// restore the original working directory
|
||||
System.IO.Directory.SetCurrentDirectory(taskStartedWorkingDirectory);
|
||||
}
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#load "runhelpers.cake"
|
||||
|
||||
using System;
|
||||
using System.IO.Compression;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Cake" version="0.17.0" />
|
||||
<package id="Newtonsoft.Json" version="8.0.3" />
|
||||
<package id="Microsoft.DataTools.SrGen" version="1.0.2" />
|
||||
<package id="Cake" version="0.30.0" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" />
|
||||
<package id="Microsoft.Data.Tools.StringResourceTool" version="1.0.0" />
|
||||
<package id="Mono.TextTransform" version="1.0.0" />
|
||||
<package id="mssql.XliffParser" version="0.5.3" />
|
||||
<package id="mssql.ResX" version="0.2.0" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user