Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always run upgrade related bundles last #89

Merged
merged 1 commit into from Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Directory.Build.props
Expand Up @@ -6,6 +6,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<EnableSourceLink Condition=" '$(NCrunch)' == '1' ">false</EnableSourceLink>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NoWarn>$(NoWarn);MSB3026</NoWarn>

<ProjectName Condition=" '$(ProjectName)' == '' ">$(MSBuildProjectName)</ProjectName>
<RootBuildFolder>$([System.IO.Path]::GetFullPath($(MSBuildThisFileDirectory)..\build\))</RootBuildFolder>
Expand Down
2 changes: 2 additions & 0 deletions src/burn/engine/registration.cpp
Expand Up @@ -585,6 +585,8 @@ extern "C" HRESULT RegistrationDetectRelatedBundles(
hr = RelatedBundlesInitializeForScope(FALSE, pRegistration, &pRegistration->relatedBundles);
ExitOnFailure(hr, "Failed to initialize per-user related bundles.");

RelatedBundlesSort(&pRegistration->relatedBundles);

LExit:
return hr;
}
Expand Down
55 changes: 55 additions & 0 deletions src/burn/engine/relatedbundle.cpp
Expand Up @@ -4,6 +4,11 @@

// internal function declarations

static __callback int __cdecl CompareRelatedBundles(
__in void* pvContext,
__in const void* pvLeft,
__in const void* pvRight
);
static HRESULT LoadIfRelatedBundle(
__in BOOL fPerMachine,
__in HKEY hkUninstallKey,
Expand Down Expand Up @@ -128,9 +133,59 @@ extern "C" HRESULT RelatedBundleFindById(
return hr;
}

extern "C" void RelatedBundlesSort(
__in BURN_RELATED_BUNDLES* pRelatedBundles
)
{
qsort_s(pRelatedBundles->rgRelatedBundles, pRelatedBundles->cRelatedBundles, sizeof(BURN_RELATED_BUNDLE), CompareRelatedBundles, NULL);
}


// internal helper functions

static __callback int __cdecl CompareRelatedBundles(
__in void* /*pvContext*/,
__in const void* pvLeft,
__in const void* pvRight
)
{
int ret = 0;
const BURN_RELATED_BUNDLE* pBundleLeft = static_cast<const BURN_RELATED_BUNDLE*>(pvLeft);
const BURN_RELATED_BUNDLE* pBundleRight = static_cast<const BURN_RELATED_BUNDLE*>(pvRight);

// Sort by relation type, then version, then bundle id.
if (pBundleLeft->relationType != pBundleRight->relationType)
{
// Upgrade bundles last, everything else according to the enum.
if (BOOTSTRAPPER_RELATION_UPGRADE == pBundleLeft->relationType)
{
ret = 1;
}
else if (BOOTSTRAPPER_RELATION_UPGRADE == pBundleRight->relationType)
{
ret = -1;
}
else if (pBundleLeft->relationType < pBundleRight->relationType)
{
ret = -1;
}
else
{
ret = 1;
}
}
else
{
VerCompareParsedVersions(pBundleLeft->pVersion, pBundleRight->pVersion, &ret);
if (0 == ret)
{
ret = ::CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE, pBundleLeft->package.sczId, -1, pBundleRight->package.sczId, -1) - 2;
}
}

return ret;
}

static HRESULT LoadIfRelatedBundle(
__in BOOL fPerMachine,
__in HKEY hkUninstallKey,
Expand Down
3 changes: 3 additions & 0 deletions src/burn/engine/relatedbundle.h
Expand Up @@ -19,6 +19,9 @@ HRESULT RelatedBundleFindById(
__in_z LPCWSTR wzId,
__out BURN_RELATED_BUNDLE** ppRelatedBundle
);
void RelatedBundlesSort(
__in BURN_RELATED_BUNDLES* pRelatedBundles
);

#if defined(__cplusplus)
}
Expand Down
42 changes: 28 additions & 14 deletions src/test/burn/BurnE2ETests.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29503.13
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestBA", "TestBA\TestBA.csproj", "{04022D35-6D75-49D0-91D2-4208E09DBA6D}"
EndProject
Expand All @@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolset.WixBA", "WixTool
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WixToolsetTest.BurnE2E", "WixToolsetTest.BurnE2E\WixToolsetTest.BurnE2E.csproj", "{FED9D707-E5C3-4867-87B0-FABDB5EB0823}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ForTestingUseOnly.wixext", "ForTestingUseOnlyExtension\ForTestingUseOnly.wixext.csproj", "{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,18 +61,6 @@ Global
{3D3B02F3-79B6-4BD5-AD49-2889DA3849A7}.Release|x64.Build.0 = Release|Any CPU
{3D3B02F3-79B6-4BD5-AD49-2889DA3849A7}.Release|x86.ActiveCfg = Release|Any CPU
{3D3B02F3-79B6-4BD5-AD49-2889DA3849A7}.Release|x86.Build.0 = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x64.ActiveCfg = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x64.Build.0 = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x86.ActiveCfg = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x86.Build.0 = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|Any CPU.Build.0 = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x64.ActiveCfg = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x64.Build.0 = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x86.ActiveCfg = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x86.Build.0 = Release|Any CPU
{7C27518B-84AD-4679-8EF4-29DF552CF1AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C27518B-84AD-4679-8EF4-29DF552CF1AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C27518B-84AD-4679-8EF4-29DF552CF1AC}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -83,6 +73,30 @@ Global
{7C27518B-84AD-4679-8EF4-29DF552CF1AC}.Release|x64.Build.0 = Release|Any CPU
{7C27518B-84AD-4679-8EF4-29DF552CF1AC}.Release|x86.ActiveCfg = Release|Any CPU
{7C27518B-84AD-4679-8EF4-29DF552CF1AC}.Release|x86.Build.0 = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x64.ActiveCfg = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x64.Build.0 = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x86.ActiveCfg = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Debug|x86.Build.0 = Debug|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|Any CPU.Build.0 = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x64.ActiveCfg = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x64.Build.0 = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x86.ActiveCfg = Release|Any CPU
{FED9D707-E5C3-4867-87B0-FABDB5EB0823}.Release|x86.Build.0 = Release|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Debug|x64.ActiveCfg = Debug|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Debug|x64.Build.0 = Debug|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Debug|x86.ActiveCfg = Debug|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Debug|x86.Build.0 = Debug|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Release|Any CPU.Build.0 = Release|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Release|x64.ActiveCfg = Release|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Release|x64.Build.0 = Release|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Release|x86.ActiveCfg = Release|Any CPU
{0037E6A3-45C6-4AB6-BC8C-1CB0C145E992}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions src/test/burn/Directory.wixproj.props
Expand Up @@ -7,5 +7,6 @@
<DefaultCompressionLevel>None</DefaultCompressionLevel>
<CompilerAdditionalOptions>-wx</CompilerAdditionalOptions>
<SuppressSpecificWarnings>1154;$(SuppressSpecificWarnings)</SuppressSpecificWarnings>
<ForTestingUseOnlyWixextPath>$(BaseOutputPath)$(Configuration)\netstandard2.0\ForTestingUseOnly.wixext.dll</ForTestingUseOnlyWixextPath>
</PropertyGroup>
</Project>
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>ForTestingUseOnly</RootNamespace>
<DebugType>embedded</DebugType>
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="WixToolset.Extensibility" PrivateAssets="all" />
</ItemGroup>
</Project>
@@ -0,0 +1,43 @@
// 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 ForTestingUseOnly
{
using System.Collections.Generic;
using System.Linq;
using ForTestingUseOnly.Symbols;
using WixToolset.Data;
using WixToolset.Data.Symbols;
using WixToolset.Extensibility;

/// <summary>
/// Extension for doing completely unsupported things in the name of testing.
/// </summary>
public class ForTestingUseOnlyBurnBackendExtension : BaseBurnBackendBinderExtension
{
private static readonly IntermediateSymbolDefinition[] BurnSymbolDefinitions =
{
ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle,
};

protected override IReadOnlyCollection<IntermediateSymbolDefinition> SymbolDefinitions => BurnSymbolDefinitions;

public override void SymbolsFinalized(IntermediateSection section)
{
base.SymbolsFinalized(section);

this.FinalizeBundleSymbol(section);
}

private void FinalizeBundleSymbol(IntermediateSection section)
{
var forTestingUseOnlyBundleSymbol = section.Symbols.OfType<ForTestingUseOnlyBundleSymbol>().SingleOrDefault();
if (null == forTestingUseOnlyBundleSymbol)
{
return;
}

var bundleSymbol = section.Symbols.OfType<WixBundleSymbol>().Single();
bundleSymbol.ProviderKey = bundleSymbol.BundleId = forTestingUseOnlyBundleSymbol.BundleId;
}
}
}
@@ -0,0 +1,77 @@
// 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 ForTestingUseOnly
{
using System;
using System.Collections.Generic;
using System.Xml.Linq;
using ForTestingUseOnly.Symbols;
using WixToolset.Data;
using WixToolset.Extensibility;

/// <summary>
/// Extension for doing completely unsupported things in the name of testing.
/// </summary>
public sealed class ForTestingUseOnlyCompiler : BaseCompilerExtension
{
public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/fortestinguseonly";

public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context)
{
switch (element.Name.LocalName)
{
case "ForTestingUseOnlyBundle":
this.ParseForTestingUseOnlyBundleElement(intermediate, section, element);
break;
default:
this.ParseHelper.UnexpectedElement(parentElement, element);
break;
}
}

private void ParseForTestingUseOnlyBundleElement(Intermediate intermediate, IntermediateSection section, XElement element)
{
var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
string bundleId = null;

foreach (var attrib in element.Attributes())
{
if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
{
switch (attrib.Name.LocalName)
{
case "Id":
bundleId = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
break;
default:
this.ParseHelper.UnexpectedAttribute(element, attrib);
break;
}
}
else
{
this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, element, attrib);
}
}

if (null == bundleId)
{
this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
}
else
{
bundleId = Guid.Parse(bundleId).ToString("B").ToUpperInvariant();
}

this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, element);

if (!this.Messaging.EncounteredError)
{
section.AddSymbol(new ForTestingUseOnlyBundleSymbol(sourceLineNumbers, new Identifier(AccessModifier.Global, "ForTestingUseOnlyBundle"))
{
BundleId = bundleId,
});
}
}
}
}
@@ -0,0 +1,16 @@
// 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 ForTestingUseOnly
{
using WixToolset.Data;
using WixToolset.Extensibility;

public sealed class ForTestingUseOnlyExtensionData : BaseExtensionData
{
public override bool TryGetSymbolDefinitionByName(string name, out IntermediateSymbolDefinition symbolDefinition)
{
symbolDefinition = ForTestingUseOnlySymbolDefinitions.ByName(name);
return symbolDefinition != null;
}
}
}
@@ -0,0 +1,18 @@
// 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 ForTestingUseOnly
{
using System;
using System.Collections.Generic;
using WixToolset.Extensibility;

public class ForTestingUseOnlyExtensionFactory : BaseExtensionFactory
{
protected override IReadOnlyCollection<Type> ExtensionTypes => new[]
{
typeof(ForTestingUseOnlyCompiler),
typeof(ForTestingUseOnlyExtensionData),
typeof(ForTestingUseOnlyBurnBackendExtension),
};
}
}
@@ -0,0 +1,47 @@
// 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 ForTestingUseOnly
{
using WixToolset.Data;
using ForTestingUseOnly.Symbols;

public static partial class ForTestingUseOnlySymbolDefinitions
{
public static readonly IntermediateSymbolDefinition ForTestingUseOnlyBundle = new IntermediateSymbolDefinition(
ForTestingUseOnlySymbolDefinitionType.ForTestingUseOnlyBundle.ToString(),
new[]
{
new IntermediateFieldDefinition(nameof(ForTestingUseOnlyBundleSymbolFields.BundleId), IntermediateFieldType.String),
},
typeof(ForTestingUseOnlyBundleSymbol));
}
}

namespace ForTestingUseOnly.Symbols
{
using WixToolset.Data;

public enum ForTestingUseOnlyBundleSymbolFields
{
BundleId,
}

public class ForTestingUseOnlyBundleSymbol : IntermediateSymbol
{
public ForTestingUseOnlyBundleSymbol() : base(ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle, null, null)
{
}

public ForTestingUseOnlyBundleSymbol(SourceLineNumber sourceLineNumber, Identifier id = null) : base(ForTestingUseOnlySymbolDefinitions.ForTestingUseOnlyBundle, sourceLineNumber, id)
{
}

public IntermediateField this[ForTestingUseOnlyBundleSymbolFields index] => this.Fields[(int)index];

public string BundleId
{
get => this.Fields[(int)ForTestingUseOnlyBundleSymbolFields.BundleId].AsString();
set => this.Set((int)ForTestingUseOnlyBundleSymbolFields.BundleId, value);
}
}
}