mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
enabled hash bang support, fixed run scripts to not alter the current working directory
This commit is contained in:
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
Usage:
|
||||
|
||||
PATH=$PATH:/absolute/path/to/powershell/app_base ./script.ps1
|
||||
|
||||
Comment:
|
||||
|
||||
The script assumes that /usr/bin/env can execute runps-file.sh.
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env runps-file.sh
|
||||
|
||||
get-process
|
||||
get-module
|
||||
|
||||
+4
-1
@@ -183,11 +183,14 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
|
||||
|
||||
pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr
|
||||
# execute the pester tests, pester needs a TEMP environment variable to be set
|
||||
exec_env/app_base/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester'
|
||||
exec_env/app_base/runps-simple.sh 'cd ../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester'
|
||||
|
||||
test: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-release-clr $(addprefix $(TESTRUN_FOLDER)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) pester-tests dotnetlibs/monad_native
|
||||
cd exec_env/app_base && PSMODULEPATH=$(shell pwd)/exec_env/app_base/Modules LD_LIBRARY_PATH=../coreclr:. ../coreclr/corerun xunit.console.netcore.exe ps_test.dll -xml ../../xunittests.xml
|
||||
# run the c++ tests
|
||||
cd dotnetlibs && ./monad_native
|
||||
# test the 3rdparty/hashbang sample
|
||||
PATH=$(PATH):$(shell pwd)/exec_env/app_base 3rdparty/hashbang/script.ps1
|
||||
|
||||
run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-debug-clr
|
||||
PAL_DBG_CHANNELS="+LOADER.TRACE" exec_env/app_base/runps-simple.sh get-location
|
||||
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
"$SCRIPTDIR/runps.sh" --file "$@"
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
CWD=$(pwd)
|
||||
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
cd $SCRIPTDIR
|
||||
echo "launching PS now"
|
||||
PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=.:/usr/lib/llvm-3.6/lib lldb-3.6 ./host_cmdline -- -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" "$@"
|
||||
cd "$SCRIPTDIR"
|
||||
echo "launching PS debug now"
|
||||
PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR:/usr/lib/llvm-3.6/lib" lldb-3.6 ./host_cmdline -- -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" --working-dir "$CWD" "$@"
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
CWD=$(pwd)
|
||||
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
cd $SCRIPTDIR
|
||||
echo "launching PS now"
|
||||
PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. strace -e trace=file ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" "$@"
|
||||
cd "$SCRIPTDIR"
|
||||
echo "launching PS trace now"
|
||||
PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" strace -e trace=file ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" --working-dir "$CWD" "$@"
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
CWD=$(pwd)
|
||||
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
cd $SCRIPTDIR
|
||||
echo "launching PS now"
|
||||
PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" "$@"
|
||||
cd "$SCRIPTDIR"
|
||||
PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-simple.exe "powershell-simple, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "ps_hello_world.Program" "UnmanagedMain" --working-dir "$CWD" "$@"
|
||||
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
#!/bin/bash
|
||||
|
||||
CWD=$(pwd)
|
||||
SCRIPTDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
||||
|
||||
cd $SCRIPTDIR
|
||||
echo "launching PS now"
|
||||
PSMODULEPATH=$SCRIPTDIR/Modules LD_LIBRARY_PATH=. ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-run.exe "powershell-run, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "Microsoft.Samples.PowerShell.Host.PSListenerConsoleSample" "UnmanagedMain" "$@"
|
||||
cd "$SCRIPTDIR"
|
||||
PSMODULEPATH="$SCRIPTDIR/Modules" LD_LIBRARY_PATH="$SCRIPTDIR" ./host_cmdline -c ../coreclr -alc Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.dll -tpa powershell-run.exe "powershell-run, version=1.0.0.0, culture=neutral, PublicKeyToken=null" "Microsoft.Samples.PowerShell.Host.PSListenerConsoleSample" "UnmanagedMain" --working-dir "$CWD" "$@"
|
||||
|
||||
|
||||
+31
-13
@@ -109,28 +109,46 @@ namespace Microsoft.Samples.PowerShell.Host
|
||||
private static void ManagedMain(string[] args)
|
||||
{
|
||||
|
||||
// Display the welcome message.
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("PowerShell for Linux interactive console");
|
||||
Console.WriteLine("========================================");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Current status:");
|
||||
Console.WriteLine("- Type 'exit' to exit");
|
||||
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
|
||||
Console.WriteLine();
|
||||
|
||||
String initialScript = null;
|
||||
if (args.Length > 0 && args[0] == "--file")
|
||||
if (args.Length > 0)
|
||||
{
|
||||
initialScript = File.ReadAllText(args[1]);
|
||||
for (int i = 0; i < args.Length; ++i)
|
||||
{
|
||||
string arg = args[i];
|
||||
bool hasNext = (i+1)<args.Length;
|
||||
string nextArg = hasNext ? args[i+1] : "";
|
||||
|
||||
if (hasNext && arg == "--file")
|
||||
{
|
||||
initialScript = File.ReadAllText(nextArg);
|
||||
++i;
|
||||
}
|
||||
else if (hasNext && arg == "--working-dir")
|
||||
{
|
||||
Directory.SetCurrentDirectory(nextArg);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the listener and run it. This method never returns.
|
||||
// Create the listener and run it
|
||||
PSListenerConsoleSample listener = new PSListenerConsoleSample(initialScript);
|
||||
|
||||
// only run if there was no script file passed in
|
||||
if (initialScript == null)
|
||||
{
|
||||
// Display the welcome message.
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("PowerShell for Linux interactive console");
|
||||
Console.WriteLine("========================================");
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Current status:");
|
||||
Console.WriteLine("- Type 'exit' to exit");
|
||||
Console.WriteLine("- Utility and Management cmdlet modules are loadable");
|
||||
Console.WriteLine();
|
||||
|
||||
listener.Run();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Management.Automation.Host;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.IO;
|
||||
|
||||
namespace ps_hello_world
|
||||
{
|
||||
@@ -534,7 +535,27 @@ namespace ps_hello_world
|
||||
allArgs.Add(argv[i]);
|
||||
}
|
||||
|
||||
test2(allArgs.ToArray());
|
||||
List<string> filteredArgs = new List<string>();
|
||||
if (allArgs.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < allArgs.Count; ++i)
|
||||
{
|
||||
string arg = allArgs[i];
|
||||
bool hasNext = (i+1)<allArgs.Count;
|
||||
string nextArg = hasNext ? allArgs[i+1] : "";
|
||||
|
||||
if (hasNext && arg == "--working-dir")
|
||||
{
|
||||
Console.WriteLine("working dir set to: " + nextArg);
|
||||
Directory.SetCurrentDirectory(nextArg);
|
||||
++i;
|
||||
}
|
||||
else
|
||||
filteredArgs.Add(arg);
|
||||
}
|
||||
}
|
||||
|
||||
test2(filteredArgs.ToArray());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user