Skip to content

Commit 918332a

Browse files
committed
Handle scope of configurable-scope BundlePackages.
Fixes wixtoolset/issues#9233
1 parent 92714e7 commit 918332a

9 files changed

Lines changed: 81 additions & 11 deletions

File tree

src/burn/engine/apply.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,7 +2761,7 @@ static HRESULT ExecuteRelatedBundle(
27612761
}
27622762
else
27632763
{
2764-
hrExecute = BundlePackageEngineExecuteRelatedBundle(pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, GenericExecuteMessageHandler, pContext, pRestart);
2764+
hrExecute = BundlePackageEngineExecuteRelatedBundle(pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, FALSE/*fPerMachine*/, GenericExecuteMessageHandler, pContext, pRestart);
27652765
ExitOnFailure(hrExecute, "Failed to configure per-user related bundle.");
27662766
}
27672767

@@ -2888,7 +2888,7 @@ static HRESULT ExecuteBundlePackage(
28882888
}
28892889
else
28902890
{
2891-
hrExecute = BundlePackageEngineExecutePackage(pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, SUCCEEDED(pExecuteAction->bundlePackage.pPackage->hrCacheResult), GenericExecuteMessageHandler, pContext, pRestart);
2891+
hrExecute = BundlePackageEngineExecutePackage(pExecuteAction, pContext->pCache, &pEngineState->variables, fRollback, SUCCEEDED(pExecuteAction->bundlePackage.pPackage->hrCacheResult), pEngineState->registration.fPerMachine, GenericExecuteMessageHandler, pContext, pRestart);
28922892
ExitOnFailure(hrExecute, "Failed to configure per-user BUNDLE package.");
28932893
}
28942894

src/burn/engine/bundlepackageengine.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ static HRESULT ExecuteBundle(
2525
__in BOOTSTRAPPER_RELATION_TYPE relationType,
2626
__in BURN_PACKAGE* pPackage,
2727
__in BOOL fPseudoPackage,
28+
__in BOOL fPerMachine,
2829
__in_z_opt LPCWSTR wzParent,
2930
__in_z_opt LPCWSTR wzIgnoreDependencies,
3031
__in_z_opt LPCWSTR wzAncestors,
@@ -51,7 +52,7 @@ extern "C" HRESULT BundlePackageEngineParsePackageFromXml(
5152
BOOL fFoundXml = FALSE;
5253
LPWSTR scz = NULL;
5354

54-
// @DetectCondition
55+
// @BundleCode
5556
hr = XmlGetAttributeEx(pixnBundlePackage, L"BundleCode", &pPackage->Bundle.sczBundleCode);
5657
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @BundleCode.");
5758

@@ -91,6 +92,10 @@ extern "C" HRESULT BundlePackageEngineParsePackageFromXml(
9192
hr = XmlGetYesNoAttribute(pixnBundlePackage, L"Win64", &pPackage->Bundle.fWin64);
9293
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Win64.");
9394

95+
// @Scope
96+
hr = PackageParseScopeFromXml(pixnBundlePackage, &pPackage->scope);
97+
ExitOnRequiredXmlQueryFailure(hr, "Failed to get @Scope.");
98+
9499
hr = BundlePackageEngineParseRelatedCodes(pixnBundlePackage, &pPackage->Bundle.rgsczDetectCodes, &pPackage->Bundle.cDetectCodes, &pPackage->Bundle.rgsczUpgradeCodes, &pPackage->Bundle.cUpgradeCodes, &pPackage->Bundle.rgsczAddonCodes, &pPackage->Bundle.cAddonCodes, &pPackage->Bundle.rgsczPatchCodes, &pPackage->Bundle.cPatchCodes);
95100
ExitOnFailure(hr, "Failed to parse related codes.");
96101

@@ -608,6 +613,7 @@ extern "C" HRESULT BundlePackageEngineExecutePackage(
608613
__in BURN_VARIABLES* pVariables,
609614
__in BOOL fRollback,
610615
__in BOOL fCacheAvailable,
616+
__in BOOL fPerMachine,
611617
__in PFN_GENERICMESSAGEHANDLER pfnGenericMessageHandler,
612618
__in LPVOID pvContext,
613619
__out BOOTSTRAPPER_APPLY_RESTART* pRestart
@@ -621,14 +627,15 @@ extern "C" HRESULT BundlePackageEngineExecutePackage(
621627
BOOTSTRAPPER_RELATION_TYPE relationType = BOOTSTRAPPER_RELATION_CHAIN_PACKAGE;
622628
BURN_PACKAGE* pPackage = pExecuteAction->bundlePackage.pPackage;
623629

624-
return ExecuteBundle(pCache, pVariables, fRollback, fCacheAvailable, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, FALSE, wzParent, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart);
630+
return ExecuteBundle(pCache, pVariables, fRollback, fCacheAvailable, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, FALSE, fPerMachine, wzParent, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart);
625631
}
626632

627633
extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle(
628634
__in BURN_EXECUTE_ACTION* pExecuteAction,
629635
__in BURN_CACHE* pCache,
630636
__in BURN_VARIABLES* pVariables,
631637
__in BOOL fRollback,
638+
__in BOOL fPerMachine,
632639
__in PFN_GENERICMESSAGEHANDLER pfnGenericMessageHandler,
633640
__in LPVOID pvContext,
634641
__out BOOTSTRAPPER_APPLY_RESTART* pRestart
@@ -643,7 +650,7 @@ extern "C" HRESULT BundlePackageEngineExecuteRelatedBundle(
643650
BOOTSTRAPPER_RELATION_TYPE relationType = ConvertRelationType(pRelatedBundle->planRelationType);
644651
BURN_PACKAGE* pPackage = &pRelatedBundle->package;
645652

646-
return ExecuteBundle(pCache, pVariables, fRollback, TRUE, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, TRUE, wzParent, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart);
653+
return ExecuteBundle(pCache, pVariables, fRollback, TRUE, pfnGenericMessageHandler, pvContext, action, relationType, pPackage, TRUE, fPerMachine, wzParent, wzIgnoreDependencies, wzAncestors, wzEngineWorkingDirectory, pRestart);
647654
}
648655

649656
extern "C" void BundlePackageEngineUpdateInstallRegistrationState(
@@ -742,6 +749,7 @@ static HRESULT ExecuteBundle(
742749
__in BOOTSTRAPPER_RELATION_TYPE relationType,
743750
__in BURN_PACKAGE* pPackage,
744751
__in BOOL fPseudoPackage,
752+
__in BOOL fPerMachine,
745753
__in_z_opt LPCWSTR wzParent,
746754
__in_z_opt LPCWSTR wzIgnoreDependencies,
747755
__in_z_opt LPCWSTR wzAncestors,
@@ -987,6 +995,16 @@ static HRESULT ExecuteBundle(
987995
hr = CoreAppendFileHandleSelfToCommandLine(sczExecutablePath, &hExecutableFile, &sczBaseCommand, NULL);
988996
ExitOnFailure(hr, "Failed to append %ls", BURN_COMMANDLINE_SWITCH_FILEHANDLE_SELF);
989997

998+
// Configurable-scope bundle packages get the scope of the parent bundle.
999+
// Note that the command-line switch takes effect only if the BA does a
1000+
// default plan.
1001+
if (BOOTSTRAPPER_PACKAGE_SCOPE_PER_MACHINE_OR_PER_USER == pPackage->scope
1002+
|| BOOTSTRAPPER_PACKAGE_SCOPE_PER_USER_OR_PER_MACHINE == pPackage->scope)
1003+
{
1004+
hr = StrAllocConcat(&sczBaseCommand, fPerMachine ? L" -permachine" : L" -peruser", 0);
1005+
ExitOnFailure(hr, "Failed to append scope switch to the command line.");
1006+
}
1007+
9901008
// build user args
9911009
if (sczUnformattedUserArgs && *sczUnformattedUserArgs)
9921010
{

src/burn/engine/bundlepackageengine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ HRESULT BundlePackageEngineExecutePackage(
5454
__in BURN_VARIABLES* pVariables,
5555
__in BOOL fRollback,
5656
__in BOOL fCacheAvailable,
57+
__in BOOL fPerMachine,
5758
__in PFN_GENERICMESSAGEHANDLER pfnGenericMessageHandler,
5859
__in LPVOID pvContext,
5960
__out BOOTSTRAPPER_APPLY_RESTART* pRestart
@@ -63,6 +64,7 @@ HRESULT BundlePackageEngineExecuteRelatedBundle(
6364
__in BURN_CACHE* pCache,
6465
__in BURN_VARIABLES* pVariables,
6566
__in BOOL fRollback,
67+
__in BOOL fPerMachine,
6668
__in PFN_GENERICMESSAGEHANDLER pfnGenericExecuteProgress,
6769
__in LPVOID pvContext,
6870
__out BOOTSTRAPPER_APPLY_RESTART* pRestart

src/burn/engine/elevation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ static HRESULT OnExecuteRelatedBundle(
29132913
}
29142914

29152915
// Execute related bundle.
2916-
hr = BundlePackageEngineExecuteRelatedBundle(&executeAction, pCache, pVariables, static_cast<BOOL>(dwRollback), GenericExecuteMessageHandler, hPipe, pRestart);
2916+
hr = BundlePackageEngineExecuteRelatedBundle(&executeAction, pCache, pVariables, static_cast<BOOL>(dwRollback), TRUE/*fPerMachine*/, GenericExecuteMessageHandler, hPipe, pRestart);
29172917
ExitOnFailure(hr, "Failed to execute related bundle.");
29182918

29192919
LExit:
@@ -3008,7 +3008,7 @@ static HRESULT OnExecuteBundlePackage(
30083008
}
30093009

30103010
// Execute BUNDLE package.
3011-
hr = BundlePackageEngineExecutePackage(&executeAction, pCache, pVariables, fRollback, fCacheAvailable, GenericExecuteMessageHandler, hPipe, pRestart);
3011+
hr = BundlePackageEngineExecutePackage(&executeAction, pCache, pVariables, fRollback, fCacheAvailable, TRUE/*fPerMachine*/, GenericExecuteMessageHandler, hPipe, pRestart);
30123012
ExitOnFailure(hr, "Failed to execute BUNDLE package.");
30133013

30143014
LExit:

src/test/burn/TestBA/TestBA.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ private void ShutdownUiThread(int? exitCode = null)
227227

228228
protected override void OnDetectBegin(DetectBeginEventArgs args)
229229
{
230-
this.Log("OnDetectBegin");
230+
this.Log($"OnDetectBegin: Cached={args.Cached}, RegistrationType={args.RegistrationType}, PackageCount={args.PackageCount}");
231231

232232
this.forceUpdateSource = this.ReadPackageAction(null, "ForceUpdateSource");
233233
if (!String.IsNullOrEmpty(this.forceUpdateSource))

src/test/burn/TestData/ConfigurableScopeTests/PuomBundlePackage/PuomBundlePackage.wixproj renamed to src/test/burn/TestData/ConfigurableScopeTests/PuomBundlePackage/Bundle.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<Project Sdk="WixToolset.Sdk">
1+
<Project>
22
<PropertyGroup>
33
<OutputType>Bundle</OutputType>
44
</PropertyGroup>
55
<ItemGroup>
66
<PackageReference Include="WixToolset.BootstrapperApplications.wixext" />
7+
<PackageReference Include="WixToolset.NetFx.wixext" />
78
</ItemGroup>
89
<ItemGroup>
10+
<ProjectReference Include="..\..\TestBA\TestBAWixlib\testbawixlib.wixproj" />
911
<ProjectReference Include="..\AllPuomBundle\AllPuomBundleTestBA.wixproj" />
1012
</ItemGroup>
1113
</Project>
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:bal="http://wixtoolset.org/schemas/v4/wxs/bal">
2-
<Bundle Id="AllPuomBundle" Name="AllPuomBundle" Manufacturer="Acme" Version="1.0.0.0">
2+
<Bundle Id="PuomBundlePackage$(BA)" Name="PuomBundlePackage$(BA)" Manufacturer="Acme" Version="1.0.0.0">
3+
<?if $(BA) = "WixStdBA"?>
34
<BootstrapperApplication>
45
<bal:WixStandardBootstrapperApplication LicenseUrl="https://www.example.com/license" Theme="hyperlinkLicense" />
56
</BootstrapperApplication>
7+
<?endif?>
8+
9+
<Variable Name="TestGroupName" Value="ConfigurableScopeTests" />
610

711
<Chain>
8-
<BundlePackage SourceFile="AllPuomBundleTestBA.exe" />
12+
<?if $(BA) = "TestBA"?>
13+
<PackageGroupRef Id="TestBA" />
14+
<?endif?>
15+
<BundlePackage SourceFile="AllPuomBundle$(BA).exe" />
916
</Chain>
1017
</Bundle>
1118
</Wix>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="WixToolset.Sdk">
2+
<PropertyGroup>
3+
<BA>TestBA</BA>
4+
</PropertyGroup>
5+
6+
<Import Project="Bundle.props" />
7+
</Project>

src/test/burn/WixToolsetTest.BurnE2E/ConfigurableScopeTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,40 @@ public void PM_PU_PUOM_Bundle_PU_Plan_Installs_PerUserMostly()
685685
pkg2.VerifyInstalled(false);
686686
}
687687

688+
[RuntimeFact]
689+
public void ConfigurableScopeBundlePackage_Follows_PerUser_Scope()
690+
{
691+
var testBAController = this.CreateTestBAController();
692+
testBAController.SetBundleScope(BundleScope.PerUser);
693+
694+
var bundle = this.CreateBundleInstaller("PuomBundlePackageTestBA");
695+
var log = bundle.Install();
696+
697+
bundle.VerifyRegisteredAndInPackageCache(plannedPerMachine: false);
698+
699+
Assert.True(LogVerifier.MessageInLogFile(log, "Plan begin, 2 packages, action: Install, planned scope: PerUser"));
700+
Assert.True(LogVerifier.MessageInLogFile(log, "Planned package: AllPuomBundleTestBA.exe, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, scope: PerUser"));
701+
702+
bundle.Uninstall();
703+
bundle.VerifyUnregisteredAndRemovedFromPackageCache(plannedPerMachine: false);
704+
}
688705

706+
[RuntimeFact]
707+
public void ConfigurableScopeBundlePackage_Follows_PerMachine_Scope()
708+
{
709+
var testBAController = this.CreateTestBAController();
710+
testBAController.SetBundleScope(BundleScope.PerMachine);
711+
712+
var bundle = this.CreateBundleInstaller("PuomBundlePackageTestBA");
713+
var log = bundle.Install();
714+
715+
bundle.VerifyRegisteredAndInPackageCache(plannedPerMachine: true);
716+
717+
Assert.True(LogVerifier.MessageInLogFile(log, "Plan begin, 2 packages, action: Install, planned scope: PerMachine"));
718+
Assert.True(LogVerifier.MessageInLogFile(log, "Planned package: AllPuomBundleTestBA.exe, state: Absent, default requested: Present, ba requested: Present, execute: Install, rollback: Uninstall, scope: PerMachine"));
719+
720+
bundle.Uninstall();
721+
bundle.VerifyUnregisteredAndRemovedFromPackageCache(plannedPerMachine: true);
722+
}
689723
}
690724
}

0 commit comments

Comments
 (0)