-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a new phase in the build pipeline.
A useful point in the build pipeline is after all the files in the project have been compiled but before they've been linked. The WiX core and extensions can operate on symbols across the project but without operating at the source-code level. This phase is currently named "optimize," after a moderately-similar phase in other compiler architectures. The name is, for now, a stake in the ground and a better alternate is welcome.
- Loading branch information
Showing
14 changed files
with
253 additions
and
7 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/api/wix/WixToolset.Extensibility/BaseOptimizerExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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.Extensibility | ||
{ | ||
using WixToolset.Extensibility.Data; | ||
|
||
/// <summary> | ||
/// Base class for creating an optimizer extension. | ||
/// </summary> | ||
public abstract class BaseOptimizerExtension : IOptimizerExtension | ||
{ | ||
/// <summary> | ||
/// Called after all files have been compiled, before built-in optimizations, and before all sections are linked into a single section. | ||
/// </summary> | ||
public virtual void PreOptimize(IOptimizeContext context) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Called after all files have been compiled, after built-in optimizations, and before all sections are linked into a single section. | ||
/// </summary> | ||
public virtual void PostOptimize(IOptimizeContext context) | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/api/wix/WixToolset.Extensibility/Data/IOptimizeContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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.Extensibility.Data | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using WixToolset.Data; | ||
|
||
/// <summary> | ||
/// Context provided to the optimizer. | ||
/// </summary> | ||
public interface IOptimizeContext | ||
{ | ||
/// <summary> | ||
/// Service provider made available to the optimizer and its extensions. | ||
/// </summary> | ||
IServiceProvider ServiceProvider { get; } | ||
|
||
/// <summary> | ||
/// Set of extensions provided to the optimizer. | ||
/// </summary> | ||
IReadOnlyCollection<IOptimizerExtension> Extensions { get; set; } | ||
|
||
/// <summary> | ||
/// Intermediate folder. | ||
/// </summary> | ||
string IntermediateFolder { get; set; } | ||
|
||
/// <summary> | ||
/// Collection of bindpaths used to bind files. | ||
/// </summary> | ||
IReadOnlyCollection<IBindPath> BindPaths { get; set; } | ||
|
||
/// <summary> | ||
/// Bind variables used during optimization. | ||
/// </summary> | ||
IDictionary<string, string> BindVariables { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the platform which the optimizer will use when defaulting 64-bit symbol properties. | ||
/// </summary> | ||
/// <value>The platform which the optimizer will use when defaulting 64-bit symbol properties.</value> | ||
Platform Platform { get; set; } | ||
|
||
/// <summary> | ||
/// Collection of intermediates to optimize. | ||
/// </summary> | ||
IReadOnlyCollection<Intermediate> Intermediates { get; set; } | ||
|
||
/// <summary> | ||
/// Collection of localization files to use in the optimizer. | ||
/// </summary> | ||
IReadOnlyCollection<Localization> Localizations { get; set; } | ||
|
||
/// <summary> | ||
/// Cancellation token. | ||
/// </summary> | ||
CancellationToken CancellationToken { get; set; } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/api/wix/WixToolset.Extensibility/IOptimizerExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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.Extensibility | ||
{ | ||
using WixToolset.Extensibility.Data; | ||
|
||
/// <summary> | ||
/// Interface that all optimizer extensions implement. | ||
/// </summary> | ||
public interface IOptimizerExtension | ||
{ | ||
/// <summary> | ||
/// Called after all files have been compiled, before built-in optimizations, and before all sections are linked into a single section. | ||
/// </summary> | ||
void PreOptimize(IOptimizeContext context); | ||
|
||
/// <summary> | ||
/// Called after all files have been compiled, after built-in optimizations, and before all sections are linked into a single section. | ||
/// </summary> | ||
void PostOptimize(IOptimizeContext context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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.Core | ||
{ | ||
using WixToolset.Extensibility.Data; | ||
|
||
/// <summary> | ||
/// Interface for built-in optimizer. | ||
/// </summary> | ||
public interface IOptimizer | ||
{ | ||
/// <summary> | ||
/// Called after all files have been compiled and before all sections are linked into a single section. | ||
/// </summary> | ||
void Optimize(IOptimizeContext context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// 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.Core | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using WixToolset.Data; | ||
using WixToolset.Extensibility; | ||
using WixToolset.Extensibility.Data; | ||
|
||
internal class OptimizeContext : IOptimizeContext | ||
{ | ||
internal OptimizeContext(IServiceProvider serviceProvider) | ||
{ | ||
this.ServiceProvider = serviceProvider; | ||
} | ||
|
||
public IServiceProvider ServiceProvider { get; } | ||
|
||
public IReadOnlyCollection<IOptimizerExtension> Extensions { get; set; } | ||
|
||
public string IntermediateFolder { get; set; } | ||
|
||
public IReadOnlyCollection<IBindPath> BindPaths { get; set; } | ||
|
||
public IDictionary<string, string> BindVariables { get; set; } | ||
|
||
public Platform Platform { get; set; } | ||
|
||
public bool IsCurrentPlatform64Bit => this.Platform == Platform.ARM64 || this.Platform == Platform.X64; | ||
|
||
public IReadOnlyCollection<Intermediate> Intermediates { get; set; } | ||
|
||
public IReadOnlyCollection<Localization> Localizations { get; set; } | ||
|
||
public CancellationToken CancellationToken { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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.Core | ||
{ | ||
using System; | ||
using WixToolset.Extensibility.Data; | ||
using WixToolset.Extensibility.Services; | ||
|
||
internal class Optimizer : IOptimizer | ||
{ | ||
internal Optimizer(IServiceProvider serviceProvider) | ||
{ | ||
this.ServiceProvider = serviceProvider; | ||
this.Messaging = this.ServiceProvider.GetService<IMessaging>(); | ||
} | ||
|
||
private IServiceProvider ServiceProvider { get; } | ||
|
||
private IMessaging Messaging { get; } | ||
|
||
public void Optimize(IOptimizeContext context) | ||
{ | ||
foreach (var extension in context.Extensions) | ||
{ | ||
extension.PreOptimize(context); | ||
} | ||
|
||
// TODO: Fill with useful optimization features. | ||
|
||
foreach (var extension in context.Extensions) | ||
{ | ||
extension.PostOptimize(context); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/wix/test/Example.Extension/ExampleOptimizerExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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 Example.Extension | ||
{ | ||
using System.Linq; | ||
using WixToolset.Extensibility; | ||
using WixToolset.Extensibility.Data; | ||
|
||
internal class ExampleOptimizerExtension : BaseOptimizerExtension | ||
{ | ||
public override void PostOptimize(IOptimizeContext context) | ||
{ | ||
foreach (var intermediate in context.Intermediates) | ||
{ | ||
foreach (var symbol in intermediate.Sections.SelectMany(s=>s.Symbols).OfType<ExampleSymbol>()) | ||
{ | ||
symbol.Value = $"{symbol.Value} <optimized>"; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters