Skip to content

Commit

Permalink
[net9.0] Merge main into net9.0 (#23890)
Browse files Browse the repository at this point in the history
### Description of Change

Merge main into net9.0
  • Loading branch information
rmarinho authored Jul 31, 2024
2 parents be906a1 + 88d8357 commit 9f28ecd
Show file tree
Hide file tree
Showing 298 changed files with 152 additions and 39 deletions.
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<IncludeSymbols>true</IncludeSymbols>
</PropertyGroup>

<PropertyGroup>
<NuGetAuditMode>all</NuGetAuditMode>
<NuGetAuditLevel>moderate</NuGetAuditLevel>
</PropertyGroup>

<PropertyGroup>
<_MauiDotNetVersionMajor Condition="'$(_MauiDotNetVersionMajor)' == ''">9</_MauiDotNetVersionMajor>
<_MauiDotNetVersionMinor Condition="'$(_MauiDotNetVersionMinor)' == ''">0</_MauiDotNetVersionMinor>
Expand Down
4 changes: 2 additions & 2 deletions eng/common/sdl/NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</solution>
<packageSources>
<clear />
<add key="guardian" value="https://securitytools.pkgs.visualstudio.com/_packaging/Guardian/nuget/v3/index.json" />
<add key="guardian" value="https://pkgs.dev.azure.com/dnceng/_packaging/Guardian1ESPTUpstreamOrgFeed/nuget/v3/index.json" />
</packageSources>
<packageSourceMapping>
<packageSource key="guardian">
<package pattern="microsoft.guardian.cli" />
<package pattern="Microsoft.Guardian.Cli.win-x64" />
</packageSource>
</packageSourceMapping>
<disabledPackageSources>
Expand Down
4 changes: 1 addition & 3 deletions eng/common/sdl/execute-all-sdl-tools.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Param(
[string] $BranchName=$env:BUILD_SOURCEBRANCH, # Optional: name of branch or version of gdn settings; defaults to master
[string] $SourceDirectory=$env:BUILD_SOURCESDIRECTORY, # Required: the directory where source files are located
[string] $ArtifactsDirectory = (Join-Path $env:BUILD_ARTIFACTSTAGINGDIRECTORY ('artifacts')), # Required: the directory where build artifacts are located
[string] $AzureDevOpsAccessToken, # Required: access token for dnceng; should be provided via KeyVault

# Optional: list of SDL tools to run on source code. See 'configure-sdl-tool.ps1' for tools list
# format.
Expand Down Expand Up @@ -75,7 +74,7 @@ try {
}

Exec-BlockVerbosely {
& $(Join-Path $PSScriptRoot 'init-sdl.ps1') -GuardianCliLocation $guardianCliLocation -Repository $RepoName -BranchName $BranchName -WorkingDirectory $workingDirectory -AzureDevOpsAccessToken $AzureDevOpsAccessToken -GuardianLoggerLevel $GuardianLoggerLevel
& $(Join-Path $PSScriptRoot 'init-sdl.ps1') -GuardianCliLocation $guardianCliLocation -Repository $RepoName -BranchName $BranchName -WorkingDirectory $workingDirectory -GuardianLoggerLevel $GuardianLoggerLevel
}
$gdnFolder = Join-Path $workingDirectory '.gdn'

Expand Down Expand Up @@ -104,7 +103,6 @@ try {
-TargetDirectory $targetDirectory `
-GdnFolder $gdnFolder `
-ToolsList $tools `
-AzureDevOpsAccessToken $AzureDevOpsAccessToken `
-GuardianLoggerLevel $GuardianLoggerLevel `
-CrScanAdditionalRunConfigParams $CrScanAdditionalRunConfigParams `
-PoliCheckAdditionalRunConfigParams $PoliCheckAdditionalRunConfigParams `
Expand Down
8 changes: 0 additions & 8 deletions eng/common/sdl/init-sdl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Param(
[string] $Repository,
[string] $BranchName='master',
[string] $WorkingDirectory,
[string] $AzureDevOpsAccessToken,
[string] $GuardianLoggerLevel='Standard'
)

Expand All @@ -21,14 +20,7 @@ $ci = $true
# Don't display the console progress UI - it's a huge perf hit
$ProgressPreference = 'SilentlyContinue'

# Construct basic auth from AzDO access token; construct URI to the repository's gdn folder stored in that repository; construct location of zip file
$encodedPat = [Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$AzureDevOpsAccessToken"))
$escapedRepository = [Uri]::EscapeDataString("/$Repository/$BranchName/.gdn")
$uri = "https://dev.azure.com/dnceng/internal/_apis/git/repositories/sdl-tool-cfg/Items?path=$escapedRepository&versionDescriptor[versionOptions]=0&`$format=zip&api-version=5.0"
$zipFile = "$WorkingDirectory/gdn.zip"

Add-Type -AssemblyName System.IO.Compression.FileSystem
$gdnFolder = (Join-Path $WorkingDirectory '.gdn')

try {
# if the folder does not exist, we'll do a guardian init and push it to the remote repository
Expand Down
4 changes: 3 additions & 1 deletion eng/common/sdl/sdl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ function Install-Gdn {
[Parameter(Mandatory=$true)]
[string]$Path,

[string]$Source = "https://pkgs.dev.azure.com/dnceng/_packaging/Guardian1ESPTUpstreamOrgFeed/nuget/v3/index.json",

# If omitted, install the latest version of Guardian, otherwise install that specific version.
[string]$Version
)
Expand All @@ -19,7 +21,7 @@ function Install-Gdn {
$ci = $true
. $PSScriptRoot\..\tools.ps1

$argumentList = @("install", "Microsoft.Guardian.Cli", "-Source https://securitytools.pkgs.visualstudio.com/_packaging/Guardian/nuget/v3/index.json", "-OutputDirectory $Path", "-NonInteractive", "-NoCache")
$argumentList = @("install", "Microsoft.Guardian.Cli.win-x64", "-Source $Source", "-OutputDirectory $Path", "-NonInteractive", "-NoCache")

if ($Version) {
$argumentList += "-Version $Version"
Expand Down
20 changes: 16 additions & 4 deletions eng/pipelines/common/ui-tests-build-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,25 @@ steps:
continueOnError: true
- publish: $(System.DefaultWorkingDirectory)/artifacts/bin
condition: and(ne('${{ parameters.platform }}' , 'windows'), ne('${{ parameters.runtimeVariant }}' , 'NativeAOT'))
condition: and(ne('${{ parameters.platform }}' , 'windows'), ne('${{ parameters.runtimeVariant }}' , 'NativeAOT'), succeeded())
artifact: ui-tests-samples

- publish: $(System.DefaultWorkingDirectory)/artifacts/bin
condition: and(ne('${{ parameters.platform }}' , 'windows'), eq('${{ parameters.runtimeVariant }}' , 'NativeAOT'))
condition: and(ne('${{ parameters.platform }}' , 'windows'), eq('${{ parameters.runtimeVariant }}' , 'NativeAOT'), succeeded())
artifact: ui-tests-samples-nativeaot

- publish: $(System.DefaultWorkingDirectory)/artifacts/bin
condition: eq('${{ parameters.platform }}' , 'windows')
artifact: ui-tests-samples-windows
condition: and(eq('${{ parameters.platform }}' , 'windows'), succeeded())
artifact: ui-tests-samples-windows

- publish: $(System.DefaultWorkingDirectory)/artifacts/bin
condition: and(ne('${{ parameters.platform }}' , 'windows'), ne('${{ parameters.runtimeVariant }}' , 'NativeAOT'), failed())
artifact: ui-tests-samples_failed_$(System.JobAttempt)

- publish: $(System.DefaultWorkingDirectory)/artifacts/bin
condition: and(ne('${{ parameters.platform }}' , 'windows'), eq('${{ parameters.runtimeVariant }}' , 'NativeAOT'), failed())
artifact: ui-tests-samples-nativeaot_failed_$(System.JobAttempt)

- publish: $(System.DefaultWorkingDirectory)/artifacts/bin
condition: and(eq('${{ parameters.platform }}' , 'windows'), failed())
artifact: ui-tests-samples-windows_failed_$(System.JobAttempt)
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ internal class AndroidWebKitWebViewManager : WebViewManager
// Using an IP address means that WebView doesn't wait for any DNS resolution,
// making it substantially faster. Note that this isn't real HTTP traffic, since
// we intercept all the requests within this origin.
private static readonly string AppOrigin = $"https://{BlazorWebView.AppHostAddress}/";
private static readonly Uri AppOriginUri = new(AppOrigin);
private static readonly AUri AndroidAppOriginUri = AUri.Parse(AppOrigin)!;
private static string AppOrigin { get; } = $"https://{BlazorWebView.AppHostAddress}/";
private static Uri AppOriginUri { get; } = new(AppOrigin);
private static AUri AndroidAppOriginUri { get; } = AUri.Parse(AppOrigin)!;
private readonly ILogger _logger;
private readonly AWebView _webview;
private readonly string _contentRootRelativeToAppRoot;
Expand Down
39 changes: 38 additions & 1 deletion src/BlazorWebView/src/Maui/BlazorWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,44 @@ namespace Microsoft.AspNetCore.Components.WebView.Maui
/// </summary>
public partial class BlazorWebView : View, IBlazorWebView
{
internal const string AppHostAddress = "0.0.0.0";
internal static string AppHostAddress { get; } = GetAppHostAddress();

private const string AppHostAddressAlways0000Switch = "BlazorWebView.AppHostAddressAlways0000";

private static bool IsAppHostAddressAlways0000Enabled =>
AppContext.TryGetSwitch(AppHostAddressAlways0000Switch, out var enabled) && enabled;

private static string GetAppHostAddress()
{
if (IsAppHostAddressAlways0000Enabled)
{
return "0.0.0.0";
}
else
{
#if IOS || MACCATALYST
// On iOS/MacCatalyst 18 and higher the 0.0.0.0 address does not work, so we use localhost instead.
// This preserves behavior on older versions of those systems, while defaulting to new behavior on
// the new system.

// Note that pre-release versions of iOS/MacCatalyst have the expected Major/Minor values,
// but the Build, MajorRevision, MinorRevision, and Revision values are all -1, so we need
// to pass in int.MinValue for those values.

if (System.OperatingSystem.IsIOSVersionAtLeast(major: 18, minor: int.MinValue, build: int.MinValue) ||
System.OperatingSystem.IsMacCatalystVersionAtLeast(major: 18, minor: int.MinValue, build: int.MinValue))
{
return "localhost";
}
else
{
return "0.0.0.0";
}
#else
return "0.0.0.0";
#endif
}
}

private readonly JSComponentConfigurationStore _jSComponents = new();

Expand Down
4 changes: 2 additions & 2 deletions src/BlazorWebView/src/Maui/iOS/BlazorWebViewHandler.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public partial class BlazorWebViewHandler : ViewHandler<IBlazorWebView, WKWebVie
{
private IOSWebViewManager? _webviewManager;

internal const string AppOrigin = "app://" + BlazorWebView.AppHostAddress + "/";
internal static readonly Uri AppOriginUri = new(AppOrigin);
internal static string AppOrigin { get; } = "app://" + BlazorWebView.AppHostAddress + "/";
internal static Uri AppOriginUri { get; } = new(AppOrigin);
private const string BlazorInitScript = @"
window.__receiveMessageCallbacks = [];
window.__dispatchMessageCallback = function(message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ResourceDictionary>

<Style x:Key="CustomStyle" TargetType="Label" BaseResourceKey="SubtitleStyle">
<Setter Property="Label.TextColor" Value="Color.Pink"/>
<Setter Property="TextColor" Value="Pink"/>
</Style>

<Style x:Key="ButtonStyle" TargetType="Button">
Expand Down
20 changes: 19 additions & 1 deletion src/SingleProject/Resizetizer/src/DpiPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@

namespace Microsoft.Maui.Resizetizer
{
internal enum ClipShape
{
None,
// RoundedSquare,
Circle,
// Squircle
}

internal class DpiPath
{
public DpiPath(string path, decimal scale, string nameSuffix = null, string scaleSuffix = null, SKSize? size = null, string[] idioms = null)
public DpiPath(string path, decimal scale, string nameSuffix = null, string scaleSuffix = null, SKSize? size = null, string[] idioms = null, ClipShape clip = ClipShape.None)
{
Path = path;
Scale = scale;
NameSuffix = nameSuffix;
ScaleSuffix = scaleSuffix;
Size = size;
Idioms = idioms;
ClipShape = clip;
}

public string Path { get; set; }
Expand All @@ -32,6 +41,8 @@ public DpiPath(string path, decimal scale, string nameSuffix = null, string scal

public string[] Idioms { get; set; }

public ClipShape ClipShape { get; set; }

public static class Android
{
public static DpiPath Original =>
Expand All @@ -50,11 +61,18 @@ public static DpiPath[] Image
public static DpiPath[] AppIcon
=> new[]
{
// legacy square
new DpiPath("mipmap-mdpi", 1.0m, size: new SKSize(48, 48)),
new DpiPath("mipmap-hdpi", 1.5m, size: new SKSize(48, 48)),
new DpiPath("mipmap-xhdpi", 2.0m, size: new SKSize(48, 48)),
new DpiPath("mipmap-xxhdpi", 3.0m, size: new SKSize(48, 48)),
new DpiPath("mipmap-xxxhdpi", 4.0m, size: new SKSize(48, 48)),
// legacy round for Android 7
new DpiPath("mipmap-mdpi", 1.0m, "_round", size: new SKSize(48, 48), clip: ClipShape.Circle),
new DpiPath("mipmap-hdpi", 1.5m, "_round", size: new SKSize(48, 48), clip: ClipShape.Circle),
new DpiPath("mipmap-xhdpi", 2.0m, "_round", size: new SKSize(48, 48), clip: ClipShape.Circle),
new DpiPath("mipmap-xxhdpi", 3.0m, "_round", size: new SKSize(48, 48), clip: ClipShape.Circle),
new DpiPath("mipmap-xxxhdpi", 4.0m, "_round", size: new SKSize(48, 48), clip: ClipShape.Circle),
};

public static DpiPath[] AppIconParts
Expand Down
24 changes: 24 additions & 0 deletions src/SingleProject/Resizetizer/src/SkiaSharpAppIconTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ void Draw(SKBitmap tempBitmap, DpiPath dpi, SKSize unscaledCanvasSize)

using var canvas = new SKCanvas(tempBitmap);

if (GetClipPath(dpi, canvasSize, unscaledCanvasSize) is { } clipPath)
{
canvas.Clear(SKColors.Transparent);

canvas.ClipPath(clipPath, antialias: true);
}

canvas.Clear(Info.Color ?? SKColors.Transparent);

// draw background
Expand Down Expand Up @@ -141,5 +148,22 @@ void Draw(SKBitmap tempBitmap, DpiPath dpi, SKSize unscaledCanvasSize)
foregroundTools.DrawUnscaled(canvas, fgScale);
}
}

static SKPath? GetClipPath(DpiPath dpi, SKSize canvasSize, SKSize unscaledCanvasSize)
{
if (dpi.ClipShape == ClipShape.Circle)
{
var radius = Math.Min(canvasSize.Width, canvasSize.Height) / 2;

var clip = new SKPath();
clip.AddCircle(
canvasSize.Width / 2,
canvasSize.Height / 2,
radius);
return clip;
}

return null;
}
}
}
32 changes: 19 additions & 13 deletions src/SingleProject/Resizetizer/test/UnitTests/BaseTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,19 @@ void AssertFileMatchesReal(string actualFilename, object[] args = null, [CallerM

if (!isSimilar)
{
var maskFilename = Path.Combine(DestinationDirectory, expectedFilename);
var root = GetTestProjectRoot();

var maskFilename = Path.Combine(root, "errors", expectedFilename);
maskFilename = Path.ChangeExtension(maskFilename, ".mask.png");

Directory.CreateDirectory(Path.GetDirectoryName(maskFilename));

using var mask = SKPixelComparer.GenerateDifferenceMask(actual, expected);
using var data = mask.Encode(SKEncodedImageFormat.Png, 100);
using var maskFile = File.Create(maskFilename);
data.SaveTo(maskFile);
using (var mask = SKPixelComparer.GenerateDifferenceMask(actual, expected))
using (var data = mask.Encode(SKEncodedImageFormat.Png, 100))
using (var maskFile = File.Create(maskFilename))
{
data.SaveTo(maskFile);
}

Assert.True(
isSimilar,
Expand All @@ -165,14 +169,7 @@ void AssertFileMatchesReal(string actualFilename, object[] args = null, [CallerM

void SaveImageResultFileReal(string destinationFilename, object[] args = null, [CallerMemberName] string methodName = null)
{
var root = Directory.GetCurrentDirectory();
root = Path.GetDirectoryName(root);
root = Path.GetDirectoryName(root);
root = Path.GetDirectoryName(root);
root = Path.GetDirectoryName(root);
root = Path.GetDirectoryName(root);
root = Path.Combine(root, "src/SingleProject/Resizetizer/test/UnitTests/");

var root = GetTestProjectRoot();
var imagePath = GetTestImageFileName(args, methodName, Path.GetExtension(destinationFilename));
var path = Path.Combine(root, imagePath);

Expand Down Expand Up @@ -206,5 +203,14 @@ private string GetTestImageFileName(object[] args, string methodName, string ext

return Path.Combine(TestImagesFolderName, name, methodName, filename);
}

private static string GetTestProjectRoot()
{
var cwd = Directory.GetCurrentDirectory();

var root = Path.Combine(cwd, "../../../../../src/SingleProject/Resizetizer/test/UnitTests/");

return root;
}
}
}
Loading

0 comments on commit 9f28ecd

Please sign in to comment.