From 51c998b57e74f9c288e59326fad3fb13355396d5 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Fri, 18 Sep 2015 17:39:42 -0700 Subject: [PATCH 01/37] added unit test to verify functionality of CommandLineArgvW in linux --- src/ps_test/test_CorePsPlatform.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index e11826091e..4534f8a2d4 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -134,5 +134,24 @@ namespace PSTests FileSystemInfo fd = new FileInfo(path); Assert.False(Platform.NonWindowsIsHardLink(fd)); } + + [Fact] + public static void TestCommandLineArgvW() + { + string testCommand= "Today is a \\\"good day\" or is it"; + + int count = 0; + + string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); + + Assert.Equal("Today", retval[0]); + Assert.Equal("is", retval[1]); + Assert.Equal("a", retval[2]); + Assert.Equal("\\\"good", retval[3]); + Assert.Equal("day\"", retval[4]); + Assert.Equal("or", retval[5]); + Assert.Equal("is", retval[6]); + Assert.Equal("it", retval[7]); + } } } From 92114f21e7471639d8a575330fc29abda3009a59 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 22 Sep 2015 15:14:22 -0700 Subject: [PATCH 02/37] added unit tests for CommandLineToArgvW in Linux --- src/ps_test/test_CorePsPlatform.cs | 107 +++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 4534f8a2d4..39f2b36c3d 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -135,10 +135,23 @@ namespace PSTests Assert.False(Platform.NonWindowsIsHardLink(fd)); } + [Fact] - public static void TestCommandLineArgvW() + public static void TestCommandLineArgvReturnsAnElement() { - string testCommand= "Today is a \\\"good day\" or is it"; + string testCommand= "Today"; + + int count = 0; + + string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); + + Assert.Equal(1, count); + } + + [Fact] + public static void TestCommandLineArgvWWithSpaces() + { + string testCommand= "Today is a good day or is it"; int count = 0; @@ -147,11 +160,97 @@ namespace PSTests Assert.Equal("Today", retval[0]); Assert.Equal("is", retval[1]); Assert.Equal("a", retval[2]); - Assert.Equal("\\\"good", retval[3]); - Assert.Equal("day\"", retval[4]); + Assert.Equal("good", retval[3]); + Assert.Equal("day", retval[4]); Assert.Equal("or", retval[5]); Assert.Equal("is", retval[6]); Assert.Equal("it", retval[7]); } + + [Fact] + public static void TestCommandLineToArgvWTabsAreTreatedAsSpaces() + { + string testCommand = "Today \t is a good day"; + + int count = 0; + + string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); + + Assert.Equal("Today", retval[0]); + Assert.Equal("is", retval[1]); + Assert.Equal("a", retval[2]); + Assert.Equal("good", retval[3]); + Assert.Equal("day", retval[4]); + } + + [Fact] + public static void TestCommandLineToArgvWQuotesAreArgs() + { + string testCommand = "Today is \"a good\" day"; + + int count = 0; + + string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); + + Assert.Equal(4, count); + Assert.Equal("Today", retval[0]); + Assert.Equal("is", retval[1]); + Assert.Equal("\"a good\"", retval[2]); + Assert.Equal("day", retval[3]); + } + + [Fact] + public static void TestCommandLineToArgvWEvenNumberBackSlashes() + { + string test1 = "a\\b c d"; + string test2 = "a\\b\\c d"; + string test3 = "a \\b\\c\\d"; + string test4 = "a\\\\\\b"; + + int count = 0; + + string[] a = Platform.NonWindowsCommandLineToArgvW(test1, out count); + + Assert.Equal(3, count); + Assert.Equal("a\\b", a[0]); + Assert.Equal("c", a[1]); + Assert.Equal("d", a[2]); + + string[] b = Platform.NonWindowsCommandLineToArgvW(test2, out count); + + Assert.Equal(2, count); + Assert.Equal("a\\b\\c", b[0]); + Assert.Equal("d", b[1]); + + string[] c = Platform.NonWindowsCommandLineToArgvW(test3, out count); + + Assert.Equal(2, count); + Assert.Equal("a", c[0]); + Assert.Equal("\\b\\c\\d", c[1]); + + string[] d = Platform.NonWindowsCommandLineToArgvW(test4, out count); + + Assert.Equal(1, count); + Assert.Equal("a\\\\\\b", d[0]); + } + + [Fact] + public static void TestCommandLineToArgvwOddNumberWithBackSlashes() + { + string test1 = "a\\\"b"; + string test2 = "a\\\\\\\"b"; + + int count = 0; + + string[] a = Platform.NonWindowsCommandLineToArgvW(test1, out count); + + Assert.Equal(1, count); + Assert.Equal("a\\\"b", a[0]); + + string[] b = Platform.NonWindowsCommandLineToArgvW(test2, out count); + + Assert.Equal(1, count); + Assert.Equal("a\\\\\\\"b", b[0]); + } } } From 3956b8cd5baad0bd9241738dfea20fb3be8ff2a3 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Fri, 9 Oct 2015 10:51:23 -0700 Subject: [PATCH 03/37] added tests to ensure that powershell can interface with the dotnet api --- src/pester-tests/Test-DotNetAPI.Tests.ps1 | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/pester-tests/Test-DotNetAPI.Tests.ps1 diff --git a/src/pester-tests/Test-DotNetAPI.Tests.ps1 b/src/pester-tests/Test-DotNetAPI.Tests.ps1 new file mode 100644 index 0000000000..2f942d00be --- /dev/null +++ b/src/pester-tests/Test-DotNetAPI.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "Test-DotNetAPI" { + $posh_E = 2.718281828459045 + $posh_pi = 3.14159265358979 + + It "Should be able to use static .NET classes and get a constant" { + [System.Math]::E | Should Match $posh_E.ToString() + [System.Math]::PI | Should Match $posh_pi.ToString() + } + + It "Should be able to invoke a method" { + [System.Environment]::GetEnvironmentVariable("PATH") | Should Be $env:PATH + } + + It "Should not require 'system' in front of static classes" { + [Environment]::CommandLine | Should Be ([System.Environment]::CommandLine) + + [Math]::E | Should Be ([System.Math]::E) + } + + It "Should be able to create a new instance of a .Net object" { + [System.Guid]$guidVal = [System.Guid]::NewGuid() + + $guidVal.GetType().Name | Should Be "Guid" + } +} From cdd2add9b14f6f35a1021c03a347fc67bf8e8b92 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Fri, 9 Oct 2015 12:01:16 -0700 Subject: [PATCH 04/37] added get-itemproperty tests --- .../Test-Get-ItemProperty.Tests.ps1 | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/pester-tests/Test-Get-ItemProperty.Tests.ps1 diff --git a/src/pester-tests/Test-Get-ItemProperty.Tests.ps1 b/src/pester-tests/Test-Get-ItemProperty.Tests.ps1 new file mode 100644 index 0000000000..75360ffdf4 --- /dev/null +++ b/src/pester-tests/Test-Get-ItemProperty.Tests.ps1 @@ -0,0 +1,65 @@ +Describe "Test-Get-ItemProperty" { + $currentDirectory = Split-Path . -Leaf + $parentDirectory = Split-Path .. -Leaf + if (Test-Path /tmp) + { + $tempDirectory = "/tmp/testfolder" + $testProvider = "/" + } + else + { + $tempDirectory = "~/testfolder" + $testProvider = "C" + } + + New-Item $tempDirectory -ItemType Directory -Force + $testfile = $tempDirectory + "/" + "testfile1" + + New-Item $testfile -ItemType file -Force + + It "Should be able to be called on in the current directory" { + { Get-ItemProperty . } | Should Not Throw + + $(Get-ItemProperty .).Name | Should Be $currentDirectory + } + + It "Should be able to be called on a parent directory" { + { Get-ItemProperty .. } | Should Not Throw + + (Get-ItemProperty ..).Name | Should Be $parentDirectory + } + + It "Should be able to be called on a directory using the path switch" { + { Get-ItemProperty -Path $tempDirectory } | Should Not Throw + } + + It "Should be able to be called on a file using the path switch" { + { Get-ItemProperty -Path $testfile } | Should Not Throw + } + + It "Should be able to access a property using the Path and name switches" { + { Get-ItemProperty -Path $testfile -Name fullname } | Should Not Throw + + $output = Get-ItemProperty -Path $testfile -Name fullname + + $output.PSPath | Should Not BeNullOrEmpty + + $output.PSDrive | Should Be $testprovider + + $output.PSProvider.Name | Should Be "FileSystem" + } + + It "Should be able to use the gp alias without error" { + { gp . } | Should Not Throw + { gp .. } | Should Not Throw + } + + It "Should have the same results between alias and cmdlet" { + $alias = gp -Path $testfile -Name fullname + $cmdlet = Get-ItemProperty -Path $testfile -Name fullname + + $alias.PSPath | Should Be $cmdlet.PSPath + $alias.PSDrive | Should Be $cmdlet.PSDrive + $alias.PSProvider.Name | Should Be $cmdlet.PSProvider.Name + } +} From c3cec1d4330fb3dbf41d0bc6a74849206dfea8e1 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Fri, 9 Oct 2015 12:44:49 -0700 Subject: [PATCH 05/37] bringing in committed monad changes --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 9330fdf4ce..a62341e50a 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 9330fdf4ce15b1bfd12be3cdd5ee8a8969f92f25 +Subproject commit a62341e50a7ba958e88e3e8e9ad746af7c2b5d6c From 0ac13b99c13a755d21f44edb1fd3d9f583df159d Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Fri, 9 Oct 2015 13:24:08 -0700 Subject: [PATCH 06/37] Added Get-PSProvider unit tests --- .../Test-Get-PSProvider.Tests.ps1 | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/pester-tests/Test-Get-PSProvider.Tests.ps1 diff --git a/src/pester-tests/Test-Get-PSProvider.Tests.ps1 b/src/pester-tests/Test-Get-PSProvider.Tests.ps1 new file mode 100644 index 0000000000..33944c31b2 --- /dev/null +++ b/src/pester-tests/Test-Get-PSProvider.Tests.ps1 @@ -0,0 +1,25 @@ +Describe "Test-Get-PSProvider" { + It "Should be able to call with no parameters without error" { + { Get-PSProvider } | Should Not Throw + } + + It "Should be able to call the filesystem provider" { + { Get-PSProvider FileSystem } | Should Not Throw + + $actual = Get-PSProvider FileSystem + + $actual.Name | Should Be "FileSystem" + + $actual.Capabilities | Should Be "Filter, ShouldProcess, Credentials" + } + + It "Should be able to call a provider with a wildcard expression" { + { Get-PSProvider File*m } | Should Not Throw + } + + It "Should be able to pipe the output" { + $actual = Get-PSProvider + + { $actual | Format-List } | Should Not Throw + } +} From 9270e0b9eb30990136e5d454f8b19721f3b3b02f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Fri, 9 Oct 2015 16:02:11 -0700 Subject: [PATCH 07/37] Implement simpler use of CommandLineToArgv Reduced code churn from monad's master branch (aka Source Depot) --- src/monad | 2 +- src/ps_test/test_CorePsPlatform.cs | 70 +++++++++++++----------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/monad b/src/monad index a62341e50a..454f5ebc33 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit a62341e50a7ba958e88e3e8e9ad746af7c2b5d6c +Subproject commit 454f5ebc3343cf764ed092392544c31dd3fbc375 diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 39f2b36c3d..0c6cc33614 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -141,11 +141,9 @@ namespace PSTests { string testCommand= "Today"; - int count = 0; + string[] retval = Platform.CommandLineToArgv(testCommand); - string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); - - Assert.Equal(1, count); + Assert.Equal(1, retval.Length); } [Fact] @@ -153,9 +151,7 @@ namespace PSTests { string testCommand= "Today is a good day or is it"; - int count = 0; - - string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); + string[] retval = Platform.CommandLineToArgv(testCommand); Assert.Equal("Today", retval[0]); Assert.Equal("is", retval[1]); @@ -172,9 +168,7 @@ namespace PSTests { string testCommand = "Today \t is a good day"; - int count = 0; - - string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); + string[] retval = Platform.CommandLineToArgv(testCommand); Assert.Equal("Today", retval[0]); Assert.Equal("is", retval[1]); @@ -188,11 +182,9 @@ namespace PSTests { string testCommand = "Today is \"a good\" day"; - int count = 0; + string[] retval = Platform.CommandLineToArgv(testCommand); - string[] retval = Platform.NonWindowsCommandLineToArgvW(testCommand, out count); - - Assert.Equal(4, count); + Assert.Equal(4, retval.Length); Assert.Equal("Today", retval[0]); Assert.Equal("is", retval[1]); Assert.Equal("\"a good\"", retval[2]); @@ -206,32 +198,31 @@ namespace PSTests string test2 = "a\\b\\c d"; string test3 = "a \\b\\c\\d"; string test4 = "a\\\\\\b"; + string[] retval; - int count = 0; + retval = Platform.CommandLineToArgv(test1); - string[] a = Platform.NonWindowsCommandLineToArgvW(test1, out count); + Assert.Equal(3, retval.Length); + Assert.Equal("a\\b", retval[0]); + Assert.Equal("c", retval[1]); + Assert.Equal("d", retval[2]); - Assert.Equal(3, count); - Assert.Equal("a\\b", a[0]); - Assert.Equal("c", a[1]); - Assert.Equal("d", a[2]); + retval = Platform.CommandLineToArgv(test2); - string[] b = Platform.NonWindowsCommandLineToArgvW(test2, out count); + Assert.Equal(2, retval.Length); + Assert.Equal("a\\b\\c", retval[0]); + Assert.Equal("d", retval[1]); - Assert.Equal(2, count); - Assert.Equal("a\\b\\c", b[0]); - Assert.Equal("d", b[1]); + retval = Platform.CommandLineToArgv(test3); - string[] c = Platform.NonWindowsCommandLineToArgvW(test3, out count); + Assert.Equal(2, retval.Length); + Assert.Equal("a", retval[0]); + Assert.Equal("\\b\\c\\d", retval[1]); - Assert.Equal(2, count); - Assert.Equal("a", c[0]); - Assert.Equal("\\b\\c\\d", c[1]); + retval = Platform.CommandLineToArgv(test4); - string[] d = Platform.NonWindowsCommandLineToArgvW(test4, out count); - - Assert.Equal(1, count); - Assert.Equal("a\\\\\\b", d[0]); + Assert.Equal(1, retval.Length); + Assert.Equal("a\\\\\\b", retval[0]); } [Fact] @@ -239,18 +230,17 @@ namespace PSTests { string test1 = "a\\\"b"; string test2 = "a\\\\\\\"b"; + string[] retval; - int count = 0; + retval = Platform.CommandLineToArgv(test1); - string[] a = Platform.NonWindowsCommandLineToArgvW(test1, out count); + Assert.Equal(1, retval.Length); + Assert.Equal("a\\\"b", retval[0]); - Assert.Equal(1, count); - Assert.Equal("a\\\"b", a[0]); + retval = Platform.CommandLineToArgv(test2); - string[] b = Platform.NonWindowsCommandLineToArgvW(test2, out count); - - Assert.Equal(1, count); - Assert.Equal("a\\\\\\\"b", b[0]); + Assert.Equal(1, retval.Length); + Assert.Equal("a\\\\\\\"b", retval[0]); } } } From 0d4ebb38b8f84260fce903008ae24f6e1daf17b5 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Oct 2015 19:47:07 -0700 Subject: [PATCH 08/37] Replace docker build scripts Import the functions into your shell, `source scripts/monad-docker.sh`, then run `monad-run make test` or `monad-tty make run-interactive` from `monad-linux`. Top level `Makefile` passes to `scripts/Makefile`. --- Makefile | 3 +++ scripts/build-run.sh | 28 --------------------------- scripts/build-tty.sh | 5 ----- scripts/build.sh | 5 ----- scripts/monad-docker.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 Makefile delete mode 100755 scripts/build-run.sh delete mode 100755 scripts/build-tty.sh delete mode 100755 scripts/build.sh create mode 100755 scripts/monad-docker.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..5d8100dd23 --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +# default rule which passes all arguments to scripts/Makefile +.DEFAULT: + $(MAKE) -C scripts $(MAKECMDGOALS) diff --git a/scripts/build-run.sh b/scripts/build-run.sh deleted file mode 100755 index 6cc6199b3e..0000000000 --- a/scripts/build-run.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -CUID=$(id -u) -CUSER=$(id -un) -CGID=$(id -g) -CGROUP=$(id -gn) -DIR=/opt/monad-linux -VOLUME=$(dirname $(pwd))/:$DIR - -# creates new user in container matching the local user so that -# artifacts will be owned by the local user; set IMPERSONATE to false -# to disable and run as root, defaults to true -if [[ ! $IMPERSONATE ]]; then IMPERSONATE=true; fi -impersonate() -{ - if ! $IMPERSONATE; then return; fi - echo \ - groupadd -g $CGID $CGROUP '&&' \ - useradd -u $CUID -g $CGID -d $DIR $CUSER '&&' \ - sudo --set-home -u $CUSER -g $CGROUP -} - -docker run --rm \ - --volume $VOLUME \ - --workdir $DIR/scripts \ - $DOCKERFLAGS \ - andschwa/magrathea:latest \ - bash -c "$(impersonate) $*" diff --git a/scripts/build-tty.sh b/scripts/build-tty.sh deleted file mode 100755 index 311b786527..0000000000 --- a/scripts/build-tty.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -# Runs with a pseudo tty so that interactive shells can be opened -export DOCKERFLAGS="--interactive --tty" -./build-run.sh "$*" diff --git a/scripts/build.sh b/scripts/build.sh deleted file mode 100755 index 16175a2647..0000000000 --- a/scripts/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -# Runs by non-interactively, just attaches output -export DOCKERFLAGS="--attach STDOUT --attach STDERR" -./build-run.sh "$*" diff --git a/scripts/monad-docker.sh b/scripts/monad-docker.sh new file mode 100755 index 0000000000..a168d14920 --- /dev/null +++ b/scripts/monad-docker.sh @@ -0,0 +1,42 @@ +# docker run magrathea without tty +monad-run() +{ + monad-docker-run "--attach STDOUT --attach STDERR" $* +} + +# docker run magrathea with interactive tty +monad-tty() +{ + monad-docker-run "--interactive --tty" $* +} + +# runs ephemeral andschwa/magrathea docker container with local +# directory mounted to /opt and workdir set to /opt +monad-docker-run() +{ + local CONSOLE=$1 + shift 1 + docker run --rm \ + --volume $(pwd)/:/opt \ + --workdir /opt \ + $CONSOLE \ + andschwa/magrathea:latest \ + bash -c "$(monad-impersonate) -- bash -c '$*'" +} + +# creates new user in container matching the local user so that +# artifacts will be owned by the local user; set IMPERSONATE to false +# to disable and run as root, defaults to true +if [[ ! $IMPERSONATE ]]; then IMPERSONATE=true; fi +monad-impersonate() +{ + if ! $IMPERSONATE; then return; fi + local CUID=$(id -u) + local CUSER=$(id -un) + local CGID=$(id -g) + local CGROUP=$(id -gn) + echo \ + groupadd -g $CGID $CGROUP '&&' \ + useradd -u $CUID -g $CGID -d /opt $CUSER '&&' \ + sudo --set-home -u $CUSER -g $CGROUP +} From 80bc66eaaa25bf458be603bfb1bd3867f4ea9226 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Oct 2015 19:57:16 -0700 Subject: [PATCH 09/37] Remove deprecated scripts --- scripts/get-current-ref.sh | 5 ----- scripts/simplebuild.sh | 20 -------------------- 2 files changed, 25 deletions(-) delete mode 100755 scripts/get-current-ref.sh delete mode 100755 scripts/simplebuild.sh diff --git a/scripts/get-current-ref.sh b/scripts/get-current-ref.sh deleted file mode 100755 index 3921a21e45..0000000000 --- a/scripts/get-current-ref.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -branch=$(git for-each-ref --format=$'%(objectname) %(refname:short)' refs/heads | awk "/^$(git rev-parse HEAD)/ {print \$2}") -echo $branch - diff --git a/scripts/simplebuild.sh b/scripts/simplebuild.sh deleted file mode 100755 index e609bd8308..0000000000 --- a/scripts/simplebuild.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash - -if [ ! -d ext-src/cppunit ]; then - echo "Please call from root folder of project" - exit 1 -fi - -pushd ext-src/cppunit -./autogen.sh -CWD=$(pwd) -if [ -f Makefile ]; then - make distclean -fi -./configure LD=clang LDFLAGS="-stdlib=libc++" CXX=clang++ CC=clang CXXFLAGS="-stdlib=libc++" --prefix=$CWD/../../externals/cppunit -make -make install - -popd - - From 53cb7f8ffaa3adaaeb8159df1f01725430b2e00d Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Oct 2015 20:10:48 -0700 Subject: [PATCH 10/37] Alias shell to run-interactive --- scripts/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/Makefile b/scripts/Makefile index b335eb677b..2c14be4587 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -170,9 +170,11 @@ run: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # execute a cmdlet, this will auto-load the utility module and print a, b and c in 3 lines $(APP_BASE)/runps-simple.sh '"a","b","c","a","a" | Select-Object -Unique' -run-interactive: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +shell: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(APP_BASE)/runps.sh +run-interactive: shell + run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(APP_BASE)/runps.sh --file $(PSSCRIPT) From 487f7a5034c71a5445a2bcd18c33cb44d984e8dc Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 12 Oct 2015 21:26:53 -0700 Subject: [PATCH 11/37] Remove workaround for missing Reflection.Metadata - monad-ext updated to contain missing libraries - monad updated to remove workaround --- src/monad | 2 +- src/monad-ext | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/monad b/src/monad index 454f5ebc33..ef930a363b 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 454f5ebc3343cf764ed092392544c31dd3fbc375 +Subproject commit ef930a363b21180c02ee6148974d39938effa035 diff --git a/src/monad-ext b/src/monad-ext index dec304a9a8..210f7442f5 160000 --- a/src/monad-ext +++ b/src/monad-ext @@ -1 +1 @@ -Subproject commit dec304a9a8704f28176474072e83f439017bac6d +Subproject commit 210f7442f5c5eeae098f5205fb6a05756f164656 From 9b0ef11e2fa0f471222b08195df93a99c39f5620 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 12:55:38 -0700 Subject: [PATCH 12/37] Add "Hello World" exe target Compile with monad-run make HelloWorld.exe, given a HelloWorld.cs. Will compile with our .NET Core, and output how to run. Does not support multiple files. --- scripts/Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/Makefile b/scripts/Makefile index 2c14be4587..dd02ee83a8 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -182,6 +182,11 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr %.ps1: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr TEMP=/tmp $(APP_BASE)/runps.sh --file ../../$@ +# compiles "Hello World" like executables using .NET Core +%.exe: %.cs + $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $^ + @echo run with monad-tty ./scripts/exec_env/coreclr/corerun ./scripts/$@ + run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location From e95b3dc801c4e50bf41e8e0e7c8f13dcd2c27282 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 13:31:03 -0700 Subject: [PATCH 13/37] Fix mkdir --- scripts/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index dd02ee83a8..6870e746f9 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -130,10 +130,10 @@ dotnetlibs/api-ms-win-core-registry-l1-1-0.dll: ../src/win-dll/lib-api-ms-win-co nuget.exe: wget 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -buildtemp: - mkdir -p buildtemp +buildtemp dotnetlibs: + mkdir -p $@ -prepare: nuget.exe buildtemp +prepare: nuget.exe buildtemp dotnetlibs mono nuget.exe restore -PackagesDirectory buildtemp # this is the execution environment from which all managed code is run @@ -152,7 +152,6 @@ APP_BASE=exec_env/app_base internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) rm -rf exec_env mkdir -p $(APP_BASE)/Modules - mkdir -p exec_env/coreclr cp ../src/monad/monad/miscfiles/display/*.ps1xml $(APP_BASE) cp ../src/monad/monad/miscfiles/types/CoreClr/*.ps1xml $(APP_BASE) cp -r ../src/monad/monad/miscfiles/modules/* $(APP_BASE)/Modules @@ -164,6 +163,7 @@ internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) cp runps*.sh $(APP_BASE) internal-prepare-clr: + mkdir -p exec_env/coreclr cp -r $(CORECLR_ASSEMBLY_BASE)/* exec_env/coreclr/ run: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr @@ -183,7 +183,7 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr TEMP=/tmp $(APP_BASE)/runps.sh --file ../../$@ # compiles "Hello World" like executables using .NET Core -%.exe: %.cs +%.exe: %.cs internal-prepare-clr $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $^ @echo run with monad-tty ./scripts/exec_env/coreclr/corerun ./scripts/$@ From 16db74fb3ea071c84fde5cc5480185fc8d33692f Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 13:36:35 -0700 Subject: [PATCH 14/37] Build from scripts again --- Makefile | 3 --- scripts/monad-docker.sh | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 5d8100dd23..0000000000 --- a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -# default rule which passes all arguments to scripts/Makefile -.DEFAULT: - $(MAKE) -C scripts $(MAKECMDGOALS) diff --git a/scripts/monad-docker.sh b/scripts/monad-docker.sh index a168d14920..a38bd41af1 100755 --- a/scripts/monad-docker.sh +++ b/scripts/monad-docker.sh @@ -11,14 +11,14 @@ monad-tty() } # runs ephemeral andschwa/magrathea docker container with local -# directory mounted to /opt and workdir set to /opt +# directory mounted to /opt and workdir set to /opt/scripts monad-docker-run() { local CONSOLE=$1 shift 1 docker run --rm \ - --volume $(pwd)/:/opt \ - --workdir /opt \ + --volume $(dirname $(pwd))/:/opt \ + --workdir /opt/scripts \ $CONSOLE \ andschwa/magrathea:latest \ bash -c "$(monad-impersonate) -- bash -c '$*'" From e483e449ad8f2d7442c2e32afbf4752686694523 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 13:39:52 -0700 Subject: [PATCH 15/37] Add build.sh back as wrapper to monad-run Fixes CI and lets us remove it at a later date. --- scripts/build.sh | 4 ++++ 1 file changed, 4 insertions(+) create mode 100755 scripts/build.sh diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100755 index 0000000000..ede2218072 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +source monad-docker.sh +monad-run $* From 3284c33f85295080eaa95d13e3c378ce3fb649e6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 13:41:39 -0700 Subject: [PATCH 16/37] Fix "Hello World" target --- scripts/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 6870e746f9..ed3d0649d1 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -183,8 +183,8 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr TEMP=/tmp $(APP_BASE)/runps.sh --file ../../$@ # compiles "Hello World" like executables using .NET Core -%.exe: %.cs internal-prepare-clr - $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $^ +%.exe: %.cs prepare internal-prepare-clr + $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $< @echo run with monad-tty ./scripts/exec_env/coreclr/corerun ./scripts/$@ run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr From acce65c680bf1bf8449bd391e0138b79f4912b4e Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 14:19:09 -0700 Subject: [PATCH 17/37] Add basic Hello World program for easier testing We can use this to assert simple things about .NET Core (our build in particular) for easier debugging. --- scripts/HelloWorld.cs | 9 +++++++++ scripts/Makefile | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 scripts/HelloWorld.cs diff --git a/scripts/HelloWorld.cs b/scripts/HelloWorld.cs new file mode 100644 index 0000000000..49fe647088 --- /dev/null +++ b/scripts/HelloWorld.cs @@ -0,0 +1,9 @@ +using System; + +internal class Program +{ + private static void Main() + { + Console.WriteLine("Hello World!"); + } +} diff --git a/scripts/Makefile b/scripts/Makefile index ed3d0649d1..a8bff344ad 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -185,7 +185,7 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # compiles "Hello World" like executables using .NET Core %.exe: %.cs prepare internal-prepare-clr $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $< - @echo run with monad-tty ./scripts/exec_env/coreclr/corerun ./scripts/$@ + @echo run with monad-tty ./exec_env/coreclr/corerun ./$@ run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location From 87988c7beaee263c25953aa9da202f5b92ef6fa6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 15:25:39 -0700 Subject: [PATCH 18/37] Enable XML output for Pester - Taught Git to ignore XML output - Updated Pester submodule with fixes - Enabled reporting in Pester Makefile target --- .gitignore | 1 + ext-src/pester | 2 +- scripts/Makefile | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0a218c43ec..bd0413d9ca 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ Makefile !scripts/Makefile cmake_install.cmake scripts/xunittests.xml +scripts/pestertests.xml scripts/powershell.inc .bash_history diff --git a/ext-src/pester b/ext-src/pester index dc5d388532..1232fc67a6 160000 --- a/ext-src/pester +++ b/ext-src/pester @@ -1 +1 @@ -Subproject commit dc5d388532499267e68c17c0a96153f7bc09c437 +Subproject commit 1232fc67a6a4b04a38cf6f9b14f3f9b77db34ccf diff --git a/scripts/Makefile b/scripts/Makefile index a8bff344ad..cce8a6bb01 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -210,7 +210,7 @@ xunit-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(add pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # execute the Pester tests, which needs a TEMP environment variable to be set - $(APP_BASE)/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester' + $(APP_BASE)/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile ../../scripts/pestertests.xml -OutputFormat NUnitXml' hashbang-tests: all # execute the 3rdparty/hashbang example From 72e9a1fed05cf8b8e2bb96cb61152688427b2148 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 19:33:08 -0700 Subject: [PATCH 19/37] Add pestertests.xml to cleanall target --- scripts/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Makefile b/scripts/Makefile index cce8a6bb01..ade23a8601 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -234,7 +234,7 @@ clean: # clean built stuff + prepare step cleanall: clean clean-native - rm -rf buildtemp xunittests.xml + rm -rf buildtemp xunittests.xml pestertests.xml docker-build: docker build --no-cache=false -t image_ps . From 34dcc5c0596db55432a983af13b30b926f510551 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 19:48:58 -0700 Subject: [PATCH 20/37] Enable XML output for native tests --- .gitignore | 3 +-- scripts/Makefile | 14 +++++--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index bd0413d9ca..612fd5995c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ CMakeFiles/ Makefile !scripts/Makefile cmake_install.cmake -scripts/xunittests.xml -scripts/pestertests.xml +scripts/*tests.xml scripts/powershell.inc .bash_history diff --git a/scripts/Makefile b/scripts/Makefile index ade23a8601..71efdf7f77 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -101,8 +101,7 @@ powershell.inc: CorePsTypeCatalog.cs: powershell.inc buildtemp/TypeCatalogGen.exe MONO_PATH=$(dir $(REFLECTION_METADATA)):$(dir $(COLLECTIONS_IMMUTABLE)) mono buildtemp/TypeCatalogGen.exe $< $@ $(MONAD_EXT)/coreclr/TargetingPack -# the pinvoke library libps.so - +# the native library, libps.so LIBPS_BUILD=buildtemp/libps-build $(LIBPS_BUILD)/Makefile: ../src/monad-native/src/CMakeLists.txt mkdir -p $(LIBPS_BUILD) @@ -117,8 +116,9 @@ $(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile mkdir -p dotnetlibs cp $(addprefix $(LIBPS_BUILD)/, $(notdir $@)) dotnetlibs -libps.so-test: $(addprefix dotnetlibs/, libps.so monad_native) - cd dotnetlibs && LD_LIBRARY_PATH=. ./monad_native +# C++ tests for monad-native +native-tests: dotnetlibs/monad_native + cd dotnetlibs && ./monad_native --gtest_output="xml:../nativetests.xml" # this is a windows dll that is needed because CoreCLR tries to access # registry functions that don't exist on Linux and there is no other good @@ -190,10 +190,6 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location -native-tests: dotnetlibs/monad_native - # execute the native C++ tests - cd dotnetlibs && ./monad_native - # xUnit tests TEST_FOLDER=../src/ps_test TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_*.cs) @@ -234,7 +230,7 @@ clean: # clean built stuff + prepare step cleanall: clean clean-native - rm -rf buildtemp xunittests.xml pestertests.xml + rm -rf buildtemp *tests.xml docker-build: docker build --no-cache=false -t image_ps . From 8f39b0a809b37f80fee09fe99d2a51a151a2bac0 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 13 Oct 2015 19:57:51 -0700 Subject: [PATCH 21/37] Rename XML test results --- .gitignore | 2 +- scripts/Makefile | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 612fd5995c..16092215a9 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,6 @@ CMakeFiles/ Makefile !scripts/Makefile cmake_install.cmake -scripts/*tests.xml +scripts/*-tests.xml scripts/powershell.inc .bash_history diff --git a/scripts/Makefile b/scripts/Makefile index 71efdf7f77..6eb73e3427 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -116,9 +116,10 @@ $(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile mkdir -p dotnetlibs cp $(addprefix $(LIBPS_BUILD)/, $(notdir $@)) dotnetlibs -# C++ tests for monad-native +# C++ tests for monad-native - results in native-tests.xml +# see https://github.com/google/googletest native-tests: dotnetlibs/monad_native - cd dotnetlibs && ./monad_native --gtest_output="xml:../nativetests.xml" + cd dotnetlibs && ./monad_native --gtest_output="xml:../native-tests.xml" # this is a windows dll that is needed because CoreCLR tries to access # registry functions that don't exist on Linux and there is no other good @@ -190,7 +191,8 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location -# xUnit tests +# xUnit tests for PowerShell - results in xunit-tests.xml +# see https://xunit.github.io/ TEST_FOLDER=../src/ps_test TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_*.cs) @@ -201,12 +203,13 @@ $(APP_BASE)/ps_test.dll: prepare $(TEST_SRCS) $(addprefix $(APP_BASE)/, xunit.co $(CSC) $(CSCOPTS_LIB) -out:$@ $(addprefix -r:$(APP_BASE)/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, System.Management.Automation.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) $(COREREF) $(TEST_SRCS) xunit-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(addprefix $(APP_BASE)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) - # execute the xUnit runner, with XML output - $(APP_BASE)/runps-test.sh ps_test.dll -xml ../../xunittests.xml + $(APP_BASE)/runps-test.sh ps_test.dll -xml ../../xunit-tests.xml +# Pester tests for PowerShell - results in pester-tests.xml +# see https://github.com/pester/Pester +# requires $TEMP to be set pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr - # execute the Pester tests, which needs a TEMP environment variable to be set - $(APP_BASE)/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile ../../scripts/pestertests.xml -OutputFormat NUnitXml' + $(APP_BASE)/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile ../../scripts/pester-tests.xml -OutputFormat NUnitXml' hashbang-tests: all # execute the 3rdparty/hashbang example From 2657db72789e034b700a9544ed867d29501b89b1 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 08:58:01 -0700 Subject: [PATCH 22/37] Fix IMPERSONATE=false --- scripts/monad-docker.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/monad-docker.sh b/scripts/monad-docker.sh index a38bd41af1..e99b6505a3 100755 --- a/scripts/monad-docker.sh +++ b/scripts/monad-docker.sh @@ -21,7 +21,7 @@ monad-docker-run() --workdir /opt/scripts \ $CONSOLE \ andschwa/magrathea:latest \ - bash -c "$(monad-impersonate) -- bash -c '$*'" + bash -c "$(monad-impersonate) bash -c '$*'" } # creates new user in container matching the local user so that @@ -38,5 +38,5 @@ monad-impersonate() echo \ groupadd -g $CGID $CGROUP '&&' \ useradd -u $CUID -g $CGID -d /opt $CUSER '&&' \ - sudo --set-home -u $CUSER -g $CGROUP + sudo --set-home -u $CUSER -g $CGROUP -- } From 3f82f7a4fb6238c6778b330944d9364201bec5f3 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 08:58:16 -0700 Subject: [PATCH 23/37] Remove PRODUCT_BASE_REFS --- scripts/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 6eb73e3427..adbb4dbf1a 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -30,7 +30,6 @@ MI_REF_ASSEMBLY=-r:$(MONAD_EXT)/PS/PS_refs_modil/microsoft.management.infrastruc MI_ASSEMBLY=dotnetlibs/Microsoft.Management.Infrastructure.dll MI_REF=-r:$(MI_ASSEMBLY) -PRODUCT_BASE_REFS=$(COREREF) PRODUCT_MI_REFS=$(COREREF) $(MI_NATIVE_REF) PRODUCT_PS_REFS=$(COREREF) $(MI_REF) -r:dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) PRODUCT_COMMANDS_REFS=$(COREREF) -r:dotnetlibs/System.Management.Automation.dll @@ -71,12 +70,12 @@ dotnetlibs/Microsoft.PowerShell.Security.dll: prepare $(SECURITY_SRCS) $(SECURIT # assembly load context dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET): prepare $(ASSEMBLY_LOAD_CONTEXT_SRCS) - $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_BASE_REFS) $(ASSEMBLY_LOAD_CONTEXT_SRCS) + $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(ASSEMBLY_LOAD_CONTEXT_SRCS) # this one is built from stubs MI_STUBS=../src/stubs/Microsoft.Management.Infrastructure.Native-stub.cs ../src/stubs/Microsoft.Management.Infrastructure.Native-stub-assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.Native.dll: prepare $(MI_STUBS) - $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_BASE_REFS) $(MI_STUBS) + $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(MI_STUBS) # this creates the type catalog generator MPATH=/usr/lib/mono/4.5/Facades From 5d9c7c6d5fc6c3b56c915ff74503c7b3ee2739de Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 09:57:08 -0700 Subject: [PATCH 24/37] Refactor prepare target for non-phony buildtemp - buildtemp, being non-phony, won't cause a recompilation every run - rearranged where appropriate for better use of $< --- scripts/Makefile | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index adbb4dbf1a..a49c2bc637 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -49,39 +49,39 @@ RUN_TARGETS=$(POWERSHELL_RUN_TARGETS) $(addprefix dotnetlibs/, Microsoft.PowerSh all: dotnetlibs/System.Management.Automation.dll $(RUN_TARGETS) dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) # this is the build rule for SMA.dll -dotnetlibs/System.Management.Automation.dll: prepare $(SYS_AUTO_SRCS) dotnetlibs/Microsoft.Management.Infrastructure.dll ../src/assembly-info/System.Management.Automation.assembly-info.cs dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) $(SYS_AUTO_RES_SRCS) $(SYS_AUTO_RES_CS_SRCS) - $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_PS_REFS) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_REF) $(SYS_AUTO_RES_CS_SRCS) ../src/assembly-info/System.Management.Automation.assembly-info.cs +dotnetlibs/System.Management.Automation.dll: ../src/assembly-info/System.Management.Automation.assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.dll dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_SRCS) $(SYS_AUTO_RES_CS_SRCS) buildtemp + $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_PS_REFS) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_REF) $(SYS_AUTO_RES_CS_SRCS) $< # this is the build rule for MMI.dll -dotnetlibs/Microsoft.Management.Infrastructure.dll: prepare $(MAN_INFRA_SRCS) dotnetlibs/Microsoft.Management.Infrastructure.Native.dll ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs $(MAN_INFRA_RES_SRCS) $(MAN_INFRA_RES_CS_SRCS) - $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_MI_REFS) $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_REF) $(MAN_INFRA_RES_CS_SRCS) ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs +dotnetlibs/Microsoft.Management.Infrastructure.dll: ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.Native.dll $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_SRCS) $(MAN_INFRA_RES_CS_SRCS) buildtemp + $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_MI_REFS) $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_CS_SRCS) $(MAN_INFRA_RES_REF) $< # Commands -dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: prepare $(COMMANDS_MANAGEMENT_SRCS) dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Security.dll $(COMMANDS_MANAGEMENT_RES_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) $(MI_ASSEMBLY) - $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(COMMANDS_MANAGEMENT_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) $(COMMANDS_MANAGEMENT_RES_REF) $(MI_REF) -r:dotnetlibs/Microsoft.PowerShell.Security.dll +dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Security.dll $(MI_ASSEMBLY) $(COMMANDS_MANAGEMENT_SRCS) $(COMMANDS_MANAGEMENT_RES_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) buildtemp + $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(MI_REF) $(COMMANDS_MANAGEMENT_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) $(COMMANDS_MANAGEMENT_RES_REF) -r:dotnetlibs/Microsoft.PowerShell.Security.dll -dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: prepare $(COMMANDS_UTILITY_SRCS) dotnetlibs/System.Management.Automation.dll $(COMMANDS_UTILITY_RES_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) +dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: dotnetlibs/System.Management.Automation.dll $(COMMANDS_UTILITY_SRCS) $(COMMANDS_UTILITY_RES_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(COMMANDS_UTILITY_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) $(COMMANDS_UTILITY_RES_REF) -dotnetlibs/Microsoft.PowerShell.Security.dll: prepare $(SECURITY_SRCS) $(SECURITY_RES_SRCS) $(SECURITY_RES_CS_SRCS) +dotnetlibs/Microsoft.PowerShell.Security.dll: $(SECURITY_SRCS) $(SECURITY_RES_SRCS) $(SECURITY_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(SECURITY_SRCS) $(SECURITY_RES_CS_SRCS) $(SECURITY_RES_REF) # assembly load context -dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET): prepare $(ASSEMBLY_LOAD_CONTEXT_SRCS) +dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET): $(ASSEMBLY_LOAD_CONTEXT_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(ASSEMBLY_LOAD_CONTEXT_SRCS) # this one is built from stubs MI_STUBS=../src/stubs/Microsoft.Management.Infrastructure.Native-stub.cs ../src/stubs/Microsoft.Management.Infrastructure.Native-stub-assembly-info.cs -dotnetlibs/Microsoft.Management.Infrastructure.Native.dll: prepare $(MI_STUBS) +dotnetlibs/Microsoft.Management.Infrastructure.Native.dll: $(MI_STUBS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(MI_STUBS) # this creates the type catalog generator MPATH=/usr/lib/mono/4.5/Facades REFLECTION_METADATA=buildtemp/System.Reflection.Metadata.1.0.22/lib/dotnet/System.Reflection.Metadata.dll COLLECTIONS_IMMUTABLE=buildtemp/System.Collections.Immutable.1.1.37/lib/dotnet/System.Collections.Immutable.dll -buildtemp/TypeCatalogGen.exe: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) +buildtemp/TypeCatalogGen.exe: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) buildtemp $(MCS) -out:$@ -target:exe -pkg:dotnet $(addprefix -r:, $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) $(MPATH)/System.Runtime.dll $(MPATH)/System.Reflection.Primitives.dll $(MPATH)/System.IO.dll) $< # this generates the necessary file of CoreCLR references that is an artifact of the Windows build process @@ -103,16 +103,15 @@ CorePsTypeCatalog.cs: powershell.inc buildtemp/TypeCatalogGen.exe # the native library, libps.so LIBPS_BUILD=buildtemp/libps-build $(LIBPS_BUILD)/Makefile: ../src/monad-native/src/CMakeLists.txt - mkdir -p $(LIBPS_BUILD) # cached files can change the path to be incorrect, this must be cleaned rm -f ../src/monad-native/src/CMakeCache.txt rm -f ../src/monad-native/src/cmake_install.cmake + mkdir -p $(LIBPS_BUILD) cd $(LIBPS_BUILD) && cmake ../../../src/monad-native/src/ NATIVE_BINARIES=libps.so monad_native host_cmdline -$(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile +$(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile dotnetlibs $(MAKE) -j -C $(LIBPS_BUILD) - mkdir -p dotnetlibs cp $(addprefix $(LIBPS_BUILD)/, $(notdir $@)) dotnetlibs # C++ tests for monad-native - results in native-tests.xml @@ -124,16 +123,17 @@ native-tests: dotnetlibs/monad_native # registry functions that don't exist on Linux and there is no other good # way of fixing this right now # (TODO linux: this should be removed by addressing it in CoreCLR) -dotnetlibs/api-ms-win-core-registry-l1-1-0.dll: ../src/win-dll/lib-api-ms-win-core-registry-l1-1-0.c - gcc -o $@ -fPIC -shared -Wall $^ +dotnetlibs/api-ms-win-core-registry-l1-1-0.dll: ../src/win-dll/lib-api-ms-win-core-registry-l1-1-0.c dotnetlibs + gcc -o $@ -fPIC -shared -Wall $< nuget.exe: wget 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -buildtemp dotnetlibs: +dotnetlibs: mkdir -p $@ -prepare: nuget.exe buildtemp dotnetlibs +buildtemp: nuget.exe dotnetlibs + mkdir -p $@ mono nuget.exe restore -PackagesDirectory buildtemp # this is the execution environment from which all managed code is run @@ -183,7 +183,7 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr TEMP=/tmp $(APP_BASE)/runps.sh --file ../../$@ # compiles "Hello World" like executables using .NET Core -%.exe: %.cs prepare internal-prepare-clr +%.exe: %.cs internal-prepare-clr buildtemp $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $< @echo run with monad-tty ./exec_env/coreclr/corerun ./$@ @@ -198,7 +198,7 @@ TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_*.cs) $(APP_BASE)/xunit%: $(MONAD_EXT)/xunit/xunit% cp -f $^ $@ -$(APP_BASE)/ps_test.dll: prepare $(TEST_SRCS) $(addprefix $(APP_BASE)/, xunit.core.dll xunit.assert.dll) $(addprefix dotnetlibs/, System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) +$(APP_BASE)/ps_test.dll: $(TEST_SRCS) $(addprefix $(APP_BASE)/, xunit.core.dll xunit.assert.dll) $(addprefix dotnetlibs/, System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) buildtemp $(CSC) $(CSCOPTS_LIB) -out:$@ $(addprefix -r:$(APP_BASE)/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, System.Management.Automation.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) $(COREREF) $(TEST_SRCS) xunit-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(addprefix $(APP_BASE)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) @@ -230,7 +230,7 @@ clean-native: clean: rm -rf dotnetlibs exec_env powershell.inc -# clean built stuff + prepare step +# clean built stuff + buildtemp step cleanall: clean clean-native rm -rf buildtemp *tests.xml From 9394a4cae8cb5c691e8aac25c798e0926e87b234 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Wed, 14 Oct 2015 13:36:05 -0700 Subject: [PATCH 25/37] Adding a new test utility file that contains mocks and functions --- src/pester-tests/Test-Mocks.ps1 | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/pester-tests/Test-Mocks.ps1 diff --git a/src/pester-tests/Test-Mocks.ps1 b/src/pester-tests/Test-Mocks.ps1 new file mode 100644 index 0000000000..183e0d148e --- /dev/null +++ b/src/pester-tests/Test-Mocks.ps1 @@ -0,0 +1,18 @@ +Function GetFileMock () { + $objs = @( [pscustomobject]@{ Size=4533816; Mode="-a---l"; LastWriteTime="9/1/2015 11:15 PM"; Name="explorer.exe" }, + [pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" }, + [pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" }, + [pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" }, + [pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" }, + [pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" }) + return $objs +} + +filter addOne() { + $_.Size += 1 + $_ +} + +filter pipelineConsume() { + $_ +} From b038ccf3658f29cc1e0402274c38fec8026cba49 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Wed, 14 Oct 2015 13:37:42 -0700 Subject: [PATCH 26/37] Add new pester test for Select-Object cmdlet --- src/pester-tests/Test-Select-Object.Tests.ps1 | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/pester-tests/Test-Select-Object.Tests.ps1 diff --git a/src/pester-tests/Test-Select-Object.Tests.ps1 b/src/pester-tests/Test-Select-Object.Tests.ps1 new file mode 100644 index 0000000000..b53e3b6be8 --- /dev/null +++ b/src/pester-tests/Test-Select-Object.Tests.ps1 @@ -0,0 +1,94 @@ +. ../../../src/pester-tests/Test-Mocks.ps1 + +Describe "Select-Object" { + BeforeEach { + $o=GetFileMock + $TestLength = 3 + } + + It "Handle piped input without error" { + { $o | Test-Path } | Should Not Throw + } + + It "-inputObject parameter should treats object as a single object" { + $(Select-Object -inputObject $o -last $TestLength).Length | Should Be $o.Length + } + + It "Should be able to use the alias" { + { $o | select } | Should Not Throw + { $o | select } | Should Not BeNullOrEmpty + } + + It "-First parameter should return correct object" { + $r = $o | Select-Object -First $TestLength + $r.Length | Should Be $TestLength + for ($i=0; $i -lt $TestLength; $i++) + { + $r[$i].Name | Should Be $o[$i].Name + } + } + + It "-Last parameter should return correct object" { + $r = $o | Select-Object -Last $TestLength + $r.Length | Should Be $TestLength + for ($i=0; $i -lt $TestLength; $i++) + { + $r[$i].Name | Should Be $o[$o.Length - $TestLength + $i].Name + } + } + + It "-Unique parameter should work correctly" { + ("a","b","c","a","a","a" | Select-Object -Unique).Length | Should Be 3 + } + + It "-Skip parameter should return correct object" { + $r = $o | Select-Object -Skip $TestLength + $r.Length | Should Be ($o.Length - $TestLength) + for ($i=0; $i -lt $TestLength; $i++) + { + $r[$i].Name | Should Be $o[$TestLength + $i].Name + } + } + + It "-Property parameter should return an object with selected columns" { + $r = $o | Select-Object -Property Name, Size + $r.Length | Should Be $o.Length + $r[0].Name | Should Be $o[0].Name + $r[0].Size | Should Be $o[0].Size + $r[0].Mode | Should BeNullOrEmpty + } + + It "Select-Object should send output to pipe properly" { + {$o | Select-Object -Unique | pipelineConsume} | Should Not Throw + } + + It "-Index parameter should select array indices" { + $firstIndex = 2 + $secondIndex = 4 + $r = $o | Select-Object -Index $firstIndex, $secondIndex + $r[0].Name | Should Be $o[$firstIndex].Name + $r[1].Name | Should Be $o[$secondIndex].Name + } + + # Note that these two tests will modify original values of $o + + It "-First option does not wait when used without -Wait option" { + $orig1 = $o[0].Size + $orig2 = $o[$TestLength].Size + $r = $o | addOne | Select-Object -First $TestLength + $r[0].Size | Should Be ($orig1 + 1) + $o[0].Size | Should Be ($orig1 + 1) + $o[$TestLength].Size | Should Be $orig2 + } + + It "-First option does wait when used with -Wait option" { + $orig1 = $o[0].Size + $orig2 = $o[$TestLength].Size + $r = $o | addOne | Select-Object -First $TestLength -Wait + $r[0].Size | Should Be ($orig1 + 1) + $o[0].Size | Should Be ($orig1 + 1) + $o[$TestLength].Size | Should Be ($orig2 + 1) + } +} + + From 304df08fd7101cc19642e86b35f4c9ff00197fc6 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 14:03:01 -0700 Subject: [PATCH 27/37] Refactor use of dotnetlibs for reduced rebuilding Also cleaned up Makefiles. Added `scripts/dotnetlibs` back to Git so Make doesn't ever have to create it (now I understand Peter's reasoning here). --- .gitignore | 12 +++++------- scripts/.gitignore | 26 +++++--------------------- scripts/Makefile | 19 +++++++++---------- scripts/dotnetlibs/.gitignore | 1 + 4 files changed, 20 insertions(+), 38 deletions(-) create mode 100644 scripts/dotnetlibs/.gitignore diff --git a/.gitignore b/.gitignore index 16092215a9..d41f12ba70 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,9 @@ .idea -.config/ -.local/ CMakeCache.txt CMakeFiles/ -Makefile -!scripts/Makefile cmake_install.cmake -scripts/*-tests.xml -scripts/powershell.inc -.bash_history +Makefile +!/scripts/Makefile +/.bash_history +/.local/ +/.config/ diff --git a/scripts/.gitignore b/scripts/.gitignore index 6b1b27ea78..d4e3fc14ef 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -1,24 +1,8 @@ -System.Collections.Immutable.*/ -System.Reflection.Metadata.*/ -Microsoft.Net.ToolsetCompilers.*/ -dotnetlibs/ -gen-all-files.txt -monad-src.diff -output.txt -string-resources-files.txt -string-resources-orig.txt -xunit.abstractions.*/ -xunit.core.*/ -xunit.extensibility.core.*/ -xunit.runner.console.*/ -TypeCatalogGen.exe -System.Collections.Immutable.dll -System.Reflection.Metadata.dll -commands-management-win.mk -commands-utility-win.mk -management-infrastructure-win.mk -system-automation-win.mk +*.txt +*.exe +*-tests.xml +*-win.mk CorePsTypeCatalog.cs +powershell.inc buildtemp/ exec_env/ - diff --git a/scripts/Makefile b/scripts/Makefile index a49c2bc637..b618553842 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -110,7 +110,7 @@ $(LIBPS_BUILD)/Makefile: ../src/monad-native/src/CMakeLists.txt cd $(LIBPS_BUILD) && cmake ../../../src/monad-native/src/ NATIVE_BINARIES=libps.so monad_native host_cmdline -$(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile dotnetlibs +$(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile $(MAKE) -j -C $(LIBPS_BUILD) cp $(addprefix $(LIBPS_BUILD)/, $(notdir $@)) dotnetlibs @@ -129,16 +129,11 @@ dotnetlibs/api-ms-win-core-registry-l1-1-0.dll: ../src/win-dll/lib-api-ms-win-co nuget.exe: wget 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' -dotnetlibs: - mkdir -p $@ - -buildtemp: nuget.exe dotnetlibs +# this creates the build output directories and restores packages from NuGet +buildtemp: nuget.exe mkdir -p $@ mono nuget.exe restore -PackagesDirectory buildtemp -# this is the execution environment from which all managed code is run -APP_BASE=exec_env/app_base - # this is an internal target, it's not intended to be called manually # # it will: @@ -149,6 +144,10 @@ APP_BASE=exec_env/app_base # # This rule does not copy coreclr, because the selection of debug or # release CoreCLR depends on the actual run target. + +# this is the execution environment from which all managed code is run +APP_BASE=exec_env/app_base + internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) rm -rf exec_env mkdir -p $(APP_BASE)/Modules @@ -228,11 +227,11 @@ clean-native: rm -rf buildtemp/libps-build clean: - rm -rf dotnetlibs exec_env powershell.inc + rm -rf dotnetlibs/* exec_env powershell.inc *-tests.xml # clean built stuff + buildtemp step cleanall: clean clean-native - rm -rf buildtemp *tests.xml + rm -rf buildtemp docker-build: docker build --no-cache=false -t image_ps . diff --git a/scripts/dotnetlibs/.gitignore b/scripts/dotnetlibs/.gitignore new file mode 100644 index 0000000000..72e8ffc0db --- /dev/null +++ b/scripts/dotnetlibs/.gitignore @@ -0,0 +1 @@ +* From a6006be8549e53941663b699106ef8239c7bc53d Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 14:05:52 -0700 Subject: [PATCH 28/37] Move libps build out of buildtemp --- scripts/.gitignore | 1 + scripts/Makefile | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/.gitignore b/scripts/.gitignore index d4e3fc14ef..8110e6a848 100644 --- a/scripts/.gitignore +++ b/scripts/.gitignore @@ -6,3 +6,4 @@ CorePsTypeCatalog.cs powershell.inc buildtemp/ exec_env/ +libps/ diff --git a/scripts/Makefile b/scripts/Makefile index b618553842..944b4e532d 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -101,13 +101,13 @@ CorePsTypeCatalog.cs: powershell.inc buildtemp/TypeCatalogGen.exe MONO_PATH=$(dir $(REFLECTION_METADATA)):$(dir $(COLLECTIONS_IMMUTABLE)) mono buildtemp/TypeCatalogGen.exe $< $@ $(MONAD_EXT)/coreclr/TargetingPack # the native library, libps.so -LIBPS_BUILD=buildtemp/libps-build +LIBPS_BUILD=libps $(LIBPS_BUILD)/Makefile: ../src/monad-native/src/CMakeLists.txt # cached files can change the path to be incorrect, this must be cleaned rm -f ../src/monad-native/src/CMakeCache.txt rm -f ../src/monad-native/src/cmake_install.cmake mkdir -p $(LIBPS_BUILD) - cd $(LIBPS_BUILD) && cmake ../../../src/monad-native/src/ + cd $(LIBPS_BUILD) && cmake ../../src/monad-native/src/ NATIVE_BINARIES=libps.so monad_native host_cmdline $(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile @@ -224,7 +224,7 @@ debug: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # clean native library, libps clean-native: - rm -rf buildtemp/libps-build + rm -rf $(LIBPS_BUILD) clean: rm -rf dotnetlibs/* exec_env powershell.inc *-tests.xml From 64f34638c2a5ec9c2f35b45602ba11dd64417989 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Wed, 14 Oct 2015 14:15:03 -0700 Subject: [PATCH 29/37] Improved readability of some variables --- src/pester-tests/Test-Select-Object.Tests.ps1 | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/pester-tests/Test-Select-Object.Tests.ps1 b/src/pester-tests/Test-Select-Object.Tests.ps1 index b53e3b6be8..d66c5270a1 100644 --- a/src/pester-tests/Test-Select-Object.Tests.ps1 +++ b/src/pester-tests/Test-Select-Object.Tests.ps1 @@ -1,39 +1,39 @@ -. ../../../src/pester-tests/Test-Mocks.ps1 +. ./Test-Mocks.ps1 Describe "Select-Object" { BeforeEach { - $o=GetFileMock + $dirObject=GetFileMock $TestLength = 3 } It "Handle piped input without error" { - { $o | Test-Path } | Should Not Throw + { $dirObject | Test-Path } | Should Not Throw } It "-inputObject parameter should treats object as a single object" { - $(Select-Object -inputObject $o -last $TestLength).Length | Should Be $o.Length + $(Select-Object -inputObject $dirObject -last $TestLength).Length | Should Be $dirObject.Length } It "Should be able to use the alias" { - { $o | select } | Should Not Throw - { $o | select } | Should Not BeNullOrEmpty + { $dirObject | select } | Should Not Throw + { $dirObject | select } | Should Not BeNullOrEmpty } It "-First parameter should return correct object" { - $r = $o | Select-Object -First $TestLength - $r.Length | Should Be $TestLength + $result = $dirObject | Select-Object -First $TestLength + $result.Length | Should Be $TestLength for ($i=0; $i -lt $TestLength; $i++) { - $r[$i].Name | Should Be $o[$i].Name + $result[$i].Name | Should Be $dirObject[$i].Name } } It "-Last parameter should return correct object" { - $r = $o | Select-Object -Last $TestLength - $r.Length | Should Be $TestLength + $result = $dirObject | Select-Object -Last $TestLength + $result.Length | Should Be $TestLength for ($i=0; $i -lt $TestLength; $i++) { - $r[$i].Name | Should Be $o[$o.Length - $TestLength + $i].Name + $result[$i].Name | Should Be $dirObject[$dirObject.Length - $TestLength + $i].Name } } @@ -42,52 +42,52 @@ Describe "Select-Object" { } It "-Skip parameter should return correct object" { - $r = $o | Select-Object -Skip $TestLength - $r.Length | Should Be ($o.Length - $TestLength) + $result = $dirObject | Select-Object -Skip $TestLength + $result.Length | Should Be ($dirObject.Length - $TestLength) for ($i=0; $i -lt $TestLength; $i++) { - $r[$i].Name | Should Be $o[$TestLength + $i].Name + $result[$i].Name | Should Be $dirObject[$TestLength + $i].Name } } It "-Property parameter should return an object with selected columns" { - $r = $o | Select-Object -Property Name, Size - $r.Length | Should Be $o.Length - $r[0].Name | Should Be $o[0].Name - $r[0].Size | Should Be $o[0].Size - $r[0].Mode | Should BeNullOrEmpty + $result = $dirObject | Select-Object -Property Name, Size + $result.Length | Should Be $dirObject.Length + $result[0].Name | Should Be $dirObject[0].Name + $result[0].Size | Should Be $dirObject[0].Size + $result[0].Mode | Should BeNullOrEmpty } It "Select-Object should send output to pipe properly" { - {$o | Select-Object -Unique | pipelineConsume} | Should Not Throw + {$dirObject | Select-Object -Unique | pipelineConsume} | Should Not Throw } It "-Index parameter should select array indices" { $firstIndex = 2 $secondIndex = 4 - $r = $o | Select-Object -Index $firstIndex, $secondIndex - $r[0].Name | Should Be $o[$firstIndex].Name - $r[1].Name | Should Be $o[$secondIndex].Name + $result = $dirObject | Select-Object -Index $firstIndex, $secondIndex + $result[0].Name | Should Be $dirObject[$firstIndex].Name + $result[1].Name | Should Be $dirObject[$secondIndex].Name } - # Note that these two tests will modify original values of $o + # Note that these two tests will modify original values of $dirObject It "-First option does not wait when used without -Wait option" { - $orig1 = $o[0].Size - $orig2 = $o[$TestLength].Size - $r = $o | addOne | Select-Object -First $TestLength - $r[0].Size | Should Be ($orig1 + 1) - $o[0].Size | Should Be ($orig1 + 1) - $o[$TestLength].Size | Should Be $orig2 + $orig1 = $dirObject[0].Size + $orig2 = $dirObject[$TestLength].Size + $result = $dirObject | addOne | Select-Object -First $TestLength + $result[0].Size | Should Be ($orig1 + 1) + $dirObject[0].Size | Should Be ($orig1 + 1) + $dirObject[$TestLength].Size | Should Be $orig2 } It "-First option does wait when used with -Wait option" { - $orig1 = $o[0].Size - $orig2 = $o[$TestLength].Size - $r = $o | addOne | Select-Object -First $TestLength -Wait - $r[0].Size | Should Be ($orig1 + 1) - $o[0].Size | Should Be ($orig1 + 1) - $o[$TestLength].Size | Should Be ($orig2 + 1) + $orig1 = $dirObject[0].Size + $orig2 = $dirObject[$TestLength].Size + $result = $dirObject | addOne | Select-Object -First $TestLength -Wait + $result[0].Size | Should Be ($orig1 + 1) + $dirObject[0].Size | Should Be ($orig1 + 1) + $dirObject[$TestLength].Size | Should Be ($orig2 + 1) } } From 504d2c327ee91bd5d488ac491b263f2a9a5501e7 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 14:17:34 -0700 Subject: [PATCH 30/37] Refactor xUnit build `ps_test.dll` is now built in dotnetlibs, and copied along with xUnit libraries during `internal-prepare-exec_env`. Build process now creates things only as needed. --- scripts/Makefile | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 944b4e532d..f20f546021 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -159,6 +159,7 @@ internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) cp -r dotnetlibs/*.so $(APP_BASE) cp dotnetlibs/host_cmdline $(APP_BASE) cp -r ../ext-src/pester $(APP_BASE)/Modules/Pester + cp -r $(MONAD_EXT)/xunit/xunit* $(APP_BASE) cp runps*.sh $(APP_BASE) internal-prepare-clr: @@ -193,14 +194,12 @@ run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # see https://xunit.github.io/ TEST_FOLDER=../src/ps_test TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_*.cs) +TEST_TARGETS=System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET) -$(APP_BASE)/xunit%: $(MONAD_EXT)/xunit/xunit% - cp -f $^ $@ +dotnetlibs/ps_test.dll: $(TEST_SRCS) $(addprefix dotnetlibs/, $(TEST_TARGETS)) buildtemp + $(CSC) $(CSCOPTS_LIB) -out:$@ $(addprefix -r:$(MONAD_EXT)/xunit/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, $(TEST_TARGETS)) $(COREREF) $(TEST_SRCS) -$(APP_BASE)/ps_test.dll: $(TEST_SRCS) $(addprefix $(APP_BASE)/, xunit.core.dll xunit.assert.dll) $(addprefix dotnetlibs/, System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) buildtemp - $(CSC) $(CSCOPTS_LIB) -out:$@ $(addprefix -r:$(APP_BASE)/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, System.Management.Automation.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)) $(COREREF) $(TEST_SRCS) - -xunit-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(addprefix $(APP_BASE)/, ps_test.dll xunit.console.netcore.exe xunit.runner.utility.dll xunit.abstractions.dll xunit.execution.dll) +xunit-tests: dotnetlibs/ps_test.dll $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr $(APP_BASE)/runps-test.sh ps_test.dll -xml ../../xunit-tests.xml # Pester tests for PowerShell - results in pester-tests.xml From f5fcc965629208941c9926cf9a30210e9f3cb5f0 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 19:13:45 -0700 Subject: [PATCH 31/37] Fix missing dependency for PowerShell.Security.dll --- scripts/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index f20f546021..4586339617 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -61,10 +61,10 @@ dotnetlibs/Microsoft.Management.Infrastructure.dll: ../src/assembly-info/Microso dotnetlibs/Microsoft.PowerShell.Commands.Management.dll: dotnetlibs/System.Management.Automation.dll dotnetlibs/Microsoft.PowerShell.Security.dll $(MI_ASSEMBLY) $(COMMANDS_MANAGEMENT_SRCS) $(COMMANDS_MANAGEMENT_RES_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(MI_REF) $(COMMANDS_MANAGEMENT_SRCS) $(COMMANDS_MANAGEMENT_RES_CS_SRCS) $(COMMANDS_MANAGEMENT_RES_REF) -r:dotnetlibs/Microsoft.PowerShell.Security.dll -dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: dotnetlibs/System.Management.Automation.dll $(COMMANDS_UTILITY_SRCS) $(COMMANDS_UTILITY_RES_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) buildtemp +dotnetlibs/Microsoft.PowerShell.Commands.Utility.dll: dotnetlibs/System.Management.Automation.dll $(COMMANDS_UTILITY_SRCS) $(COMMANDS_UTILITY_RES_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(COMMANDS_UTILITY_SRCS) $(COMMANDS_UTILITY_RES_CS_SRCS) $(COMMANDS_UTILITY_RES_REF) -dotnetlibs/Microsoft.PowerShell.Security.dll: $(SECURITY_SRCS) $(SECURITY_RES_SRCS) $(SECURITY_RES_CS_SRCS) buildtemp +dotnetlibs/Microsoft.PowerShell.Security.dll: dotnetlibs/System.Management.Automation.dll $(SECURITY_SRCS) $(SECURITY_RES_SRCS) $(SECURITY_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(SECURITY_SRCS) $(SECURITY_RES_CS_SRCS) $(SECURITY_RES_REF) # assembly load context From c8f76b62812f2422dd21443dd52f55ea7028bb64 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 19:31:11 -0700 Subject: [PATCH 32/37] Factor out relative paths in Makefile They make for terrible headaches. --- scripts/Makefile | 56 ++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 4586339617..d555ec9b5e 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -1,10 +1,8 @@ -.PHONY: all - -# this should go away and be automatically generated -include assembly-load-context.mk +# the monad-linux superproject +MONAD=$(realpath $(CURDIR)/..) # main references to the CoreCLR reference assemblies -MONAD_EXT=../src/monad-ext +MONAD_EXT=$(MONAD)/src/monad-ext TARGETING_PACK=$(MONAD_EXT)/coreclr/TargetingPack COREREF=$(addprefix -r:, $(shell ls $(TARGETING_PACK)/*.dll)) CORECLR_ASSEMBLY_BASE=$(MONAD_EXT)/coreclr/Runtime @@ -13,7 +11,7 @@ CORECLR_ASSEMBLY_BASE=$(MONAD_EXT)/coreclr/Runtime include powershell-run.mk # this variable is needed by module specific include makefiles below -ADMIN_GIT_ROOT=../src/monad +ADMIN_GIT_ROOT=$(MONAD)/src/monad # these are automatically generated from the PowerShell build sytem # - System.Management.Automation.dll (the main PS dll) @@ -25,6 +23,10 @@ include commands-utility.mk include management-infrastructure.mk include security.mk +# this should go away and be automatically generated +include assembly-load-context.mk + +# reference sets for the PowerShell assemblies MI_NATIVE_REF=-r:dotnetlibs/Microsoft.Management.Infrastructure.Native.dll MI_REF_ASSEMBLY=-r:$(MONAD_EXT)/PS/PS_refs_modil/microsoft.management.infrastructure.metadata_dll MI_ASSEMBLY=dotnetlibs/Microsoft.Management.Infrastructure.dll @@ -46,14 +48,15 @@ CSCOPTS_LIB_PS=$(CSCOPTS_LIB) -unsafe -define:CORECLR -define:_CORECLR /nowarn:C RUN_TARGETS=$(POWERSHELL_RUN_TARGETS) $(addprefix dotnetlibs/, Microsoft.PowerShell.Commands.Management.dll Microsoft.PowerShell.Commands.Utility.dll Microsoft.PowerShell.Security.dll api-ms-win-core-registry-l1-1-0.dll host_cmdline) +.PHONY: all all: dotnetlibs/System.Management.Automation.dll $(RUN_TARGETS) dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) # this is the build rule for SMA.dll -dotnetlibs/System.Management.Automation.dll: ../src/assembly-info/System.Management.Automation.assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.dll dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_SRCS) $(SYS_AUTO_RES_CS_SRCS) buildtemp +dotnetlibs/System.Management.Automation.dll: $(MONAD)/src/assembly-info/System.Management.Automation.assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.dll dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_SRCS) $(SYS_AUTO_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_PS_REFS) $(SYS_AUTO_SRCS) $(SYS_AUTO_RES_REF) $(SYS_AUTO_RES_CS_SRCS) $< # this is the build rule for MMI.dll -dotnetlibs/Microsoft.Management.Infrastructure.dll: ../src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.Native.dll $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_SRCS) $(MAN_INFRA_RES_CS_SRCS) buildtemp +dotnetlibs/Microsoft.Management.Infrastructure.dll: $(MONAD)/src/assembly-info/Microsoft.Management.Infrastructure.assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.Native.dll $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_SRCS) $(MAN_INFRA_RES_CS_SRCS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_MI_REFS) $(MAN_INFRA_SRCS) $(MAN_INFRA_RES_CS_SRCS) $(MAN_INFRA_RES_REF) $< # Commands @@ -73,7 +76,7 @@ dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET): $(ASSEMBLY_LOAD_CONTEXT_SRCS) buildt $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(ASSEMBLY_LOAD_CONTEXT_SRCS) # this one is built from stubs -MI_STUBS=../src/stubs/Microsoft.Management.Infrastructure.Native-stub.cs ../src/stubs/Microsoft.Management.Infrastructure.Native-stub-assembly-info.cs +MI_STUBS=$(MONAD)/src/stubs/Microsoft.Management.Infrastructure.Native-stub.cs $(MONAD)/src/stubs/Microsoft.Management.Infrastructure.Native-stub-assembly-info.cs dotnetlibs/Microsoft.Management.Infrastructure.Native.dll: $(MI_STUBS) buildtemp $(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(MI_STUBS) @@ -81,7 +84,7 @@ dotnetlibs/Microsoft.Management.Infrastructure.Native.dll: $(MI_STUBS) buildtemp MPATH=/usr/lib/mono/4.5/Facades REFLECTION_METADATA=buildtemp/System.Reflection.Metadata.1.0.22/lib/dotnet/System.Reflection.Metadata.dll COLLECTIONS_IMMUTABLE=buildtemp/System.Collections.Immutable.1.1.37/lib/dotnet/System.Collections.Immutable.dll -buildtemp/TypeCatalogGen.exe: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) buildtemp +buildtemp/TypeCatalogGen.exe: $(ADMIN_GIT_ROOT)/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) buildtemp $(MCS) -out:$@ -target:exe -pkg:dotnet $(addprefix -r:, $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) $(MPATH)/System.Runtime.dll $(MPATH)/System.Reflection.Primitives.dll $(MPATH)/System.IO.dll) $< # this generates the necessary file of CoreCLR references that is an artifact of the Windows build process @@ -96,18 +99,19 @@ powershell.inc: @echo '$(PROFILE_REFERENCES)' >> $@ # generate the Core PS type catalog -# this comes from: ../src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/makefile.inc +# this comes from: $(MONAD)/src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/makefile.inc CorePsTypeCatalog.cs: powershell.inc buildtemp/TypeCatalogGen.exe MONO_PATH=$(dir $(REFLECTION_METADATA)):$(dir $(COLLECTIONS_IMMUTABLE)) mono buildtemp/TypeCatalogGen.exe $< $@ $(MONAD_EXT)/coreclr/TargetingPack # the native library, libps.so +MONAD_NATIVE=$(MONAD)/src/monad-native/src LIBPS_BUILD=libps -$(LIBPS_BUILD)/Makefile: ../src/monad-native/src/CMakeLists.txt +$(LIBPS_BUILD)/Makefile: $(MONAD_NATIVE)/CMakeLists.txt # cached files can change the path to be incorrect, this must be cleaned - rm -f ../src/monad-native/src/CMakeCache.txt - rm -f ../src/monad-native/src/cmake_install.cmake + rm -f $(MONAD_NATIVE)/CMakeCache.txt + rm -f $(MONAD_NATIVE)/cmake_install.cmake mkdir -p $(LIBPS_BUILD) - cd $(LIBPS_BUILD) && cmake ../../src/monad-native/src/ + cd $(LIBPS_BUILD) && cmake $(MONAD_NATIVE) NATIVE_BINARIES=libps.so monad_native host_cmdline $(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile @@ -117,13 +121,13 @@ $(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile # C++ tests for monad-native - results in native-tests.xml # see https://github.com/google/googletest native-tests: dotnetlibs/monad_native - cd dotnetlibs && ./monad_native --gtest_output="xml:../native-tests.xml" + cd dotnetlibs && ./monad_native --gtest_output="xml:$(MONAD)/scripts/native-tests.xml" # this is a windows dll that is needed because CoreCLR tries to access # registry functions that don't exist on Linux and there is no other good # way of fixing this right now # (TODO linux: this should be removed by addressing it in CoreCLR) -dotnetlibs/api-ms-win-core-registry-l1-1-0.dll: ../src/win-dll/lib-api-ms-win-core-registry-l1-1-0.c dotnetlibs +dotnetlibs/api-ms-win-core-registry-l1-1-0.dll: $(MONAD)/src/win-dll/lib-api-ms-win-core-registry-l1-1-0.c dotnetlibs gcc -o $@ -fPIC -shared -Wall $< nuget.exe: @@ -151,14 +155,14 @@ APP_BASE=exec_env/app_base internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) rm -rf exec_env mkdir -p $(APP_BASE)/Modules - cp ../src/monad/monad/miscfiles/display/*.ps1xml $(APP_BASE) - cp ../src/monad/monad/miscfiles/types/CoreClr/*.ps1xml $(APP_BASE) - cp -r ../src/monad/monad/miscfiles/modules/* $(APP_BASE)/Modules + cp $(ADMIN_GIT_ROOT)/monad/miscfiles/display/*.ps1xml $(APP_BASE) + cp $(ADMIN_GIT_ROOT)/monad/miscfiles/types/CoreClr/*.ps1xml $(APP_BASE) + cp -r $(ADMIN_GIT_ROOT)/monad/miscfiles/modules/* $(APP_BASE)/Modules cp -r dotnetlibs/*.dll $(APP_BASE) cp -r dotnetlibs/*.exe $(APP_BASE) cp -r dotnetlibs/*.so $(APP_BASE) cp dotnetlibs/host_cmdline $(APP_BASE) - cp -r ../ext-src/pester $(APP_BASE)/Modules/Pester + cp -r $(MONAD)/ext-src/pester $(APP_BASE)/Modules/Pester cp -r $(MONAD_EXT)/xunit/xunit* $(APP_BASE) cp runps*.sh $(APP_BASE) @@ -180,7 +184,7 @@ run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # easy way to run individual PowerShell scripts, `make script.ps1` where the path is relative to monad-linux/scripts (with TEMP set for Pester) %.ps1: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr - TEMP=/tmp $(APP_BASE)/runps.sh --file ../../$@ + TEMP=/tmp $(APP_BASE)/runps.sh --file $(MONAD)/scripts/$@ # compiles "Hello World" like executables using .NET Core %.exe: %.cs internal-prepare-clr buildtemp @@ -192,7 +196,7 @@ run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr # xUnit tests for PowerShell - results in xunit-tests.xml # see https://xunit.github.io/ -TEST_FOLDER=../src/ps_test +TEST_FOLDER=$(MONAD)/src/ps_test TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_*.cs) TEST_TARGETS=System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET) @@ -200,17 +204,17 @@ dotnetlibs/ps_test.dll: $(TEST_SRCS) $(addprefix dotnetlibs/, $(TEST_TARGETS)) b $(CSC) $(CSCOPTS_LIB) -out:$@ $(addprefix -r:$(MONAD_EXT)/xunit/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, $(TEST_TARGETS)) $(COREREF) $(TEST_SRCS) xunit-tests: dotnetlibs/ps_test.dll $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr - $(APP_BASE)/runps-test.sh ps_test.dll -xml ../../xunit-tests.xml + $(APP_BASE)/runps-test.sh ps_test.dll -xml $(MONAD)/scripts/xunit-tests.xml # Pester tests for PowerShell - results in pester-tests.xml # see https://github.com/pester/Pester # requires $TEMP to be set pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr - $(APP_BASE)/runps-simple.sh 'cd ../../../src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile ../../scripts/pester-tests.xml -OutputFormat NUnitXml' + $(APP_BASE)/runps-simple.sh 'cd $(MONAD)/src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile $(MONAD)/scripts/pester-tests.xml -OutputFormat NUnitXml' hashbang-tests: all # execute the 3rdparty/hashbang example - PATH=$(PATH):$(shell pwd)/$(APP_BASE) $(shell pwd)/3rdparty/hashbang/script.ps1 + PATH=$(PATH):$(MONAD)/scripts/$(APP_BASE) $(MONAD)/scripts/3rdparty/hashbang/script.ps1 test: native-tests xunit-tests pester-tests hashbang-tests From 6c47d78821f2114421d2f1b639e79df1dcf92d12 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 22:32:14 -0700 Subject: [PATCH 33/37] Refactor exec_env setup, can now build in parallel With dependencies setup correctly, `make -j` now works as expected. `prepare` target came back under a new role, to setup the application base and CoreCLR in the execution environment. Note that `$(APP_BASE)` is a phony target because we always want a clean deployment. Cannot `rm -rf exec_env` because it conflicts with `$(CORECLR)` when run in parallel. --- scripts/Makefile | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index d555ec9b5e..49a4d1f025 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -138,9 +138,7 @@ buildtemp: nuget.exe mkdir -p $@ mono nuget.exe restore -PackagesDirectory buildtemp -# this is an internal target, it's not intended to be called manually -# -# it will: +# this is a phony target that will: # - create necessary directories for deployment layout # - copy all the PowerShell stuff into PowerShell's app_base # - copy the custom host and other scripts into PowerShell's app_base @@ -148,12 +146,14 @@ buildtemp: nuget.exe # # This rule does not copy coreclr, because the selection of debug or # release CoreCLR depends on the actual run target. +# - copy xUnit libraries # this is the execution environment from which all managed code is run APP_BASE=exec_env/app_base -internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) - rm -rf exec_env +.PHONY: $(APP_BASE) +$(APP_BASE): runps.sh $(POWERSHELL_RUN_TARGETS) + rm -rf $@ mkdir -p $(APP_BASE)/Modules cp $(ADMIN_GIT_ROOT)/monad/miscfiles/display/*.ps1xml $(APP_BASE) cp $(ADMIN_GIT_ROOT)/monad/miscfiles/types/CoreClr/*.ps1xml $(APP_BASE) @@ -166,32 +166,36 @@ internal-prepare-exec_env: runps.sh $(POWERSHELL_RUN_TARGETS) cp -r $(MONAD_EXT)/xunit/xunit* $(APP_BASE) cp runps*.sh $(APP_BASE) -internal-prepare-clr: - mkdir -p exec_env/coreclr - cp -r $(CORECLR_ASSEMBLY_BASE)/* exec_env/coreclr/ +CORECLR=exec_env/coreclr +$(CORECLR): + rm -rf $@ + mkdir -p $@ + cp -r $(CORECLR_ASSEMBLY_BASE)/* $@ -run: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +prepare: $(APP_BASE) $(CORECLR) + +run: $(RUN_TARGETS) prepare # execute a cmdlet, this will auto-load the utility module and print a, b and c in 3 lines $(APP_BASE)/runps-simple.sh '"a","b","c","a","a" | Select-Object -Unique' -shell: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +shell: $(RUN_TARGETS) prepare $(APP_BASE)/runps.sh run-interactive: shell -run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +run-file: $(RUN_TARGETS) prepare $(APP_BASE)/runps.sh --file $(PSSCRIPT) # easy way to run individual PowerShell scripts, `make script.ps1` where the path is relative to monad-linux/scripts (with TEMP set for Pester) -%.ps1: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +%.ps1: $(RUN_TARGETS) prepare TEMP=/tmp $(APP_BASE)/runps.sh --file $(MONAD)/scripts/$@ # compiles "Hello World" like executables using .NET Core -%.exe: %.cs internal-prepare-clr buildtemp +%.exe: %.cs $(CORECLR) buildtemp $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $< - @echo run with monad-tty ./exec_env/coreclr/corerun ./$@ + @echo run with monad-tty ./$(CORECLR)/corerun ./$@ -run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +run-debugclr: $(RUN_TARGETS) prepare PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location # xUnit tests for PowerShell - results in xunit-tests.xml @@ -203,25 +207,25 @@ TEST_TARGETS=System.Management.Automation.dll Microsoft.PowerShell.Commands.Mana dotnetlibs/ps_test.dll: $(TEST_SRCS) $(addprefix dotnetlibs/, $(TEST_TARGETS)) buildtemp $(CSC) $(CSCOPTS_LIB) -out:$@ $(addprefix -r:$(MONAD_EXT)/xunit/, xunit.core.dll xunit.assert.dll) $(addprefix -r:dotnetlibs/, $(TEST_TARGETS)) $(COREREF) $(TEST_SRCS) -xunit-tests: dotnetlibs/ps_test.dll $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +xunit-tests: dotnetlibs/ps_test.dll $(RUN_TARGETS) prepare $(APP_BASE)/runps-test.sh ps_test.dll -xml $(MONAD)/scripts/xunit-tests.xml # Pester tests for PowerShell - results in pester-tests.xml # see https://github.com/pester/Pester # requires $TEMP to be set -pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +pester-tests: $(RUN_TARGETS) prepare $(APP_BASE)/runps-simple.sh 'cd $(MONAD)/src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile $(MONAD)/scripts/pester-tests.xml -OutputFormat NUnitXml' -hashbang-tests: all - # execute the 3rdparty/hashbang example +# 3rdparty "hashbang" example using runps-file +hashbang-tests: all prepare PATH=$(PATH):$(MONAD)/scripts/$(APP_BASE) $(MONAD)/scripts/3rdparty/hashbang/script.ps1 test: native-tests xunit-tests pester-tests hashbang-tests -trace: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +trace: $(RUN_TARGETS) prepare $(APP_BASE)/runps-simple-trace.sh get-location -debug: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr +debug: $(RUN_TARGETS) prepare # quoting here is a bit special if strings are passed in, because lldb seems to forward arguments strangely $(APP_BASE)/runps-simple-debug.sh get-location From 49a2b29b030e5ad59bc16f09c2f42c71eac40c56 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 14 Oct 2015 22:38:06 -0700 Subject: [PATCH 34/37] Clean up cruft --- scripts/Makefile | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/Makefile b/scripts/Makefile index 49a4d1f025..499aead303 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -143,9 +143,6 @@ buildtemp: nuget.exe # - copy all the PowerShell stuff into PowerShell's app_base # - copy the custom host and other scripts into PowerShell's app_base # - copy PS modules -# -# This rule does not copy coreclr, because the selection of debug or -# release CoreCLR depends on the actual run target. # - copy xUnit libraries # this is the execution environment from which all managed code is run @@ -195,9 +192,6 @@ run-file: $(RUN_TARGETS) prepare $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $< @echo run with monad-tty ./$(CORECLR)/corerun ./$@ -run-debugclr: $(RUN_TARGETS) prepare - PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location - # xUnit tests for PowerShell - results in xunit-tests.xml # see https://xunit.github.io/ TEST_FOLDER=$(MONAD)/src/ps_test @@ -222,24 +216,33 @@ hashbang-tests: all prepare test: native-tests xunit-tests pester-tests hashbang-tests +# debug/trace targets + trace: $(RUN_TARGETS) prepare $(APP_BASE)/runps-simple-trace.sh get-location +run-debugclr: $(RUN_TARGETS) prepare + PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location + +# quoting here is a bit special if strings are passed in, because lldb +# seems to forward arguments strangely debug: $(RUN_TARGETS) prepare - # quoting here is a bit special if strings are passed in, because lldb seems to forward arguments strangely $(APP_BASE)/runps-simple-debug.sh get-location -# clean native library, libps +# Cleaning +.PHONY: clean-native clean cleanall + clean-native: rm -rf $(LIBPS_BUILD) clean: rm -rf dotnetlibs/* exec_env powershell.inc *-tests.xml -# clean built stuff + buildtemp step cleanall: clean clean-native rm -rf buildtemp +# Shell-in-a-box Docker setup + docker-build: docker build --no-cache=false -t image_ps . $(eval INSTANCE_ID := $(shell docker inspect -f '{{.Id}}' image_ps)) From a352f21316f1fd244a26f7eddefeb82cc162a3c3 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 15 Oct 2015 10:11:17 -0700 Subject: [PATCH 35/37] Changes per pull request 182 comments --- src/pester-tests/Test-Mocks.ps1 | 12 +-- src/pester-tests/Test-Select-Object.Tests.ps1 | 80 ++++++++++++------- 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/src/pester-tests/Test-Mocks.ps1 b/src/pester-tests/Test-Mocks.ps1 index 183e0d148e..4b6a3e8876 100644 --- a/src/pester-tests/Test-Mocks.ps1 +++ b/src/pester-tests/Test-Mocks.ps1 @@ -1,14 +1,14 @@ Function GetFileMock () { $objs = @( [pscustomobject]@{ Size=4533816; Mode="-a---l"; LastWriteTime="9/1/2015 11:15 PM"; Name="explorer.exe" }, - [pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" }, - [pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" }, - [pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" }, - [pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" }, - [pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" }) + [pscustomobject]@{ Size=994816; Mode="-a---l"; LastWriteTime="9/1/2015 11:13 PM"; Name="HelpPane.exe" }, + [pscustomobject]@{ Size=316640; Mode="-a---l"; LastWriteTime="9/1/2015 11:17 PM"; Name="WMSysPr9.prx" }, + [pscustomobject]@{ Size=215040; Mode="-a---l"; LastWriteTime="9/1/2015 11:20 PM"; Name="notepad.exe" }, + [pscustomobject]@{ Size=207239; Mode="-a----"; LastWriteTime="10/7/2015 2:37 PM"; Name="setupact.log" }, + [pscustomobject]@{ Size=181064; Mode="-a----"; LastWriteTime="9/9/2015 11:54 PM"; Name="PSEXESVC.EXE" }) return $objs } -filter addOne() { +filter addOneToSizeProperty() { $_.Size += 1 $_ } diff --git a/src/pester-tests/Test-Select-Object.Tests.ps1 b/src/pester-tests/Test-Select-Object.Tests.ps1 index d66c5270a1..e0192ac09f 100644 --- a/src/pester-tests/Test-Select-Object.Tests.ps1 +++ b/src/pester-tests/Test-Select-Object.Tests.ps1 @@ -2,91 +2,113 @@ Describe "Select-Object" { BeforeEach { - $dirObject=GetFileMock + $dirObject = GetFileMock $TestLength = 3 } It "Handle piped input without error" { - { $dirObject | Test-Path } | Should Not Throw + { $dirObject | Select-Object } | Should Not Throw } - It "-inputObject parameter should treats object as a single object" { - $(Select-Object -inputObject $dirObject -last $TestLength).Length | Should Be $dirObject.Length + It "Should treat input as a single object with the inputObject parameter" { + $result = $(Select-Object -inputObject $dirObject -last $TestLength).Length + $expected = $dirObject.Length + + $result | Should Be $expected } It "Should be able to use the alias" { { $dirObject | select } | Should Not Throw - { $dirObject | select } | Should Not BeNullOrEmpty } - It "-First parameter should return correct object" { + It "Should have same result when using alias" { + $result = $dirObject | select + $expected = $dirObject | Select-Object + + $result | Should Be $expected + } + + It "Should return correct object with First parameter" { $result = $dirObject | Select-Object -First $TestLength + $result.Length | Should Be $TestLength + for ($i=0; $i -lt $TestLength; $i++) { $result[$i].Name | Should Be $dirObject[$i].Name } } - It "-Last parameter should return correct object" { + It "Should return correct object with Last parameter" { $result = $dirObject | Select-Object -Last $TestLength + $result.Length | Should Be $TestLength + for ($i=0; $i -lt $TestLength; $i++) { $result[$i].Name | Should Be $dirObject[$dirObject.Length - $TestLength + $i].Name } } - It "-Unique parameter should work correctly" { - ("a","b","c","a","a","a" | Select-Object -Unique).Length | Should Be 3 + It "Should work correctly with Unique parameter" { + $result = ("a","b","c","a","a","a" | Select-Object -Unique).Length + $expected = 3 + + $result | Should Be $expected } - It "-Skip parameter should return correct object" { + It "Should return correct object with Skip parameter" { $result = $dirObject | Select-Object -Skip $TestLength - $result.Length | Should Be ($dirObject.Length - $TestLength) + + $result.Length | Should Be ($dirObject.Length - $TestLength) + for ($i=0; $i -lt $TestLength; $i++) { $result[$i].Name | Should Be $dirObject[$TestLength + $i].Name } } - It "-Property parameter should return an object with selected columns" { + It "Should return an object with selected columns" { $result = $dirObject | Select-Object -Property Name, Size - $result.Length | Should Be $dirObject.Length + + $result.Length | Should Be $dirObject.Length $result[0].Name | Should Be $dirObject[0].Name $result[0].Size | Should Be $dirObject[0].Size $result[0].Mode | Should BeNullOrEmpty } - It "Select-Object should send output to pipe properly" { + It "Should send output to pipe properly" { {$dirObject | Select-Object -Unique | pipelineConsume} | Should Not Throw } - It "-Index parameter should select array indices" { - $firstIndex = 2 + It "Should select array indices with Index parameter" { + $firstIndex = 2 $secondIndex = 4 - $result = $dirObject | Select-Object -Index $firstIndex, $secondIndex + $result = $dirObject | Select-Object -Index $firstIndex, $secondIndex + $result[0].Name | Should Be $dirObject[$firstIndex].Name $result[1].Name | Should Be $dirObject[$secondIndex].Name } # Note that these two tests will modify original values of $dirObject - It "-First option does not wait when used without -Wait option" { - $orig1 = $dirObject[0].Size - $orig2 = $dirObject[$TestLength].Size - $result = $dirObject | addOne | Select-Object -First $TestLength - $result[0].Size | Should Be ($orig1 + 1) - $dirObject[0].Size | Should Be ($orig1 + 1) + It "Should not wait when used without -Wait option" { + $orig1 = $dirObject[0].Size + $orig2 = $dirObject[$TestLength].Size + $result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength + + $result[0].Size | Should Be ($orig1 + 1) + $dirObject[0].Size | Should Be ($orig1 + 1) $dirObject[$TestLength].Size | Should Be $orig2 } - It "-First option does wait when used with -Wait option" { - $orig1 = $dirObject[0].Size - $orig2 = $dirObject[$TestLength].Size - $result = $dirObject | addOne | Select-Object -First $TestLength -Wait - $result[0].Size | Should Be ($orig1 + 1) - $dirObject[0].Size | Should Be ($orig1 + 1) + It "Should wait when used with -Wait option" { + $orig1 = $dirObject[0].Size + $orig2 = $dirObject[$TestLength].Size + $result = $dirObject | addOneToSizeProperty | Select-Object -First $TestLength -Wait + + $result[0].Size | Should Be ($orig1 + 1) + $dirObject[0].Size | Should Be ($orig1 + 1) $dirObject[$TestLength].Size | Should Be ($orig2 + 1) } } From f6e6a75cf56665df1e729d48243314e785546c47 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 15 Oct 2015 13:50:03 -0700 Subject: [PATCH 36/37] Add src/monad-omi-provider --- .gitmodules | 3 +++ src/monad-omi-provider | 1 + 2 files changed, 4 insertions(+) create mode 160000 src/monad-omi-provider diff --git a/.gitmodules b/.gitmodules index 5b79583008..0adbb8a1b3 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "ext-src/pester"] path = ext-src/pester url = https://msostc.visualstudio.com/DefaultCollection/PS/_git/Pester +[submodule "src/monad-omi-provider"] + path = src/monad-omi-provider + url = https://msostc.visualstudio.com/DefaultCollection/PS/_git/monad-omi-provider diff --git a/src/monad-omi-provider b/src/monad-omi-provider new file mode 160000 index 0000000000..7c7307925b --- /dev/null +++ b/src/monad-omi-provider @@ -0,0 +1 @@ +Subproject commit 7c7307925b81420bb6d8520a51bc759b4d52ea0a From 2473bf0ce45fc1cfc1dbc38795859396f415d8b7 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Thu, 15 Oct 2015 13:53:42 -0700 Subject: [PATCH 37/37] Add src/omi submodule at OMI-Shell/OMI-PSRP-Support --- .gitmodules | 4 ++++ src/omi | 1 + 2 files changed, 5 insertions(+) create mode 160000 src/omi diff --git a/.gitmodules b/.gitmodules index 0adbb8a1b3..61529ee9ff 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,3 +16,7 @@ [submodule "src/monad-omi-provider"] path = src/monad-omi-provider url = https://msostc.visualstudio.com/DefaultCollection/PS/_git/monad-omi-provider +[submodule "src/omi"] + path = src/omi + url = https://msostc.visualstudio.com/DefaultCollection/PS/_git/omi + branch = OMI-Shell/OMI-PSRP-Support diff --git a/src/omi b/src/omi new file mode 160000 index 0000000000..1f81decc6a --- /dev/null +++ b/src/omi @@ -0,0 +1 @@ +Subproject commit 1f81decc6a74f1de619659a4dd8359b66814189b