-
Notifications
You must be signed in to change notification settings - Fork 565
[dotnet] Fix support for startup hooks. Fixes #24492. #24664
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
tests/dotnet/StartupHookLibrary/MacCatalyst/StartupHookLibrary.csproj
This file contains hidden or 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,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-maccatalyst</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> | ||
|
|
This file contains hidden or 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 @@ | ||
| using System; | ||
|
|
||
| using Foundation; | ||
|
|
||
|
|
||
| class StartupHook { | ||
| public static void Initialize () | ||
| { | ||
| Console.WriteLine ("STARTUP"); | ||
|
|
||
| StartupStatus.Initialized = true; | ||
| } | ||
| } | ||
|
|
||
| public static class StartupStatus { | ||
| public static bool Initialized { get; internal set; } | ||
| } |
8 changes: 8 additions & 0 deletions
8
tests/dotnet/StartupHookLibrary/iOS/StartupHookLibrary.csproj
This file contains hidden or 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,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-ios</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> | ||
|
|
8 changes: 8 additions & 0 deletions
8
tests/dotnet/StartupHookLibrary/macOS/StartupHookLibrary.csproj
This file contains hidden or 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,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-macos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> | ||
|
|
This file contains hidden or 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,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project> | ||
| <ItemGroup> | ||
| <Compile Include="../*.cs" /> | ||
| </ItemGroup> | ||
| </Project> |
8 changes: 8 additions & 0 deletions
8
tests/dotnet/StartupHookLibrary/tvOS/StartupHookLibrary.csproj
This file contains hidden or 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,8 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-tvos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> | ||
|
|
This file contains hidden or 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,35 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| using Foundation; | ||
|
|
||
| namespace MySimpleApp { | ||
| public class Program { | ||
| static int Main (string [] args) | ||
| { | ||
| GC.KeepAlive (typeof (NSObject)); // prevent linking away the platform assembly | ||
|
|
||
| Console.WriteLine (Environment.GetEnvironmentVariable ("MAGIC_WORD")); | ||
| Console.WriteLine ($"Startup.Initialized: {StartupHook.Initialized}"); | ||
| Console.WriteLine ($"StartupStatus.Initialized: {StartupStatus.Initialized}"); | ||
|
|
||
| var rv = 0; | ||
|
|
||
| if (!StartupHook.Initialized) | ||
| rv += 1; | ||
|
|
||
| if (!StartupStatus.Initialized) | ||
| rv += 2; | ||
|
|
||
| return rv; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class StartupHook { | ||
|
rolfbjarne marked this conversation as resolved.
|
||
| public static bool Initialized { get; private set; } | ||
| public static void Initialize () | ||
| { | ||
| Initialized = true; | ||
| } | ||
| } | ||
This file contains hidden or 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 @@ | ||
| include ../shared.mk |
7 changes: 7 additions & 0 deletions
7
tests/dotnet/StartupHookTest/MacCatalyst/StartupHookTest.csproj
This file contains hidden or 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,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-maccatalyst</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
This file contains hidden or 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,2 @@ | ||
| TOP=../../.. | ||
| include $(TOP)/tests/common/shared-dotnet-test.mk |
This file contains hidden or 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 @@ | ||
| include ../shared.mk |
This file contains hidden or 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,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-ios</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
This file contains hidden or 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 @@ | ||
| include ../shared.mk |
This file contains hidden or 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,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-macos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
This file contains hidden or 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 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
|
|
||
| <ApplicationTitle>StartupHookTest</ApplicationTitle> | ||
| <ApplicationId>com.xamarin.startuphooktest</ApplicationId> | ||
| </PropertyGroup> | ||
|
|
||
| <Import Project="../../common/shared-dotnet.csproj" /> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="../*.cs" /> | ||
|
|
||
| <ProjectReference Include="../../StartupHookLibrary/$(_PlatformName)/StartupHookLibrary.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or 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,3 @@ | ||
| TOP=../../../.. | ||
| TESTNAME=StartupHookTest | ||
| include $(TOP)/tests/common/shared-dotnet.mk |
This file contains hidden or 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 @@ | ||
| include ../shared.mk |
This file contains hidden or 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,7 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-tvos</TargetFramework> | ||
| </PropertyGroup> | ||
| <Import Project="..\shared.csproj" /> | ||
| </Project> |
This file contains hidden or 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,114 @@ | ||
| #nullable enable | ||
|
|
||
| namespace Xamarin.Tests { | ||
| [TestFixture] | ||
| public class StartupHookTest : TestBaseClass { | ||
| const string project = "StartupHookTest"; | ||
|
|
||
| [TestCase (ApplePlatform.MacOSX, "osx-arm64")] | ||
| [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")] | ||
| public void EnabledForDebug (ApplePlatform platform, string runtimeIdentifiers) | ||
| { | ||
| Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
|
||
| var configuration = "Debug"; | ||
| var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath, configuration: configuration); | ||
| Clean (project_path); | ||
|
|
||
| var properties = GetDefaultProperties (runtimeIdentifiers); | ||
| properties ["Configuration"] = configuration; | ||
| DotNet.AssertBuild (project_path, properties); | ||
|
|
||
| if (CanExecute (platform, properties)) { | ||
| var appExecutable = GetNativeExecutable (platform, appPath); | ||
| var env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookTest:StartupHookLibrary" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env); | ||
|
|
||
| env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookLibrary" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 1); // this should fail | ||
|
|
||
| env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookTest" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 2); // this should fail | ||
| } | ||
| } | ||
|
|
||
| [TestCase (ApplePlatform.MacOSX, "osx-arm64")] | ||
| [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")] | ||
| public void DisabledForRelease (ApplePlatform platform, string runtimeIdentifiers) | ||
| { | ||
| Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
|
||
| var configuration = "Release"; | ||
| var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath, configuration: configuration); | ||
| Clean (project_path); | ||
|
|
||
| var properties = GetDefaultProperties (runtimeIdentifiers); | ||
| properties ["Configuration"] = configuration; | ||
| DotNet.AssertBuild (project_path, properties); | ||
|
|
||
| if (CanExecute (platform, properties)) { | ||
| var appExecutable = GetNativeExecutable (platform, appPath); | ||
| var env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookTest:StartupHookLibrary" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 3); // this should fail | ||
|
|
||
| env = new Dictionary<string, string?> (); | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 3); // this should fail | ||
|
|
||
| env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookLibrary" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 3); // this should fail | ||
|
|
||
| env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookTest" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 3); // this should fail | ||
| } | ||
| } | ||
|
|
||
| [TestCase (ApplePlatform.MacOSX, "osx-arm64")] | ||
| [TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64")] | ||
| public void Enableable (ApplePlatform platform, string runtimeIdentifiers) | ||
| { | ||
| Configuration.IgnoreIfIgnoredPlatform (platform); | ||
|
|
||
| var configuration = "Release"; | ||
| var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath, configuration: configuration); | ||
| Clean (project_path); | ||
|
|
||
| var properties = GetDefaultProperties (runtimeIdentifiers); | ||
| properties ["Configuration"] = configuration; | ||
| properties ["StartupHookSupport"] = "true"; | ||
| DotNet.AssertBuild (project_path, properties); | ||
|
|
||
| if (CanExecute (platform, properties)) { | ||
| var appExecutable = GetNativeExecutable (platform, appPath); | ||
| var env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookTest:StartupHookLibrary" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env); // this should work | ||
|
|
||
| env = new Dictionary<string, string?> (); | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 3); // this should fail | ||
|
|
||
| env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookLibrary" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 1); // this should fail | ||
|
rolfbjarne marked this conversation as resolved.
|
||
|
|
||
| env = new Dictionary<string, string?> { | ||
| { "DOTNET_STARTUP_HOOKS", "StartupHookTest" }, | ||
| }; | ||
| ExecuteWithMagicWordAndAssert (appExecutable, env, expectedExitCode: 2); // this should fail | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Android I also had this in a block for "applications" (that have OutputType=Exe or AndroidApplication=true).
It may not matter, though.