Skip to content

Commit

Permalink
Merge/Port 1.0 license support into main/1.1 (#2012)
Browse files Browse the repository at this point in the history
* Update installer to support both publishing IDs used in App SDK. (#1759)

* draft changes

* fixing typo

Co-authored-by: Ben Kuhn <benkuhn@ntdev.microsoft.com>

* Added MSIX license support (#1783)

* Update installer to support installing licenses. Structure in place, need to coordinate with build pipeline to implement InstallLicenses (instead of printf)

* Simplified help

* Added missing Copyright. Add valid license for inner-loop testing. Added --dry-run and other command line parameters (to expedite testing as well as product benefit). Wired up install flow. Next is testing the actual get-license-from-stream-and-install

* It works! Verified with stub NOP implementation here for dev inner-loop and full pipeline bits. Improved error reporting.

* Add license support to Deployment API and a new InstallLicenses API (#1790)

* Updated DeploymentManager to install license files if necessary

* Add stubs for the InstallLicenseFile() methods

* Change installer to install licenses BEFORE packages, for higher reliability

* Copy the license header to the source tree to use whehn building via the pipeline]

* Add Licensing API and export from Bootstrap'r

* Added some pseudocode in MsixInstallLicenses(). Real implementation coming RSN

* yml changes to pickup licensing package when needed.

* moving restore to the top of the pipeline.

* moving back, wrong stage

* Fixed license filename

* add nuget authenticate call

* differnt connection

* adding nuget config for build

* avoid using licensing support in github / PR builds, which don't have access to the resources

* update script to capture package version / name.

* one missed check

* Incorported feedback

* udpdating nuget.config name to avoid conflicts.

Co-authored-by: Ben Kuhn <benkuhn@ntdev.microsoft.com>

* Incorporated feedback

Co-authored-by: Ben Kuhn <bjk4929@yahoo.com>
Co-authored-by: Ben Kuhn <benkuhn@ntdev.microsoft.com>
  • Loading branch information
3 people authored Jan 26, 2022
1 parent 0780fe5 commit 6df1822
Show file tree
Hide file tree
Showing 37 changed files with 781 additions and 48 deletions.
8 changes: 8 additions & 0 deletions WindowsAppRuntime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RestartAgent", "dev\Restart
{F76B776E-86F5-48C5-8FC7-D2795ECC9746} = {F76B776E-86F5-48C5-8FC7-D2795ECC9746}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Licensing", "Licensing", "{34671779-4A4D-4D0E-B259-CD0F14D4F6D4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Licensing", "dev\Licensing\Licensing.vcxitems", "{885A43FA-052D-4B0D-A2DC-13EE15796435}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
test\inc\inc.vcxitems*{0a5fee93-48b7-40ec-bb9a-b27d11060da9}*SharedItemsImports = 4
Expand All @@ -271,10 +275,12 @@ Global
test\inc\inc.vcxitems*{56a1d696-feda-4333-bf37-772ebececb10}*SharedItemsImports = 4
test\inc\inc.vcxitems*{5b2d17fe-c371-417f-860c-3d32397c2404}*SharedItemsImports = 4
test\inc\inc.vcxitems*{7c502995-59c3-483b-86ba-815985353633}*SharedItemsImports = 4
dev\Licensing\Licensing.vcxitems*{885a43fa-052d-4b0d-a2dc-13ee15796435}*SharedItemsImports = 9
test\inc\inc.vcxitems*{8e52d7ea-a200-4a6b-ba74-8efb49468caf}*SharedItemsImports = 4
test\inc\inc.vcxitems*{b567fe2e-3a03-48d0-b2b5-760cdec35891}*SharedItemsImports = 9
dev\Common\Common.vcxitems*{b73ad907-6164-4294-88fb-f3c9c10da1f1}*SharedItemsImports = 4
dev\DynamicDependency\API\DynamicDependency.vcxitems*{b73ad907-6164-4294-88fb-f3c9c10da1f1}*SharedItemsImports = 4
dev\Licensing\Licensing.vcxitems*{b73ad907-6164-4294-88fb-f3c9c10da1f1}*SharedItemsImports = 4
dev\PowerNotifications\PowerNotifications.vcxitems*{b73ad907-6164-4294-88fb-f3c9c10da1f1}*SharedItemsImports = 4
dev\UndockedRegFreeWinRT\UndockedRegFreeWinRT.vcxitems*{b73ad907-6164-4294-88fb-f3c9c10da1f1}*SharedItemsImports = 4
dev\PowerNotifications\PowerNotifications.vcxitems*{b75c1b22-553c-40e4-b38e-6ab4d01fdb9d}*SharedItemsImports = 9
Expand Down Expand Up @@ -1049,6 +1055,8 @@ Global
{09DDAE21-397F-4263-8561-7F2FF28127CF} = {0C534F12-B076-47E5-A05B-2A711233AC6F}
{6539E9E1-BF36-40E5-86BC-070E99DB7B7B} = {6CD01EF6-D4A4-4801-ADCF-344CF87FF942}
{BC5E5A3E-E733-4388-8B00-F8495DA7C778} = {3DE93B2F-F887-437D-B512-6B1024ABA290}
{34671779-4A4D-4D0E-B259-CD0F14D4F6D4} = {448ED2E5-0B37-4D97-9E6B-8C10A507976A}
{885A43FA-052D-4B0D-A2DC-13EE15796435} = {34671779-4A4D-4D0E-B259-CD0F14D4F6D4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4B3D7591-CFEC-4762-9A07-ABE99938FB77}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
channel: 'experimental'
enableLicenseInstall: false

steps:
- template: WindowsAppSDK-BuildProject-Steps.yml
Expand All @@ -9,3 +10,4 @@ steps:
buildOutputDir: $(buildOutputDir)
publishDir: $(publishDir)
channel: ${{ parameters.channel }}
enableLicenseInstall: ${{ parameters.enableLicenseInstall }}
38 changes: 38 additions & 0 deletions build/AzurePipelinesTemplates/WindowsAppSDK-BuildProject-Steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,34 @@ parameters:
buildOutputDir: '$(Build.SourcesDirectory)\BuildOutput'
artifactName: 'drop'
channel: 'experimental'
enableLicenseInstall: false
# license installation assets are only accessible in internal builds, but are only
# needed in release-signed stable builds. Only enble this functionality in the private
# pipeline builds. Otherwise, default to an inert placeholder implementation.


steps:
- ${{ if eq(parameters.enableLicenseInstall, true) }}:
- task: NuGetAuthenticate@0
inputs:
nuGetServiceConnections: 'ProjectReunionInternal'

# Restore transport package dependencies. This is only enbaled in release-signed builds.
- task: PowerShell@2
name: ConvertVersionDetailsToPackageConfig
displayName: "Convert VersionDetails To PackageConfig"
inputs:
filePath: '$(Build.SourcesDirectory)\build\Scripts\ConvertVersionDetailsToPackageConfig.ps1'
arguments: -versionDetailsPath '$(Build.SourcesDirectory)\eng\Version.Details.xml' -packageConfigPath '$(Build.SourcesDirectory)\build\packages.config'

- task: 333b11bd-d341-40d9-afcf-b32d5ce6f23b@2
displayName: RestoreNuGetPackages
inputs:
restoreSolution: build/packages.config
feedsToUse: config
nugetConfigPath: build/licensing.nuget.config
restoreDirectory: packages

- template: WindowsAppSDK-PopulateBuildDateAndRevision-Steps.yml

- script: |
Expand Down Expand Up @@ -119,6 +145,18 @@ steps:
}
}
# Copy MSIX license installation header into the correct source location.
- ${{ if eq(parameters.enableLicenseInstall, true) }}:
- task: CopyFiles@2
displayName: 'Extract license header to source location'
inputs:
SourceFolder: '$(Build.SourcesDirectory)\build\packages\$(AppLicensingInternalPackageName).$(AppLicensingInternalPackageVersion)\src'
Contents: |
*.h
TargetFolder: '$(Build.SourcesDirectory)\dev\Licensing'
flattenFolders: false
overWrite: true
- task: VSBuild@1
displayName: 'Build solution ${{ parameters.solutionPath }}'
inputs:
Expand Down
2 changes: 2 additions & 0 deletions build/ProjectReunion-BuildFoundation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
- template: AzurePipelinesTemplates\WindowsAppSDK-BuildDevProject-Steps.yml
parameters:
channel: ${{ variables.channel }}
enableLicenseInstall: true

# component detection must happen *within* the build task
- task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0
Expand Down Expand Up @@ -166,6 +167,7 @@ jobs:
buildOutputDir: $(buildOutputDir)
publishDir: $(publishDir)
channel: ${{ variables.channel }}
enableLicenseInstall: true

- task: CopyFiles@2
displayName: 'Copy AnyCpu-built binaries to Nuget for staging'
Expand Down
25 changes: 25 additions & 0 deletions build/licensing.nuget.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<!--
Where packages should go. Visual Studio will provide a default value of $(SolutionDir) but command-line based
package restores could end up in a different location. Setting this value keeps Visual Studio and NuGet.exe
in sync for packages.config based restores.
-->
<add key="repositoryPath" value=".\packages" />
</config>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<clear />
<add key="Project.Reunion.nuget.internal" value="https://pkgs.dev.azure.com/microsoft/ProjectReunion/_packaging/Project.Reunion.nuget.internal/nuget/v3/index.json" />
</packageSources>
<disabledPackageSources>
<clear />
</disabledPackageSources>
</configuration>
40 changes: 40 additions & 0 deletions build/scripts/ConvertVersionDetailsToPackageConfig.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Param(
[Parameter(Position=0)]
[string]$versionDetailsPath = "",
[Parameter(Position=1)]
[string]$packageConfigPath = ""
)

[xml]$buildConfig = Get-Content -Path $versionDetailsPath

$packagesText =
@"
<?xml version="1.0" encoding="utf-8"?>
<packages>
<!-- Transport packages from the feeder repositories -->
"@
foreach ($dependency in $buildConfig.Dependencies.ProductDependencies.Dependency)
{
$name = $dependency.name
$ver = $dependency.version
Write-Host "id: " $name
Write-Host "ver: " $ver

if ($name -eq "Microsoft.WindowsAppSDK.AppLicensingInternal.TransportPackage")
{
Write-Host "##vso[task.setvariable variable=AppLicensingInternalPackageName;]$name"
Write-Host "##vso[task.setvariable variable=AppLicensingInternalPackageVersion;]$ver"
}

$packagesText += ' <package id="' + $name + '" version="' + $ver + '" targetFramework="native" />
'
}
$packagesText +=
@"
</packages>
"@

Write-Host $packagesText

Set-Content -Value $packagesText $packageConfigPath
59 changes: 53 additions & 6 deletions dev/Deployment/DeploymentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <TerminalVelocityFeatures-DeploymentAPI.h>
#include <Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentManager.g.cpp>

#include "WindowsAppRuntime-License.h"

namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation
{

Expand Down Expand Up @@ -107,7 +109,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
}

std::wstring frameworkPackageFullName{ packageFullName };
auto deployPackagesResult{ DeployPackages(frameworkPackageFullName) };
auto deployPackagesResult{ Deploy(frameworkPackageFullName) };
DeploymentStatus status{};
if (SUCCEEDED(deployPackagesResult))
{
Expand Down Expand Up @@ -215,23 +217,68 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
CATCH_RETURN()

// Deploys all of the packages carried by the specified framework.
HRESULT DeploymentManager::DeployPackages(const std::wstring& frameworkPackageFullName) try
HRESULT DeploymentManager::Deploy(const std::wstring& frameworkPackageFullName) try
{
RETURN_IF_FAILED(InstallLicenses(frameworkPackageFullName));
RETURN_IF_FAILED(DeployPackages(frameworkPackageFullName));
return S_OK;
}
CATCH_RETURN()

HRESULT DeploymentManager::InstallLicenses(const std::wstring& frameworkPackageFullName)
{
// Build path for licenses
auto licensePath{ std::filesystem::path(GetPackagePath(frameworkPackageFullName)) };
licensePath /= WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER;
auto licenseFilespec{ licensePath };
licenseFilespec /= L"*_license.xml";

// Deploy the licenses (if any)
::Microsoft::Windows::ApplicationModel::Licensing::Installer licenseInstaller;
WIN32_FIND_DATA findFileData{};
wil::unique_hfind hfind{ FindFirstFileW(licenseFilespec.c_str(), &findFileData) };
if (!hfind)
{
const auto lastError{ GetLastError() };
RETURN_HR_IF_MSG(HRESULT_FROM_WIN32(lastError), (lastError != ERROR_FILE_NOT_FOUND) && (lastError != ERROR_PATH_NOT_FOUND),
"FindFirstFile:%ls", licenseFilespec.c_str());
return S_OK;
}
for (;;)
{
// Install the license file
auto licenseFilename{ licensePath };
licenseFilename /= findFileData.cFileName;
RETURN_IF_FAILED_MSG(licenseInstaller.InstallLicenseFile(licenseFilename.c_str()),
"LicenseFile:%ls", licenseFilename.c_str());

// Next! (if any)
if (!FindNextFileW(hfind.get(), &findFileData))
{
const auto lastError{ GetLastError() };
RETURN_HR_IF(HRESULT_FROM_WIN32(lastError), lastError != ERROR_NO_MORE_FILES);
break;
}
}
return S_OK;
}

HRESULT DeploymentManager::DeployPackages(const std::wstring& frameworkPackageFullName)
{
auto frameworkPath = std::filesystem::path(GetPackagePath(frameworkPackageFullName));
const auto frameworkPath{ std::filesystem::path(GetPackagePath(frameworkPackageFullName)) };
for (const auto& package : c_targetPackages)
{
// Build path for the packages.
auto packagePath{ frameworkPath };
packagePath /= WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER;
packagePath /= package.identifier + WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FILE_EXTENSION;

// Deploy package.
RETURN_IF_FAILED(AddPackage(packagePath));
}

return S_OK;
}
CATCH_RETURN()

hstring DeploymentManager::GetCurrentFrameworkPackageFullName()
{
Expand Down Expand Up @@ -276,7 +323,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
continue;
}
}

return hstring(currentPackageInfo.Package(i).packageFullName);
}

Expand Down
2 changes: 2 additions & 0 deletions dev/Deployment/DeploymentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
static HRESULT VerifyPackage(const std::wstring& packageFamilyName, const PACKAGE_VERSION targetVersion);
static std::wstring GetPackagePath(std::wstring const& packageFullName);
static HRESULT AddPackage(const std::filesystem::path& packagePath);
static HRESULT Deploy(const std::wstring& frameworkPackageFullName);
static HRESULT DeployPackages(const std::wstring& frameworkPackageFullName);
static HRESULT InstallLicenses(const std::wstring& frameworkPackageFullName);
static hstring GetCurrentFrameworkPackageFullName();
};
}
Expand Down
4 changes: 2 additions & 2 deletions dev/Deployment/PackageDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
};

// All supported SubTypeNames.
static PackageIdentifier c_subTypeNames[] =
static const PackageIdentifier c_subTypeNames[] =
{
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_MAINPREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_MAIN, PackageVersionType::Versioned },
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_PREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_SINGLETON, PackageVersionType::Unversioned },
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_DDLMPREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_DDLM, PackageVersionType::Framework },
};

// All packages that the DeploymentAPI will attempt check and deploy from the framework.
static PackageIdentifier c_targetPackages[] =
static const PackageIdentifier c_targetPackages[] =
{
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_MAINPREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_MAIN, PackageVersionType::Versioned },
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_PREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_SINGLETON, PackageVersionType::Unversioned },
Expand Down
27 changes: 27 additions & 0 deletions dev/Licensing/Licensing.vcxitems
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<ItemsProjectGuid>{885A43FA-052D-4b0d-A2DC-13EE15796435}</ItemsProjectGuid>
<ItemsProjectName>Licensing</ItemsProjectName>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories);$(MSBuildThisFileDirectory)</AdditionalIncludeDirectories>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectCapability Include="SourceItemsFromImports" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)WindowsAppRuntime-License.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)MsixLicensing.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)MsixLicensing.cpp" />
</ItemGroup>
<ItemGroup>
<PublicHeaders Include="$(MSBuildThisFileDirectory)MsixLicensing.h" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions dev/Licensing/MsixLicensing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.

#include "pch.h"

#include "msixlicensing.h"

#include <WindowsAppRuntime-License.h>

STDAPI MsixInstallLicenses() noexcept try
{
//TODO
// FOREACH file IN pkgdir\MSIX\*_license.xml
// InstallLicenseFile(file)
return S_OK;
}
CATCH_RETURN();
8 changes: 8 additions & 0 deletions dev/Licensing/MsixLicensing.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.

#ifndef __MSIXLICENSING_H
#define __MSIXLICENSING_H

STDAPI MsixInstallLicenses() noexcept;

#endif // __MSIXLICENSING_H
Loading

0 comments on commit 6df1822

Please sign in to comment.