From 6782caed866b6d3d484dde145fdbb63ac21a8c32 Mon Sep 17 00:00:00 2001 From: dantraMSFT Date: Mon, 6 Nov 2017 07:25:25 -0800 Subject: [PATCH 1/9] Build PowerShell.Core.Instrumentation.dll - Resource-only binary for the ETW resources. --- build.psm1 | 31 +- .../CMakeLists.txt | 71 + .../PowerShell-Core-Instrumentation.man | 5635 +++++++++++++++++ .../version.rc | 15 + 4 files changed, 5751 insertions(+), 1 deletion(-) create mode 100644 src/PowerShell.Core.Instrumentation/CMakeLists.txt create mode 100644 src/PowerShell.Core.Instrumentation/PowerShell-Core-Instrumentation.man create mode 100644 src/PowerShell.Core.Instrumentation/version.rc diff --git a/build.psm1 b/build.psm1 index d612370ffda..288c1ab816c 100644 --- a/build.psm1 +++ b/build.psm1 @@ -257,6 +257,35 @@ cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$ log " Copying $srcPath to $dstPath" Copy-Item $srcPath $dstPath } + + # Place the remoting configuration script in the same directory + # as the binary so it will get published. + Copy-Item .\Install-PowerShellRemoting.ps1 $dstPath + + # + # Build the ETW manifest resource-only binary + # + $location = "$PSScriptRoot\src\PowerShell.Core.Instrumentation" + Set-Location -Path $location + + $command = @" +cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$Arch" "&" cmake "$overrideFlags" -DBUILD_ONECORE=ON -DBUILD_TARGET_ARCH=$Arch -G "$cmakeGenerator" . "&" msbuild ALL_BUILD.vcxproj "/p:Configuration=$Configuration" +"@ + log " Executing Build Command for PowerShell.Core.Instrumentation: $command" + Start-NativeExecution { Invoke-Expression -Command:$command } + + # Copy the binaries and manifest to the packaging directory + $dstPath = "$PSScriptRoot\src\powershell-win-core" + $FilesToCopy = @( + [IO.Path]::Combine($location, $Configuration, 'PowerShell.Core.Instrumentation.dll'), + [IO.Path]::Combine($location, 'PowerShell.Core.Instrumentation.man') + ) + $FilesToCopy | ForEach-Object { + $srcPath = $_ + log " Copying $srcPath to $dstPath" + Copy-Item -Path $srcPath -Destination $dstPath + } + } finally { Pop-Location } @@ -600,7 +629,7 @@ function New-PSOptions { [string]$Output, [switch]$SMAOnly, - + [switch]$PSModuleRestore ) diff --git a/src/PowerShell.Core.Instrumentation/CMakeLists.txt b/src/PowerShell.Core.Instrumentation/CMakeLists.txt new file mode 100644 index 00000000000..acd027bc545 --- /dev/null +++ b/src/PowerShell.Core.Instrumentation/CMakeLists.txt @@ -0,0 +1,71 @@ +cmake_minimum_required(VERSION 3.5) +# +# Builds PowerShell.Core.Instrumentation.dll resource-only DLL containing ETW event resources +# + +# The fully qualified path to the event manifest +SET(EVENTS_MANIFEST "${CMAKE_CURRENT_SOURCE_DIR}/PowerShell.Core.Instrumentation.man") + +# User mode manifest resource-only dll +function(add_manifest_binary) + + add_definitions(-D_DLL=1) + add_library(${ARGV}) + + # NOTE: EVENTS_MANIFEST must be the fully qualified path to the manifest + SET(MC_MANIFEST_FULLNAME ${EVENTS_MANIFEST}) + + # get the ETW manifest's filename without the directory or extension + get_filename_component(MC_MANIFEST_BASENAME ${EVENTS_MANIFEST} NAME_WE) + + SET(MC_COMMAND "mc.exe") + SET(GeneratedManifestFiles) + + # The target directory for generated managed files + SET (MC_GENERATED_DIR "${CMAKE_CURRENT_BINARY_DIR}") + + # include the generated directory in the include path + include_directories("${MC_GENERATED_DIR}") + + SET (MC_GENERATED_FILES + ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}.rc + ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}TEMP.BIN + ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}_MSG00001.BIN + ) + + SET(MC_COMMAND "mc.exe -h ${MC_GENERATED_DIR} -r ${MC_GENERATED_DIR} ${MC_MANIFEST_FULLNAME}") + + add_custom_command( + COMMENT "Generating native event manifest files for ${EVENTS_MANIFEST}" + OUTPUT ${MC_GENERATED_FILES} + DEPENDS ${MC_MANIFEST_FULLNAME} + COMMAND cmd.exe /c ${MC_COMMAND} + WORKING_DIRECTORY ${MC_GENERATED_DIR} + VERBATIM + ) + + list (APPEND GeneratedManifestFiles ${MC_GENERATED_DIR}/${MC_MANIFEST_BASENAME}.rc) + + set_source_files_properties(${GeneratedManifestFiles} PROPERTIES GENERATED TRUE) + add_custom_target(GeneratedManifestFiles DEPENDS ${GeneratedManifestFiles}) + + # for a resource only dll, cmake can report an error + # if there is no linker language set. + # CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly. + # Missing variable is: CMAKE_RC_CREATE_SHARED_LIBRARY + get_property(isSet TARGET ${ARGV0} PROPERTY LINKER_LANGUAGE SET) + if (NOT ${isSet}) + set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX") + endif() + set_target_properties(${ARGV0} PROPERTIES LINK_FLAGS "/NODEFAULTLIB /NOENTRY") + set_target_properties(${ARGV0} PROPERTIES COMPILE_DEFINITIONS "CORECLR") + + # ensure the target is dependent on the generated files. + add_dependencies(${ARGV0} GeneratedManifestFiles) + +endfunction() + +file(GLOB SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/version.rc) + +add_manifest_binary(PowerShell.Core.Instrumentation SHARED ${SOURCES}) + diff --git a/src/PowerShell.Core.Instrumentation/PowerShell-Core-Instrumentation.man b/src/PowerShell.Core.Instrumentation/PowerShell-Core-Instrumentation.man new file mode 100644 index 00000000000..2fad01ea51c --- /dev/null +++ b/src/PowerShell.Core.Instrumentation/PowerShell-Core-Instrumentation.man @@ -0,0 +1,5635 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + 15728640 + + + + + + true + + 1048985600 + + + + 64 + + + + + + true + + 1048985600 + + + + 64 + + + + + + true + + 1048985600 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +