From 651ad904724f32f5e993fa73aa11a611d95a1a10 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 31 Dec 2017 02:17:12 -0800 Subject: Support filtering localizations by culture --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 9 +++--- .../CommandLine/CommandLineParser.cs | 32 ++++++++++++++++++++-- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'src/WixToolset.Core/CommandLine') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 48f1b214..5097bd9b 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -13,20 +13,20 @@ namespace WixToolset.Core.CommandLine internal class BuildCommand : ICommandLineCommand { - public BuildCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, IEnumerable libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable cultures, bool bindFiles, IEnumerable bindPaths, IEnumerable includeSearchPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile) + public BuildCommand(IServiceProvider serviceProvider, IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, IEnumerable libraryFiles, IEnumerable filterCultures, string outputPath, OutputType outputType, string cabCachePath, bool bindFiles, IEnumerable bindPaths, IEnumerable includeSearchPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile) { this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); this.ExtensionManager = serviceProvider.GetService(); this.LocFiles = locFiles; this.LibraryFiles = libraryFiles; + this.FilterCultures = filterCultures; this.PreprocessorVariables = preprocessorVariables; this.SourceFiles = sources; this.OutputPath = outputPath; this.OutputType = outputType; this.CabCachePath = cabCachePath; - this.Cultures = cultures; this.BindFiles = bindFiles; this.BindPaths = bindPaths; this.IncludeSearchPaths = includeSearchPaths; @@ -43,6 +43,8 @@ namespace WixToolset.Core.CommandLine public IExtensionManager ExtensionManager { get; } + public IEnumerable FilterCultures { get; } + public IEnumerable IncludeSearchPaths { get; } public IEnumerable LocFiles { get; } @@ -59,8 +61,6 @@ namespace WixToolset.Core.CommandLine public string CabCachePath { get; } - public IEnumerable Cultures { get; } - public bool BindFiles { get; } public IEnumerable BindPaths { get; } @@ -205,6 +205,7 @@ namespace WixToolset.Core.CommandLine { var resolver = new Resolver(this.ServiceProvider); resolver.BindPaths = this.BindPaths; + resolver.FilterCultures = this.FilterCultures; resolver.IntermediateFolder = this.IntermediateFolder; resolver.IntermediateRepresentation = output; resolver.Localizations = localizations; diff --git a/src/WixToolset.Core/CommandLine/CommandLineParser.cs b/src/WixToolset.Core/CommandLine/CommandLineParser.cs index 500bed08..f4bc8ade 100644 --- a/src/WixToolset.Core/CommandLine/CommandLineParser.cs +++ b/src/WixToolset.Core/CommandLine/CommandLineParser.cs @@ -114,7 +114,7 @@ namespace WixToolset.Core.CommandLine cmdline.GetNextArgumentOrError(ref cabCachePath); return true; - case "cultures": + case "culture": cmdline.GetNextArgumentOrError(cultures); return true; case "contentsfile": @@ -210,8 +210,9 @@ namespace WixToolset.Core.CommandLine var sourceFiles = GatherSourceFiles(files, outputFolder); var variables = this.GatherPreprocessorVariables(defines); var bindPathList = this.GatherBindPaths(bindPaths); + var filterCultures = CalculateFilterCultures(cultures); var type = CalculateOutputType(outputType, outputFile); - return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile); + return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile); } case Commands.Compile: @@ -225,6 +226,33 @@ namespace WixToolset.Core.CommandLine return null; } + private static IEnumerable CalculateFilterCultures(List cultures) + { + var result = new List(); + + if (cultures == null) + { + } + else if (cultures.Count == 1 && cultures[0].Equals("null", StringComparison.OrdinalIgnoreCase)) + { + // When null is used treat it as if cultures wasn't specified. This is + // needed for batching in the MSBuild task since MSBuild doesn't support + // empty items. + } + else + { + foreach (var culture in cultures) + { + // Neutral is different from null. For neutral we still want to do culture filtering. + // Set the culture to the empty string = identifier for the invariant culture. + var filter = (culture.Equals("neutral", StringComparison.OrdinalIgnoreCase)) ? String.Empty : culture; + result.Add(filter); + } + } + + return result; + } + private static OutputType CalculateOutputType(string outputType, string outputFile) { if (String.IsNullOrEmpty(outputType)) -- cgit v1.2.3-55-g6feb