diff options
author | Gleb Popov <arrowd@FreeBSD.org> | 2025-02-15 14:16:21 +0300 |
---|---|---|
committer | Gleb Popov <arrowd@FreeBSD.org> | 2025-02-21 21:01:54 +0300 |
commit | 1a37ab5e607402b589579a165afed8cf81ee050b (patch) | |
tree | f3003bcb439cf2cc0c25e381d7035c5e3d5b9408 /shells/powershell/files | |
parent | shells/libpowershell-native: Support library for PowerShell (diff) |
shells/powershell: Microsoft's shell with support for .NET objects
Co-authored-by: Felix Palmen <zirias@FreeBSD.org>
Co-authored-by: Szczepan Ćwikliński <sec@thinkcode.pl>
Diffstat (limited to 'shells/powershell/files')
7 files changed, 170 insertions, 0 deletions
diff --git a/shells/powershell/files/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets b/shells/powershell/files/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets new file mode 100644 index 000000000000..85ece3e539a3 --- /dev/null +++ b/shells/powershell/files/Microsoft.PowerShell.SDK.csproj.TypeCatalog.targets @@ -0,0 +1,9 @@ +<Project> + <Target Name="_GetDependencies" + DependsOnTargets="ResolveAssemblyReferencesDesignTime"> + <ItemGroup> + <_RefAssemblyPath Include="%(_ReferencesFromRAR.HintPath)%3B" Condition=" '%(_ReferencesFromRAR.NuGetPackageId)' != 'Microsoft.Management.Infrastructure' "/> + </ItemGroup> + <WriteLinesToFile File="$(_DependencyFile)" Lines="@(_RefAssemblyPath)" Overwrite="true" /> + </Target> +</Project> diff --git a/shells/powershell/files/patch-PowerShell.Common.props b/shells/powershell/files/patch-PowerShell.Common.props new file mode 100644 index 000000000000..d532c59d2f9d --- /dev/null +++ b/shells/powershell/files/patch-PowerShell.Common.props @@ -0,0 +1,19 @@ +--- PowerShell.Common.props.orig 2024-04-11 18:38:22 UTC ++++ PowerShell.Common.props +@@ -15,12 +15,10 @@ + BeforeTargets="_GenerateRestoreProjectSpec;GenerateNuspec;BeforeBuild" + > + +- <Exec Command='git describe --abbrev=60 --long' +- WorkingDirectory="$(MSBuildProjectDirectory)" +- ConsoleToMSBuild="true" +- StandardOutputImportance="Low"> +- <Output TaskParameter="ConsoleOutput" PropertyName="PowerShellVersion" /> +- </Exec> ++ <PropertyGroup> ++ <PowerShellVersion>7.5.0</PowerShellVersion> ++ <ReleaseTag>7.5.0</ReleaseTag> ++ </PropertyGroup> + + <PropertyGroup Condition = "'$(ReleaseTag)' != ''"> + <!-- diff --git a/shells/powershell/files/patch-nuget.config b/shells/powershell/files/patch-nuget.config new file mode 100644 index 000000000000..fa4c90932f5c --- /dev/null +++ b/shells/powershell/files/patch-nuget.config @@ -0,0 +1,15 @@ +diff --git a/nuget.config.orig b/nuget.config +index 388a65572dd1..7a6c69b95096 100644 +--- nuget.config.orig ++++ nuget.config +@@ -2,7 +2,9 @@ + <configuration> + <packageSources> + <clear /> +- <add key="powershell" value="https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/PowerShell/nuget/v3/index.json" /> ++ <add key="a" value="%%LOCALBASE%%/share/dotnet/library-packs" /> ++ <add key="b" value="%%LOCALBASE%%/share/dotnet/packs" /> ++ <add key="c" value="%%NUGET_DISTDIR%%" /> + </packageSources> + <disabledPackageSources> + <clear /> diff --git a/shells/powershell/files/patch-src_ResGen_ResGen.csproj b/shells/powershell/files/patch-src_ResGen_ResGen.csproj new file mode 100644 index 000000000000..23a3265355f9 --- /dev/null +++ b/shells/powershell/files/patch-src_ResGen_ResGen.csproj @@ -0,0 +1,11 @@ +--- src/ResGen/ResGen.csproj.orig 2024-01-11 22:25:54 UTC ++++ src/ResGen/ResGen.csproj +@@ -7,7 +7,7 @@ + <OutputType>Exe</OutputType> + <TieredCompilation>true</TieredCompilation> + <TieredCompilationQuickJit>true</TieredCompilationQuickJit> +- <RuntimeIdentifiers>win-x86;win-x64;osx-x64;linux-x64</RuntimeIdentifiers> ++ <RuntimeIdentifiers>$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifiers> + </PropertyGroup> + + </Project> diff --git a/shells/powershell/files/patch-src_TypeCatalogGen_TypeCatalogGen.csproj b/shells/powershell/files/patch-src_TypeCatalogGen_TypeCatalogGen.csproj new file mode 100644 index 000000000000..b64a0ead0bac --- /dev/null +++ b/shells/powershell/files/patch-src_TypeCatalogGen_TypeCatalogGen.csproj @@ -0,0 +1,11 @@ +--- src/TypeCatalogGen/TypeCatalogGen.csproj.orig 2024-01-11 22:25:54 UTC ++++ src/TypeCatalogGen/TypeCatalogGen.csproj +@@ -8,7 +8,7 @@ + <OutputType>Exe</OutputType> + <TieredCompilation>true</TieredCompilation> + <TieredCompilationQuickJit>true</TieredCompilationQuickJit> +- <RuntimeIdentifiers>win-x86;win-x64;osx-x64;linux-x64</RuntimeIdentifiers> ++ <RuntimeIdentifiers>$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifiers> + </PropertyGroup> + + </Project> diff --git a/shells/powershell/files/patch-src_powershell-unix_powershell-unix.csproj b/shells/powershell/files/patch-src_powershell-unix_powershell-unix.csproj new file mode 100644 index 000000000000..0b50eaadd765 --- /dev/null +++ b/shells/powershell/files/patch-src_powershell-unix_powershell-unix.csproj @@ -0,0 +1,11 @@ +--- src/powershell-unix/powershell-unix.csproj.orig 2024-04-11 18:38:22 UTC ++++ src/powershell-unix/powershell-unix.csproj +@@ -9,7 +9,7 @@ + <TieredCompilation>true</TieredCompilation> + <TieredCompilationQuickJit>true</TieredCompilationQuickJit> + <TieredCompilationQuickJitForLoops>true</TieredCompilationQuickJitForLoops> +- <RuntimeIdentifiers>linux-x64;osx-x64;</RuntimeIdentifiers> ++ <RuntimeIdentifiers>$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifiers> + </PropertyGroup> + + <ItemGroup> diff --git a/shells/powershell/files/patch-src_powershell_Program.cs b/shells/powershell/files/patch-src_powershell_Program.cs new file mode 100644 index 000000000000..ec1585be12ca --- /dev/null +++ b/shells/powershell/files/patch-src_powershell_Program.cs @@ -0,0 +1,94 @@ +--- src/powershell/Program.cs.orig 2024-03-30 20:39:17 UTC ++++ src/powershell/Program.cs +@@ -56,6 +56,13 @@ namespace Microsoft.PowerShell + private const int MACOS_KERN_ARGMAX = 8; + private const int MACOS_KERN_PROCARGS2 = 49; + private const int MACOS_PROC_PIDPATHINFO_MAXSIZE = 4096; ++ ++ // FreeBSD p/Invoke constants ++ private const int FREEBSD_CTL_KERN = 1; ++ private const int FREEBSD_KERN_PROC = 14; ++ private const int FREEBSD_KERN_PROC_ARGS = 7; ++ private const int FREEBSD_KERN_PROC_PATHNAME = 12; ++ private const int FREEBSD_ENOMEM = 12; + #endif + + /// <summary> +@@ -125,7 +132,62 @@ namespace Microsoft.PowerShell + ThrowOnFailure("exec", ExecPwshLogin(args, pwshPath, isMacOS: false)); + return; + } ++ else if (OperatingSystem.IsFreeBSD()) ++ { ++ Span<int> fmib = stackalloc int[4]; ++ int fmibLength = 4; ++ fmib[0] = FREEBSD_CTL_KERN; ++ fmib[1] = FREEBSD_KERN_PROC; ++ fmib[2] = FREEBSD_KERN_PROC_ARGS; ++ fmib[3] = -1; + ++ int sz = 1; ++ unsafe ++ { ++ fixed (int *mibptr = fmib) ++ { ++ ThrowOnFailure(nameof(procNameFirstByte), SysCtl(mibptr, fmibLength, &procNameFirstByte, &sz, IntPtr.Zero, 0), FREEBSD_ENOMEM); ++ } ++ } ++ ++ if (!IsLogin(procNameFirstByte, args)) ++ { ++ return; ++ } ++ ++ fmib[2] = FREEBSD_KERN_PROC_PATHNAME; ++ int pathsz = 0; ++ ++ unsafe ++ { ++ fixed (int *mibptr = fmib) ++ { ++ ThrowOnFailure(nameof(pathsz), SysCtl(mibptr, fmibLength, (void *)null, &pathsz, IntPtr.Zero, 0)); ++ } ++ } ++ ++ IntPtr execPathPtr = Marshal.AllocHGlobal(pathsz); ++ try ++ { ++ unsafe ++ { ++ fixed (int *mibptr = fmib) ++ { ++ ThrowOnFailure(nameof(execPathPtr), SysCtl(mibptr, fmibLength, execPathPtr.ToPointer(), &pathsz, IntPtr.Zero, 0)); ++ } ++ } ++ string? execPath = Marshal.PtrToStringAnsi(execPathPtr); ++ ArgumentNullException.ThrowIfNull(execPath); ++ ThrowOnFailure("exec", ExecPwshLogin(args, execPath, isMacOS: false)); ++ } ++ finally ++ { ++ Marshal.FreeHGlobal(execPathPtr); ++ } ++ ++ return; ++ } ++ + // At this point, we are on macOS + + // Set up the mib array and the query for process maximum args size +@@ -417,11 +479,13 @@ namespace Microsoft.PowerShell + /// </summary> + /// <param name="call">The native call that was attempted.</param> + /// <param name="code">The exit code it returned.</param> +- private static void ThrowOnFailure(string call, int code) ++ /// <param name="ignore">Ignore this error, consider it success.</param> ++ private static void ThrowOnFailure(string call, int code, int ignore = 0) + { + if (code < 0) + { + code = Marshal.GetLastWin32Error(); ++ if (code == ignore) return; + Console.Error.WriteLine($"Call to '{call}' failed with errno {code}"); + throw new StartupException(call, code); + } |