Files
PowerShell/scripts/Makefile
T

257 lines
13 KiB
Makefile
Raw Normal View History

2015-10-14 19:31:11 -07:00
# the monad-linux superproject
MONAD=$(realpath $(CURDIR)/..)
2015-06-03 10:33:16 -07:00
# main references to the CoreCLR reference assemblies
2015-10-14 19:31:11 -07:00
MONAD_EXT=$(MONAD)/src/monad-ext
2015-09-18 12:39:05 -07:00
TARGETING_PACK=$(MONAD_EXT)/coreclr/TargetingPack
COREREF=$(addprefix -r:, $(shell ls $(TARGETING_PACK)/*.dll))
2015-10-06 15:13:29 -07:00
CORECLR_ASSEMBLY_BASE=$(MONAD_EXT)/coreclr/Runtime
# powershell-run is the main powershell executable
include powershell-run.mk
2015-09-18 12:39:05 -07:00
# this variable is needed by module specific include makefiles below
2015-10-14 19:31:11 -07:00
ADMIN_GIT_ROOT=$(MONAD)/src/monad
2015-09-18 12:39:05 -07:00
# these are automatically generated from the PowerShell build sytem
2015-06-03 10:33:16 -07:00
# - System.Management.Automation.dll (the main PS dll)
# - commands/modules (they contain cmdlets): management and utility
# - Microsoft.Management.Infrastructure.dll (the first dll in the remoting code paths)
include system-automation.mk
include commands-management.mk
include commands-utility.mk
include management-infrastructure.mk
2015-07-09 16:02:58 -07:00
include security.mk
2015-10-14 19:31:11 -07:00
# 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
MI_REF=-r:$(MI_ASSEMBLY)
2015-09-03 14:55:21 -07:00
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
# compilers
# - Roslyn's csc is used for all the PS code
# - Mono's mcs is used for build helper tools
2015-10-07 13:05:58 -07:00
CSC=mono buildtemp/Microsoft.Net.Compilers.1.0.0/tools/csc.exe
MCS=mcs
2015-09-18 12:39:05 -07:00
CSCOPTS_BASE=-noconfig -nostdlib
CSCOPTS_LIB=$(CSCOPTS_BASE) -target:library
CSCOPTS_LIB_PS=$(CSCOPTS_LIB) -unsafe -define:CORECLR -define:_CORECLR /nowarn:CS1701,CS1702
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)
2015-10-14 19:31:11 -07:00
.PHONY: all
all: dotnetlibs/System.Management.Automation.dll $(RUN_TARGETS) dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET)
2015-06-10 11:11:41 -07:00
# this is the build rule for SMA.dll
2015-10-14 19:31:11 -07:00
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) $<
2015-06-10 11:11:41 -07:00
# this is the build rule for MMI.dll
2015-10-14 19:31:11 -07:00
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
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
2015-09-18 12:39:05 -07:00
$(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: dotnetlibs/System.Management.Automation.dll $(SECURITY_SRCS) $(SECURITY_RES_SRCS) $(SECURITY_RES_CS_SRCS) buildtemp
2015-09-18 12:39:05 -07:00
$(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(PRODUCT_COMMANDS_REFS) $(SECURITY_SRCS) $(SECURITY_RES_CS_SRCS) $(SECURITY_RES_REF)
2015-07-09 16:02:58 -07:00
# assembly load context
dotnetlibs/$(ASSEMBLY_LOAD_CONTEXT_TARGET): $(ASSEMBLY_LOAD_CONTEXT_SRCS) buildtemp
2015-10-14 08:58:16 -07:00
$(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(ASSEMBLY_LOAD_CONTEXT_SRCS)
# this one is built from stubs
2015-10-14 19:31:11 -07:00
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
2015-10-14 08:58:16 -07:00
$(CSC) -out:$@ $(CSCOPTS_LIB_PS) $(COREREF) $(MI_STUBS)
2015-10-07 13:05:58 -07:00
# this creates the type catalog generator
MPATH=/usr/lib/mono/4.5/Facades
2015-10-07 13:05:58 -07:00
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
2015-10-14 19:31:11 -07:00
buildtemp/TypeCatalogGen.exe: $(ADMIN_GIT_ROOT)/monad/nttargets/assemblies/core/PSAssemblyLoadContext/TypeCatalogGen/TypeCatalogGen.cs $(REFLECTION_METADATA) $(COLLECTIONS_IMMUTABLE) buildtemp
2015-10-07 13:05:58 -07:00
$(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
# since we don't have Make 4.1, we can't use $(file), and using @echo makes the escaping tricky
# the list of references MUST be line-by-line, to match '^\$\(PS_PROFILE_REF_PATH\)\\(.+);\s*\\$'
REFERENCE_ASSEMBLIES=$(notdir $(shell ls $(TARGETING_PACK)/*.dll))
PROFILE_REFERENCES=$(addsuffix ;\\\n, $(addprefix $$(PS_PROFILE_REF_PATH)\, $(REFERENCE_ASSEMBLIES)))
powershell.inc:
@echo 'PROFILE_REF_PATH=$$(SDK_REF_PATH)\Profiles' > $@
@echo 'PS_PROFILE_REF_PATH=$$(PROFILE_REF_PATH)\PowerShell' >> $@
@echo 'PROFILE_REFERENCES=\\' >> $@
@echo '$(PROFILE_REFERENCES)' >> $@
# generate the Core PS type catalog
2015-10-14 19:31:11 -07:00
# this comes from: $(MONAD)/src/monad/monad/nttargets/assemblies/core/PSAssemblyLoadContext/makefile.inc
2015-10-07 13:05:58 -07:00
CorePsTypeCatalog.cs: powershell.inc buildtemp/TypeCatalogGen.exe
MONO_PATH=$(dir $(REFLECTION_METADATA)):$(dir $(COLLECTIONS_IMMUTABLE)) mono buildtemp/TypeCatalogGen.exe $< $@ $(MONAD_EXT)/coreclr/TargetingPack
2015-10-13 19:48:58 -07:00
# the native library, libps.so
2015-10-14 19:31:11 -07:00
MONAD_NATIVE=$(MONAD)/src/monad-native/src
2015-10-14 14:05:52 -07:00
LIBPS_BUILD=libps
2015-10-14 19:31:11 -07:00
$(LIBPS_BUILD)/Makefile: $(MONAD_NATIVE)/CMakeLists.txt
# cached files can change the path to be incorrect, this must be cleaned
2015-10-14 19:31:11 -07:00
rm -f $(MONAD_NATIVE)/CMakeCache.txt
rm -f $(MONAD_NATIVE)/cmake_install.cmake
mkdir -p $(LIBPS_BUILD)
2015-10-14 19:31:11 -07:00
cd $(LIBPS_BUILD) && cmake $(MONAD_NATIVE)
2015-10-06 21:16:59 -07:00
NATIVE_BINARIES=libps.so monad_native host_cmdline
$(addprefix dotnetlibs/, $(NATIVE_BINARIES)): $(LIBPS_BUILD)/Makefile
2015-10-06 21:16:59 -07:00
$(MAKE) -j -C $(LIBPS_BUILD)
cp $(addprefix $(LIBPS_BUILD)/, $(notdir $@)) dotnetlibs
2015-10-13 19:57:51 -07:00
# C++ tests for monad-native - results in native-tests.xml
# see https://github.com/google/googletest
2015-10-13 19:48:58 -07:00
native-tests: dotnetlibs/monad_native
2015-10-14 19:31:11 -07:00
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)
2015-10-14 19:31:11 -07:00
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 $<
2015-10-06 21:55:21 -07:00
nuget.exe:
2015-10-07 15:35:11 -07:00
wget 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe'
2015-10-06 21:15:48 -07:00
# this creates the build output directories and restores packages from NuGet
buildtemp: nuget.exe
mkdir -p $@
2015-10-06 21:55:21 -07:00
mono nuget.exe restore -PackagesDirectory buildtemp
2015-06-11 14:19:24 -07:00
# this is an internal target, it's not intended to be called manually
#
# it 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
# - copy PS modules
#
# 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
2015-09-21 11:20:30 -07:00
mkdir -p $(APP_BASE)/Modules
2015-10-14 19:31:11 -07:00
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
2015-09-21 11:20:30 -07:00
cp -r dotnetlibs/*.dll $(APP_BASE)
cp -r dotnetlibs/*.exe $(APP_BASE)
cp -r dotnetlibs/*.so $(APP_BASE)
cp dotnetlibs/host_cmdline $(APP_BASE)
2015-10-14 19:31:11 -07:00
cp -r $(MONAD)/ext-src/pester $(APP_BASE)/Modules/Pester
2015-10-14 14:17:34 -07:00
cp -r $(MONAD_EXT)/xunit/xunit* $(APP_BASE)
2015-09-21 11:20:30 -07:00
cp runps*.sh $(APP_BASE)
2015-10-06 15:13:29 -07:00
internal-prepare-clr:
2015-10-13 13:31:03 -07:00
mkdir -p exec_env/coreclr
2015-10-06 15:13:29 -07:00
cp -r $(CORECLR_ASSEMBLY_BASE)/* exec_env/coreclr/
2015-10-06 15:13:29 -07:00
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
2015-09-21 11:20:30 -07:00
$(APP_BASE)/runps-simple.sh '"a","b","c","a","a" | Select-Object -Unique'
2015-10-12 20:10:48 -07:00
shell: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-09-21 11:20:30 -07:00
$(APP_BASE)/runps.sh
2015-10-12 20:10:48 -07:00
run-interactive: shell
2015-10-06 15:13:29 -07:00
run-file: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-09-21 11:20:30 -07:00
$(APP_BASE)/runps.sh --file $(PSSCRIPT)
2015-09-01 14:08:04 -07:00
# easy way to run individual PowerShell scripts, `make script.ps1` where the path is relative to monad-linux/scripts (with TEMP set for Pester)
2015-10-06 15:13:29 -07:00
%.ps1: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-10-14 19:31:11 -07:00
TEMP=/tmp $(APP_BASE)/runps.sh --file $(MONAD)/scripts/$@
2015-09-01 13:55:54 -07:00
2015-10-13 12:55:38 -07:00
# compiles "Hello World" like executables using .NET Core
%.exe: %.cs internal-prepare-clr buildtemp
2015-10-13 13:41:39 -07:00
$(CSC) -out:$@ $(CSCOPTS_BASE) -target:exe $(COREREF) $<
@echo run with monad-tty ./exec_env/coreclr/corerun ./$@
2015-10-13 12:55:38 -07:00
2015-10-06 15:13:29 -07:00
run-debugclr: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-09-21 11:20:30 -07:00
PAL_DBG_CHANNELS="+LOADER.TRACE" $(APP_BASE)/runps-simple.sh get-location
2015-10-13 19:57:51 -07:00
# xUnit tests for PowerShell - results in xunit-tests.xml
# see https://xunit.github.io/
2015-10-14 19:31:11 -07:00
TEST_FOLDER=$(MONAD)/src/ps_test
2015-09-18 12:39:05 -07:00
TEST_SRCS=$(addprefix $(TEST_FOLDER)/, test_*.cs)
2015-10-14 14:17:34 -07:00
TEST_TARGETS=System.Management.Automation.dll Microsoft.PowerShell.Commands.Management.dll $(ASSEMBLY_LOAD_CONTEXT_TARGET)
2015-09-18 12:39:05 -07:00
2015-10-14 14:17:34 -07:00
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)
2015-09-18 12:39:05 -07:00
2015-10-14 14:17:34 -07:00
xunit-tests: dotnetlibs/ps_test.dll $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-10-14 19:31:11 -07:00
$(APP_BASE)/runps-test.sh ps_test.dll -xml $(MONAD)/scripts/xunit-tests.xml
2015-08-28 21:18:58 -07:00
2015-10-13 19:57:51 -07:00
# Pester tests for PowerShell - results in pester-tests.xml
# see https://github.com/pester/Pester
# requires $TEMP to be set
2015-10-06 15:13:29 -07:00
pester-tests: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-10-14 19:31:11 -07:00
$(APP_BASE)/runps-simple.sh 'cd $(MONAD)/src/pester-tests; $$env:TEMP="/tmp"; invoke-pester -OutputFile $(MONAD)/scripts/pester-tests.xml -OutputFormat NUnitXml'
2015-08-28 21:18:58 -07:00
2015-10-07 13:05:58 -07:00
hashbang-tests: all
2015-08-28 21:18:58 -07:00
# execute the 3rdparty/hashbang example
2015-10-14 19:31:11 -07:00
PATH=$(PATH):$(MONAD)/scripts/$(APP_BASE) $(MONAD)/scripts/3rdparty/hashbang/script.ps1
2015-08-28 21:18:58 -07:00
test: native-tests xunit-tests pester-tests hashbang-tests
2015-10-06 15:13:29 -07:00
trace: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
2015-09-21 11:20:30 -07:00
$(APP_BASE)/runps-simple-trace.sh get-location
2015-10-06 15:13:29 -07:00
debug: $(RUN_TARGETS) internal-prepare-exec_env internal-prepare-clr
# quoting here is a bit special if strings are passed in, because lldb seems to forward arguments strangely
2015-09-21 11:20:30 -07:00
$(APP_BASE)/runps-simple-debug.sh get-location
2015-10-06 21:15:48 -07:00
# clean native library, libps
clean-native:
2015-10-14 14:05:52 -07:00
rm -rf $(LIBPS_BUILD)
2015-10-06 21:15:48 -07:00
clean:
rm -rf dotnetlibs/* exec_env powershell.inc *-tests.xml
# clean built stuff + buildtemp step
2015-10-06 21:15:48 -07:00
cleanall: clean clean-native
rm -rf buildtemp
docker-build:
2015-06-25 16:52:12 -07:00
docker build --no-cache=false -t image_ps .
$(eval INSTANCE_ID := $(shell docker inspect -f '{{.Id}}' image_ps))
docker-run: docker-build
2015-07-13 13:08:47 -07:00
# docker port is 4201 for shellinabox by default, but can be overridden
$(eval SHELLINABOX_PORT := $(shell if [ "${SHELLINABOX_PORT}" = "" ]; then echo 4201; else echo ${SHELLINABOX_PORT}; fi))
@echo "SHELLINABOX_PORT=${SHELLINABOX_PORT}"
docker run -d -P -p $(SHELLINABOX_PORT):4201 --name test_ps image_ps
2015-07-13 13:08:47 -07:00
# those two ports are container ports, so they can be hard-coded
docker port test_ps 22
2015-07-13 13:08:47 -07:00
docker port test_ps 4201
$(eval HOST_IP := $(shell ifconfig eth0 | awk '/inet addr/{print substr($$2,6)}'))
@echo "connect to docker at: http://${HOST_IP}:${SHELLINABOX_PORT}/"
@echo "use username: 'test1' and password: 'pass' to connect"
docker-stop:
docker stop test_ps
docker rm test_ps