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

try to use invoking .net runtime instead of looking it up from path #413

Merged
merged 5 commits into from
Oct 25, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Runner.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ private static async Task<int> CreateRunner(string binpath, Parameters parameter
Console.WriteLine(e.Data);
};
#if !OS_LINUX && !OS_WINDOWS && !OS_OSX && !X64 && !X86 && !ARM && !ARM64
var dotnet = WhichUtil.Which("dotnet", true);
var dotnet = Sdk.Utils.DotNetMuxer.MuxerPath ?? WhichUtil.Which("dotnet", true);
string ext = ".dll";
#else
string ext = IOUtil.ExeExtension;
Expand Down Expand Up @@ -497,7 +497,7 @@ private static async Task<int> CreateExternalRunner(string binpath, Parameters p
// Use embedded runner to configure external github agent, otherwise only port 80 or 443 are possible to use for configuration
#if !OS_LINUX && !OS_WINDOWS && !OS_OSX && !X64 && !X86 && !ARM && !ARM64
arguments = $"\"{Path.Join(binpath, "Runner.Listener.dll")}\" {arguments}";
file = WhichUtil.Which("dotnet", true);
file = Sdk.Utils.DotNetMuxer.MuxerPath ?? WhichUtil.Which("dotnet", true);
#else
file = Path.Join(binpath, $"Runner.Listener{ext}");
#endif
Expand Down Expand Up @@ -535,7 +535,7 @@ private static async Task<int> CreateExternalRunner(string binpath, Parameters p
if(!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) {
#if !OS_LINUX && !OS_WINDOWS && !OS_OSX && !X64 && !X86 && !ARM && !ARM64
arguments = $"\"{Path.Join(binpath, "Runner.Client.dll")}\" spawn \"{file}\" {arguments}";
file = WhichUtil.Which("dotnet", true);
file = Sdk.Utils.DotNetMuxer.MuxerPath ?? WhichUtil.Which("dotnet", true);
#else
arguments = $"spawn \"{file}\" {arguments}";
file = Path.Join(binpath, $"Runner.Client{ext}");
Expand Down Expand Up @@ -1293,7 +1293,7 @@ static int Main(string[] args)
invoker.ErrorDataReceived += _out;
}
#if !OS_LINUX && !OS_WINDOWS && !OS_OSX && !X64 && !X86 && !ARM && !ARM64
var dotnet = WhichUtil.Which("dotnet", true);
var dotnet = Sdk.Utils.DotNetMuxer.MuxerPath ?? WhichUtil.Which("dotnet", true);
string ext = ".dll";
#else
string ext = IOUtil.ExeExtension;
Expand Down
2 changes: 2 additions & 0 deletions src/Runner.Language.Server/Runner.Language.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
</PropertyGroup>
<PropertyGroup Condition="'$(WASM)' != '1'">
<OutputType>Exe</OutputType>
<!-- See https://github.com/dotnet/sdk/issues/18116#issuecomment-855266314 -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Runner.Listener/JobDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ private async Task RunAsync(Pipelines.AgentJobRequestMessage message, string orc
string workerFileName = Path.Combine(assemblyDirectory, $"{_workerProcessName}{ext}");
string arguments = "spawnclient " + pipeHandleOut + " " + pipeHandleIn;
#if !OS_LINUX && !OS_WINDOWS && !OS_OSX && !X64 && !X86 && !ARM && !ARM64
var dotnet = WhichUtil.Which("dotnet", true);
var dotnet = global::Sdk.Utils.DotNetMuxer.MuxerPath ?? WhichUtil.Which("dotnet", true);
arguments = $"\"{workerFileName}\" {arguments}";
workerFileName = dotnet;
#endif
Expand Down
8 changes: 8 additions & 0 deletions src/Runner.Sdk/Util/IOUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,5 +558,13 @@ private static void RemoveReadOnly(FileSystemInfo item)
item.Attributes = item.Attributes & ~FileAttributes.ReadOnly;
}
}

public static string GetDotnet() {
var procPath = Environment.ProcessPath;
if(Path.GetFileNameWithoutExtension(procPath) == "dotnet" && Path.GetExtension(procPath) == ExeExtension) {
return procPath;
}
return WhichUtil.Which("dotnet", true);
}
}
}
2 changes: 1 addition & 1 deletion src/Runner.Worker/RunnerPluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public async Task RunPluginActionAsync(IExecutionContext context, string plugin,
string arguments = $"action \"{plugin}\"";

#if !OS_LINUX && !OS_WINDOWS && !OS_OSX && !X64 && !X86 && !ARM && !ARM64
var dotnet = WhichUtil.Which("dotnet", true);
var dotnet = global::Sdk.Utils.DotNetMuxer.MuxerPath ?? WhichUtil.Which("dotnet", true);
arguments = $"\"{file}\" {arguments}";
file = dotnet;
#endif
Expand Down
73 changes: 73 additions & 0 deletions src/Sdk/Utils/DotNetMuxer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// System.AppContext.GetData is not available in these frameworks

/// https://github.com/dotnet/aspnetcore/blob/main/src/Shared/CommandLineUtils/Utilities/DotNetMuxer.cs

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Sdk.Utils
{
/// <summary>
/// Utilities for finding the "dotnet.exe" file from the currently running .NET Core application
/// </summary>
public static class DotNetMuxer
{
private const string MuxerName = "dotnet";

static DotNetMuxer()
{
MuxerPath = TryFindMuxerPath();
}

/// <summary>
/// The full filepath to the .NET Core muxer.
/// </summary>
public static string? MuxerPath { get; }

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / package

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / package

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x86, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x86, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 32 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

/// <summary>
/// Finds the full filepath to the .NET Core muxer,
/// or returns a string containing the default name of the .NET Core muxer ('dotnet').
/// </summary>
/// <returns>The path or a string named 'dotnet'.</returns>
public static string MuxerPathOrDefault()
=> MuxerPath ?? MuxerName;

private static string? TryFindMuxerPath()

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / package

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (linux-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x86, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-x64, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-x86, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / deploy

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / CodeQL-Build

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (win-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (osx-arm64, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm, false)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 42 in src/Sdk/Utils/DotNetMuxer.cs

View workflow job for this annotation

GitHub Actions / build (alpine-arm, true)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var expectedFileName = MuxerName;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
expectedFileName += ".exe";
}

// If the currently running process is dotnet(.exe), return that path
var mainModuleFullPath = Process.GetCurrentProcess().MainModule?.FileName;
var mainModuleFileName = Path.GetFileName(mainModuleFullPath);
if (string.Equals(expectedFileName, mainModuleFileName, StringComparison.OrdinalIgnoreCase))
{
return mainModuleFullPath;
}

// The currently running process may not be dotnet(.exe). For example,
// it might be "testhost(.exe)" when running tests.
// In this case, we can get the location where the CLR is installed,
// and find dotnet(.exe) relative to that path.
var runtimeDirectory = RuntimeEnvironment.GetRuntimeDirectory();
var candidateDotNetExePath = Path.Combine(runtimeDirectory, "..", "..", "..", expectedFileName);
if (File.Exists(candidateDotNetExePath))
{
var normalizedPath = Path.GetFullPath(candidateDotNetExePath);
return normalizedPath;
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion src/runner-server-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
]
},
"scripts": {
"build": "dotnet publish ../Runner.Language.Server --no-self-contained -p:BUILD_OS=Any -p:RuntimeFrameworkVersion=6.0.0 --output native"
"build": "dotnet publish ../Runner.Language.Server --no-self-contained -p:UseAppHost=false -p:BUILD_OS=Any -p:RuntimeFrameworkVersion=6.0.0 --output native"
},
"devDependencies": {
"@types/vscode": "^1.73.0",
Expand Down
11 changes: 11 additions & 0 deletions src/runner-server-web-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
"activationEvents": [
"onLanguage:yaml"
],
"contributes": {
"semanticTokenScopes": [
{
"scopes": {
"constant.defaultLibrary": ["constant.language"],
"constant.numeric": ["constant.numeric"],
"punctuation": ["meta.embedded"]
}
}
]
},
"browser": "./client/dist/browserClientMain",
"scripts": {
"vscode:prepublish": "npm run build",
Expand Down
Loading