Skip to content
Open
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
44 changes: 36 additions & 8 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ function Get-EnvironmentInformation
$environment += @{'IsCoreCLR' = [System.Management.Automation.Platform]::IsCoreCLR}
$environment += @{'IsLinux' = [System.Management.Automation.Platform]::IsLinux}
$environment += @{'IsMacOS' = [System.Management.Automation.Platform]::IsMacOS}
$environment += @{'IsFreeBSD' = [System.Management.Automation.Platform]::IsFreeBSD}
} else {
$environment += @{'IsCoreCLR' = $false}
$environment += @{'IsLinux' = $false}
$environment += @{'IsMacOS' = $false}
$environment += @{'IsFreeBSD' = $false}
}

if ($environment.IsWindows)
Expand All @@ -159,6 +161,10 @@ function Get-EnvironmentInformation
}
}

if ($environment.IsFreeBSD) {
$environment += @{ 'OSArchitecture' = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture }
}

if ($environment.IsLinux) {
$environment += @{ 'OSArchitecture' = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture }
$LinuxInfo = Get-Content /etc/os-release -Raw | ConvertFrom-StringData
Expand Down Expand Up @@ -276,7 +282,7 @@ function Test-IsReleaseCandidate
return $false
}

$optimizedFddRegex = 'fxdependent-(linux|win|win7|osx)-(x64|x86|arm64|arm)'
$optimizedFddRegex = 'fxdependent-(linux|win|win7|osx|freebsd)-(x64|x86|arm64|arm)'

function Start-PSBuild {
[CmdletBinding(DefaultParameterSetName="Default")]
Expand Down Expand Up @@ -322,6 +328,7 @@ function Start-PSBuild {
"linux-arm",
"linux-arm64",
"linux-x64",
"freebsd-x64",
"osx-arm64",
"osx-x64",
"win-arm",
Expand Down Expand Up @@ -360,7 +367,7 @@ function Start-PSBuild {
}

if ($ForMinimalSize) {
if ($Runtime -and "linux-x64", "win7-x64", "osx-x64" -notcontains $Runtime) {
if ($Runtime -and "linux-x64", "win7-x64", "osx-x64", "freebsd-x64" -notcontains $Runtime) {
throw "Build for the minimal size is enabled only for following runtimes: 'linux-x64', 'win7-x64', 'osx-x64'"
}
}
Expand Down Expand Up @@ -814,6 +821,10 @@ function Test-ShouldGenerateExperimentalFeatures
$runtimePattern = '^linux.*-'
}

if ($environment.IsFreeBSD) {
$runtimePattern = '^freebsd.*-'
}

$runtimePattern += $environment.OSArchitecture.ToString()
Write-Verbose "runtime pattern check: $Runtime -match $runtimePattern" -Verbose
if ($Runtime -match $runtimePattern) {
Expand Down Expand Up @@ -999,6 +1010,7 @@ function New-PSOptions {
"linux-arm",
"linux-arm64",
"linux-x64",
"freebsd-x64",
"osx-arm64",
"osx-x64",
"win-arm",
Expand Down Expand Up @@ -1051,6 +1063,10 @@ function New-PSOptions {
'Darwin' {
$Runtime = "osx-${Architecture}"
}

'FreeBSD' {
$Runtime = "freebsd-${Architecture}"
}
}

if (-not $Runtime) {
Expand All @@ -1071,7 +1087,7 @@ function New-PSOptions {

$Executable = if ($Runtime -like 'fxdependent*') {
"pwsh.dll"
} elseif ($environment.IsLinux -or $environment.IsMacOS) {
} elseif ($environment.IsLinux -or $environment.IsMacOS -or $environment.IsFreeBSD) {
"pwsh"
} elseif ($environment.IsWindows) {
"pwsh.exe"
Expand Down Expand Up @@ -2045,15 +2061,15 @@ function Install-Dotnet {
$installObtainUrl = "https://dotnet.microsoft.com/download/dotnet/scripts/v1"
$uninstallObtainUrl = "https://raw.githubusercontent.com/dotnet/cli/master/scripts/obtain"

# Install for Linux and OS X
if ($environment.IsLinux -or $environment.IsMacOS) {
# Install for Linux, OS X, and FreeBSD
if ($environment.IsLinux -or $environment.IsMacOS -or $environment.IsFreeBSD) {
$wget = Get-Command -Name wget -CommandType Application -TotalCount 1 -ErrorAction Stop

# Attempt to uninstall previous dotnet packages if requested
if ($RemovePreviousVersion) {
$uninstallScript = if ($environment.IsLinux -and $environment.IsUbuntu) {
"dotnet-uninstall-debian-packages.sh"
} elseif ($environment.IsMacOS) {
} elseif ($environment.IsMacOS -or $environment.IsFreeBSD) {
"dotnet-uninstall-pkgs.sh"
}

Expand All @@ -2063,7 +2079,7 @@ function Install-Dotnet {
Invoke-Expression "$sudo bash ./$uninstallScript"
}
} else {
Write-Warning "This script only removes prior versions of dotnet for Ubuntu and OS X"
Write-Warning "This script only removes prior versions of dotnet for Ubuntu, OS X, and FreeBSD"
}
}

Expand Down Expand Up @@ -2243,7 +2259,7 @@ function Start-PSBootstrap {
}

try {
if ($environment.IsLinux -or $environment.IsMacOS) {
if ($environment.IsLinux -or $environment.IsMacOS -or $environment.IsFreeBSD) {
# This allows sudo install to be optional; needed when running in containers / as root
# Note that when it is null, Invoke-Expression (but not &) must be used to interpolate properly
$sudo = if (!$NoSudo) { "sudo" }
Expand Down Expand Up @@ -2346,6 +2362,18 @@ function Start-PSBootstrap {
Start-NativeExecution {
Invoke-Expression "apk add $Deps"
}
} elseif ($environment.IsFreeBSD) {
$Deps += 'libunwind', 'curl', 'bash', 'git'
$PackageManager = "pkg install --yes"
$baseCommand = "$sudo $PackageManager"

if($NoSudo)
{
$baseCommand = $PackageManager
}
Start-NativeExecution {
Invoke-Expression "$baseCommand $Deps"
}
}

# Install [fpm](https://github.com/jordansissel/fpm)
Expand Down
2 changes: 1 addition & 1 deletion docs/host-powershell/sample/MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<AssemblyName>MyApp</AssemblyName>
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win10-x64;linux-x64;osx-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win10-x64;linux-x64;osx-x64;freebsd-x64</RuntimeIdentifiers>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static string GetText()
ExecuteOnStaThread(() => GetTextImpl(out clipboardText));
return clipboardText;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
{
tool = "xclip";
args = "-selection clipboard -out";
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void SetText(string text)
ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT)));
return;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
{
tool = "xclip";
if (string.IsNullOrEmpty(text))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ protected override void ProcessRecord()
return;
}

if (Platform.IsFreeBSD)
{
string errorMessage = UnblockFileStrings.FreeBSDNotSupported;
Exception e = new PlatformNotSupportedException(errorMessage);
ThrowTerminatingError(new ErrorRecord(exception: e, errorId: "FreeBSDNotSupported", ErrorCategory.NotImplemented, targetObject: null));
return;
}

foreach (string path in pathsToProcess)
{
if (IsBlocked(path))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ internal static string PlatformName
{
return "Linux";
}
else if (Platform.IsFreeBSD)
{
return "FreeBSD";
}
else
{
// Unknown/unsupported platform
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="FreeBSDNotSupported" xml:space="preserve">
<value>The cmdlet does not support FreeBSD.</value>
</data>
<data name="LinuxNotSupported" xml:space="preserve">
<value>The cmdlet does not support Linux.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ internal class CommandLineParameterParser
{
private const int MaxPipePathLengthLinux = 108;
private const int MaxPipePathLengthMacOS = 104;
private const int MaxPipePathLengthFreeBSD = 1023;

internal static int MaxNameLength()
{
Expand All @@ -164,6 +165,12 @@ internal static int MaxNameLength()
return ushort.MaxValue;
}

if (Platform.IsFreeBSD)
{
int length = MaxPipePathLengthFreeBSD - Path.GetTempPath().Length;
return length > 255 ? 255 : length;
}

int maxLength = Platform.IsLinux ? MaxPipePathLengthLinux : MaxPipePathLengthMacOS;
return maxLength - Path.GetTempPath().Length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ All parameters are case-insensitive.</value>

-Login | -l

On Linux and macOS, starts PowerShell as a login shell, using /bin/sh to
On Linux, macOS, and FreeBSD starts PowerShell as a login shell, using /bin/sh to
execute login profiles such as /etc/profile and ~/.profile. On Windows,
this switch does nothing.

Expand Down
2 changes: 1 addition & 1 deletion src/ResGen/ResGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<OutputType>Exe</OutputType>
<TieredCompilation>true</TieredCompilation>
<TieredCompilationQuickJit>true</TieredCompilationQuickJit>
<RuntimeIdentifiers>win-x86;win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x86;win-x64;osx-x64;linux-x64;freebsd-x64</RuntimeIdentifiers>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,11 @@ private static string GetNativeDllSubFolderName(out string ext)
folderName = "osx-" + processArch;
ext = ".dylib";
}
else if (Platform.IsFreeBSD)
{
folderName = "freebsd-" + processArch;
ext = ".so";
}

return folderName;
}
Expand Down
13 changes: 12 additions & 1 deletion src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public static bool IsCoreCLR
}
}

/// <summary>
/// True if the current platform is FreeBSD.
/// </summary>
public static bool IsFreeBSD
{
get
{
return OperatingSystem.IsFreeBSD();
}
}

/// <summary>
/// True if the underlying system is NanoServer.
/// </summary>
Expand Down Expand Up @@ -441,7 +452,7 @@ internal static uint NonWindowsGetThreadId()

internal static int NonWindowsGetProcessParentPid(int pid)
{
return IsMacOS ? Unix.NativeMethods.GetPPid(pid) : Unix.GetProcFSParentPid(pid);
return IsMacOS ? Unix.NativeMethods.GetPPid(pid) : IsFreeBSD ? Unix.NativeMethods.GetPPid(pid) : Unix.GetProcFSParentPid(pid);
}

internal static bool NonWindowsKillProcess(int pid)
Expand Down
4 changes: 2 additions & 2 deletions src/System.Management.Automation/DscSupport/CimDSCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ internal void ValidateInstanceText(string classText)
uint offset = 0;
byte[] bytes = null;

if (Platform.IsLinux || Platform.IsMacOS)
if (Platform.IsLinux || Platform.IsMacOS || Platform.IsFreeBSD)
{
bytes = System.Text.Encoding.UTF8.GetBytes(classText);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ public static void Initialize(Collection<Exception> errors, List<string> moduleP
{
s_tracer.WriteLine("Initializing DSC class cache force={0}");

if (Platform.IsLinux || Platform.IsMacOS)
if (Platform.IsLinux || Platform.IsMacOS || Platform.IsFreeBSD)
{
//
// Load the base schema files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4640,6 +4640,12 @@ static InitialSessionState()
string.Empty,
ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),

new SessionStateVariableEntry(
SpecialVariables.IsFreeBSD,
Platform.IsFreeBSD,
string.Empty,
ScopedItemOptions.ReadOnly | ScopedItemOptions.AllScope),

new SessionStateVariableEntry(
SpecialVariables.IsCoreCLR,
Platform.IsCoreCLR,
Expand Down
4 changes: 4 additions & 0 deletions src/System.Management.Automation/engine/SpecialVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ internal static class SpecialVariables

internal static readonly VariablePath IsWindowsPath = new VariablePath("IsWindows");

internal const string IsFreeBSD = "IsFreeBSD";

internal static readonly VariablePath IsFreeBSDPath = new VariablePath("IsFreeBSD");

internal const string IsCoreCLR = "IsCoreCLR";

internal static readonly VariablePath IsCoreCLRPath = new VariablePath("IsCoreCLR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ public sealed class RemoteSessionNamedPipeServer : IDisposable
private const int _namedPipeBufferSizeForRemoting = 32768;
private const int _maxPipePathLengthLinux = 108;
private const int _maxPipePathLengthMacOS = 104;
private const int _maxPipePathLengthFreeBSD = 1023;

// Singleton server.
private static readonly object s_syncObject;
Expand Down Expand Up @@ -575,6 +576,11 @@ public static void CreateCustomNamedPipeServer(string pipeName)
if (!Platform.IsWindows)
{
int maxNameLength = (Platform.IsLinux ? _maxPipePathLengthLinux : _maxPipePathLengthMacOS) - Path.GetTempPath().Length;
if (Platform.IsFreeBSD)
{
int length = _maxPipePathLengthFreeBSD - Path.GetTempPath().Length;
maxNameLength = length > 255 ? 255 : length;
}
if (pipeName.Length > maxNameLength)
{
throw new InvalidOperationException(
Expand Down
2 changes: 1 addition & 1 deletion src/TypeCatalogGen/TypeCatalogGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<OutputType>Exe</OutputType>
<TieredCompilation>true</TieredCompilation>
<TieredCompilationQuickJit>true</TieredCompilationQuickJit>
<RuntimeIdentifiers>win-x86;win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<RuntimeIdentifiers>win-x86;win-x64;osx-x64;linux-x64;freebsd-x64</RuntimeIdentifiers>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/powershell-unix/powershell-unix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<TieredCompilation>true</TieredCompilation>
<TieredCompilationQuickJit>true</TieredCompilationQuickJit>
<TieredCompilationQuickJitForLoops>true</TieredCompilationQuickJitForLoops>
<RuntimeIdentifiers>linux-x64;osx-x64;</RuntimeIdentifiers>
<RuntimeIdentifiers>linux-x64;osx-x64;freebsd-x64;</RuntimeIdentifiers>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading