From 84d1f05fee656c01938613bcc50bd8139006bbf6 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 31 Dec 2017 00:43:02 -0800 Subject: Support preprocessing .wxl files --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 57 ++++++++++++++++--------- src/WixToolset.Core/Localizer.cs | 17 ++++++-- 2 files changed, 50 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index e11cd15a..48f1b214 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -75,37 +75,48 @@ namespace WixToolset.Core.CommandLine public int Execute() { - var intermediates = this.CompilePhase(); + var wixobjs = this.CompilePhase(); if (this.Messaging.EncounteredError) { return this.Messaging.LastErrorNumber; } - if (!intermediates.Any()) + if (!wixobjs.Any()) { return 1; } - if (this.OutputType == OutputType.Library) - { - var library = this.LibraryPhase(intermediates); + var wxls = this.LoadLocalizationFiles(); - library?.Save(this.OutputPath); + if (this.Messaging.EncounteredError) + { + return this.Messaging.LastErrorNumber; } - else if (this.OutputType == OutputType.IntermediatePostLink) + + if (this.OutputType == OutputType.Library) { - var output = this.LinkPhase(intermediates); + var wixlib = this.LibraryPhase(wixobjs, wxls); - output?.Save(this.OutputPath); + if (!this.Messaging.EncounteredError) + { + wixlib.Save(this.OutputPath); + } } else { - var output = this.LinkPhase(intermediates); + var wixipl = this.LinkPhase(wixobjs); if (!this.Messaging.EncounteredError) { - this.BindPhase(output); + if (this.OutputType == OutputType.IntermediatePostLink) + { + wixipl.Save(this.OutputPath); + } + else + { + this.BindPhase(wixipl, wxls); + } } } @@ -147,10 +158,8 @@ namespace WixToolset.Core.CommandLine return intermediates; } - private Intermediate LibraryPhase(IEnumerable intermediates) + private Intermediate LibraryPhase(IEnumerable intermediates, IEnumerable localizations) { - var localizations = this.LoadLocalizationFiles().ToList(); - // If there was an error loading localization files, then bail. if (this.Messaging.EncounteredError) { @@ -184,12 +193,8 @@ namespace WixToolset.Core.CommandLine return linker.Execute(); } - private void BindPhase(Intermediate output) + private void BindPhase(Intermediate output, IEnumerable localizations) { - var localizations = new List(output.Localizations); - - localizations.AddRange(this.LoadLocalizationFiles()); - // If there was an error loading localization files, then bail. if (this.Messaging.EncounteredError) { @@ -288,7 +293,19 @@ namespace WixToolset.Core.CommandLine { foreach (var loc in this.LocFiles) { - var localization = Localizer.ParseLocalizationFile(this.Messaging, loc); + var preprocessor = new Preprocessor(this.ServiceProvider); + preprocessor.IncludeSearchPaths = this.IncludeSearchPaths; + preprocessor.Platform = Platform.X86; // TODO: set this correctly + preprocessor.SourcePath = loc; + preprocessor.Variables = this.PreprocessorVariables; + var document = preprocessor.Execute(); + + if (this.Messaging.EncounteredError) + { + continue; + } + + var localization = Localizer.ParseLocalizationFile(this.Messaging, document); yield return localization; } diff --git a/src/WixToolset.Core/Localizer.cs b/src/WixToolset.Core/Localizer.cs index 38d8864e..cb9a4406 100644 --- a/src/WixToolset.Core/Localizer.cs +++ b/src/WixToolset.Core/Localizer.cs @@ -22,13 +22,22 @@ namespace WixToolset.Core /// /// Loads a localization file from a path on disk. /// - /// Path to library file saved on disk. - /// Collection containing TableDefinitions to use when loading the localization file. - /// Suppress xml schema validation while loading. + /// Path to localization file saved on disk. /// Returns the loaded localization file. public static Localization ParseLocalizationFile(IMessaging messaging, string path) { - XElement root = XDocument.Load(path).Root; + var document = XDocument.Load(path); + return ParseLocalizationFile(messaging, document); + } + + /// + /// Loads a localization file from memory. + /// + /// Document to parse as localization file. + /// Returns the loaded localization file. + public static Localization ParseLocalizationFile(IMessaging messaging, XDocument document) + { + XElement root = document.Root; Localization localization = null; SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(root); -- cgit v1.2.3-55-g6feb