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 b335eb677b..a8bff344ad 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,15 +163,18 @@ 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 # 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) @@ -180,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 prepare internal-prepare-clr + $(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $< + @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 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 index 16175a2647..ede2218072 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# Runs by non-interactively, just attaches output -export DOCKERFLAGS="--attach STDOUT --attach STDERR" -./build-run.sh "$*" +source monad-docker.sh +monad-run $* 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/monad-docker.sh b/scripts/monad-docker.sh new file mode 100755 index 0000000000..a38bd41af1 --- /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/scripts +monad-docker-run() +{ + local CONSOLE=$1 + shift 1 + docker run --rm \ + --volume $(dirname $(pwd))/:/opt \ + --workdir /opt/scripts \ + $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 +} 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 - -