From 6067839ba180f2f4bcd5eac67f839f68f513ccd2 Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Fri, 13 Oct 2023 18:16:08 -0400 Subject: Add `Files` file harvesting. Implements https://github.com/wixtoolset/issues/issues/7857. Like [naked files](https://github.com/wixtoolset/issues/issues/7696), `Files` elements can appear where `Component` elements do in WiX v4. The optimizer enumerates files and directories, generating single-file components as it goes. MSBuild-like wildcards (including `**`) are supported. `Excludes` child elements lets you exclude files that would otherwise be captured by wildcards. --- src/api/wix/WixToolset.Data/ErrorMessages.cs | 5 ++ .../WixToolset.Data/Symbols/HarvestFilesSymbol.cs | 84 ++++++++++++++++++++++ .../WixToolset.Data/Symbols/SymbolDefinitions.cs | 1 + .../Services/IParseHelper.cs | 2 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/api/wix/WixToolset.Data/Symbols/HarvestFilesSymbol.cs (limited to 'src/api') diff --git a/src/api/wix/WixToolset.Data/ErrorMessages.cs b/src/api/wix/WixToolset.Data/ErrorMessages.cs index 79b835cd..d604e94f 100644 --- a/src/api/wix/WixToolset.Data/ErrorMessages.cs +++ b/src/api/wix/WixToolset.Data/ErrorMessages.cs @@ -368,6 +368,11 @@ namespace WixToolset.Data return Message(sourceLineNumbers, Ids.ExpectedAttribute, "The {0}/@{1} attribute was not found; it is required unless the attribute {2} has a value of '{3}'.", elementName, attributeName, otherAttributeName, otherAttributeValue, otherAttributeValueUnless); } + public static Message ExpectedAttributeInElementOrParent(SourceLineNumber sourceLineNumbers, string elementName, string attributeName) + { + return Message(sourceLineNumbers, Ids.ExpectedAttributeInElementOrParent, "The {0}/@{1} attribute was not found or empty; it is required unless it is specified in the parent element.", elementName, attributeName); + } + public static Message ExpectedAttributeInElementOrParent(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string parentElementName) { return Message(sourceLineNumbers, Ids.ExpectedAttributeInElementOrParent, "The {0}/@{1} attribute was not found or empty; it is required, or it can be specified in the parent {2} element.", elementName, attributeName, parentElementName); diff --git a/src/api/wix/WixToolset.Data/Symbols/HarvestFilesSymbol.cs b/src/api/wix/WixToolset.Data/Symbols/HarvestFilesSymbol.cs new file mode 100644 index 00000000..a3123fc1 --- /dev/null +++ b/src/api/wix/WixToolset.Data/Symbols/HarvestFilesSymbol.cs @@ -0,0 +1,84 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Data +{ + using WixToolset.Data.Symbols; + + public static partial class SymbolDefinitions + { + public static readonly IntermediateSymbolDefinition HarvestFiles = new IntermediateSymbolDefinition( + SymbolDefinitionType.HarvestFiles, + new[] + { + new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.DirectoryRef), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.Inclusions), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.Exclusions), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.ComplexReferenceParentType), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.ParentId), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(HarvestFilesSymbolFields.SourcePath), IntermediateFieldType.String), + }, + typeof(HarvestFilesSymbol)); + } +} + +namespace WixToolset.Data.Symbols +{ + public enum HarvestFilesSymbolFields + { + DirectoryRef, + Inclusions, + Exclusions, + ComplexReferenceParentType, + ParentId, + SourcePath, + } + + public class HarvestFilesSymbol : IntermediateSymbol + { + public HarvestFilesSymbol() : base(SymbolDefinitions.HarvestFiles, null, null) + { + } + + public HarvestFilesSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(SymbolDefinitions.HarvestFiles, sourceLineNumber, id) + { + } + + public IntermediateField this[HarvestFilesSymbolFields index] => this.Fields[(int)index]; + + public string DirectoryRef + { + get => (string)this.Fields[(int)HarvestFilesSymbolFields.DirectoryRef]; + set => this.Set((int)HarvestFilesSymbolFields.DirectoryRef, value); + } + + public string Inclusions + { + get => (string)this.Fields[(int)HarvestFilesSymbolFields.Inclusions]; + set => this.Set((int)HarvestFilesSymbolFields.Inclusions, value); + } + + public string Exclusions + { + get => (string)this.Fields[(int)HarvestFilesSymbolFields.Exclusions]; + set => this.Set((int)HarvestFilesSymbolFields.Exclusions, value); + } + + public string ComplexReferenceParentType + { + get => (string)this.Fields[(int)HarvestFilesSymbolFields.ComplexReferenceParentType]; + set => this.Set((int)HarvestFilesSymbolFields.ComplexReferenceParentType, value); + } + + public string ParentId + { + get => (string)this.Fields[(int)HarvestFilesSymbolFields.ParentId]; + set => this.Set((int)HarvestFilesSymbolFields.ParentId, value); + } + + public string SourcePath + { + get => (string)this.Fields[(int)HarvestFilesSymbolFields.SourcePath]; + set => this.Set((int)HarvestFilesSymbolFields.SourcePath, value); + } + } +} diff --git a/src/api/wix/WixToolset.Data/Symbols/SymbolDefinitions.cs b/src/api/wix/WixToolset.Data/Symbols/SymbolDefinitions.cs index 3b545a71..67c00431 100644 --- a/src/api/wix/WixToolset.Data/Symbols/SymbolDefinitions.cs +++ b/src/api/wix/WixToolset.Data/Symbols/SymbolDefinitions.cs @@ -40,6 +40,7 @@ namespace WixToolset.Data FeatureComponents, File, FileSFPCatalog, + HarvestFiles, Icon, ImageFamilies, IniFile, diff --git a/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs index 3c20c14b..e7856c7c 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs @@ -11,7 +11,7 @@ namespace WixToolset.Extensibility.Services using WixToolset.Extensibility.Data; /// - /// Interface provided to help compiler extensions parse. + /// Interface provided to help compiler and optimizer extensions parse. /// public interface IParseHelper { -- cgit v1.2.3-55-g6feb