diff --git a/scripts/dotnet-cli-build/CompileTargets.cs b/scripts/dotnet-cli-build/CompileTargets.cs index e24fdbd08..8322e9107 100644 --- a/scripts/dotnet-cli-build/CompileTargets.cs +++ b/scripts/dotnet-cli-build/CompileTargets.cs @@ -165,6 +165,7 @@ namespace Microsoft.DotNet.Cli.Build // Run the build string rid = GetRuntimeId(); string corehostSrcDir = Path.Combine(c.BuildContext.BuildDirectory, "src", "corehost"); + string commitHash = c.BuildContext.Get("CommitHash"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { @@ -177,6 +178,7 @@ namespace Microsoft.DotNet.Cli.Build var baseSupportedRid = $"win7-{arch}"; var cmakeHostPolicyVer = $"-DCLI_CMAKE_HOST_POLICY_VER:STRING={buildVersion.LatestHostPolicyVersion}"; var cmakeBaseRid = $"-DCLI_CMAKE_PKG_RID:STRING={baseSupportedRid}"; + var cmakeCommitHash = $"-DCLI_CMAKE_COMMIT_HASH:STRING={commitHash}"; ExecIn(cmakeOut, "cmake", corehostSrcDir, @@ -184,6 +186,7 @@ namespace Microsoft.DotNet.Cli.Build ridMacro, cmakeHostPolicyVer, cmakeBaseRid, + cmakeCommitHash, "-G", visualStudio); @@ -217,7 +220,9 @@ namespace Microsoft.DotNet.Cli.Build "--policyver", buildVersion.LatestHostPolicyVersion, "--rid", - rid); + rid, + "--commithash", + commitHash); // Copy the output out File.Copy(Path.Combine(cmakeOut, "cli", "dotnet"), Path.Combine(Dirs.CorehostLatest, "dotnet"), overwrite: true); diff --git a/src/corehost/build.sh b/src/corehost/build.sh index cd35754b5..390762002 100755 --- a/src/corehost/build.sh +++ b/src/corehost/build.sh @@ -27,12 +27,13 @@ init_distro_name_and_rid() usage() { - echo "Usage: $0 --arch --rid --policyver [--xcompiler ]" + echo "Usage: $0 --arch --rid --policyver --commithash [--xcompiler ]" echo "" echo "Options:" echo " --arch Target Architecture (amd64, x86, arm)" echo " --rid Target Runtime Identifier" echo " --policyver Version of the hostpolicy library" + echo " --commithash Current commit hash of the repo at build time" echo " --xcompiler Cross Compiler when the target is arm" echo " e.g.) /usr/bin/arm-linux-gnueabi-g++-4.7" @@ -53,6 +54,7 @@ __build_arch= __runtime_id= __policy_ver= __CrossBuild=0 +__commit_hash= while [ "$1" != "" ]; do lowerI="$(echo $1 | awk '{print tolower($0)}')" @@ -73,6 +75,10 @@ while [ "$1" != "" ]; do shift __policy_ver=$1 ;; + --commithash) + shift + __commit_hash=$1 + ;; --xcompiler) shift __CrossCompiler="$1" @@ -116,15 +122,20 @@ if [ -z $__rid_plat ]; then exit -1 fi +if [-z $__commit_hash ]; then + echo "Commit hash was not specified" + exit -1 +fi + __build_arch_lowcase=$(echo "$__build_arch" | tr '[:upper:]' '[:lower:]') __base_rid=$__rid_plat-$__build_arch_lowcase echo "Building Corehost from $DIR to $(pwd)" set -x # turn on trace if [ $__CrossBuild == 1 ]; then - cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_RUNTIME_ID:STRING=$__runtime_id -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCMAKE_CXX_COMPILER="$__CrossCompiler" -DCLI_CMAKE_PKG_RID:STRING=$__base_rid + cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_RUNTIME_ID:STRING=$__runtime_id -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCMAKE_CXX_COMPILER="$__CrossCompiler" -DCLI_CMAKE_PKG_RID:STRING=$__base_rid -DCLI_CMAKE_COMMIT_HASH:STRING=$__commit_hash else - cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_RUNTIME_ID:STRING=$__runtime_id -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCLI_CMAKE_PKG_RID:STRING=$__base_rid + cmake "$DIR" -G "Unix Makefiles" $__cmake_defines -DCLI_CMAKE_RUNTIME_ID:STRING=$__runtime_id -DCLI_CMAKE_HOST_POLICY_VER:STRING=$__policy_ver -DCLI_CMAKE_PKG_RID:STRING=$__base_rid -DCLI_CMAKE_COMMIT_HASH:STRING=$__commit_hash fi set +x # turn off trace make diff --git a/src/corehost/cli/fxr/hostfxr.cpp b/src/corehost/cli/fxr/hostfxr.cpp index dcf9e6367..98bc32036 100644 --- a/src/corehost/cli/fxr/hostfxr.cpp +++ b/src/corehost/cli/fxr/hostfxr.cpp @@ -147,6 +147,8 @@ bool hostpolicy_exists_in_svc(pal::string_t* resolved_dir) SHARED_API int hostfxr_main(const int argc, const pal::char_t* argv[]) { trace::setup(); + + trace::info(_X("--- Invoked hostfxr [commit hash: %s] main"), _STRINGIFY(REPO_COMMIT_HASH)); fx_muxer_t muxer; return muxer.execute(argc, argv); diff --git a/src/corehost/cli/hostpolicy.cpp b/src/corehost/cli/hostpolicy.cpp index 6e729436a..686883b59 100644 --- a/src/corehost/cli/hostpolicy.cpp +++ b/src/corehost/cli/hostpolicy.cpp @@ -226,7 +226,8 @@ SHARED_API int corehost_main(const int argc, const pal::char_t* argv[]) { if (trace::is_enabled()) { - trace::info(_X("--- Invoked policy [%s,%s,%s][%s] main = {"), + trace::info(_X("--- Invoked hostpolicy [commit hash: %s] [%s,%s,%s][%s] main = {"), + _STRINGIFY(REPO_COMMIT_HASH), _STRINGIFY(HOST_POLICY_PKG_NAME), _STRINGIFY(HOST_POLICY_PKG_VER), _STRINGIFY(HOST_POLICY_PKG_REL_DIR), diff --git a/src/corehost/cli/setup.cmake b/src/corehost/cli/setup.cmake index acea35b8e..ec07ca335 100644 --- a/src/corehost/cli/setup.cmake +++ b/src/corehost/cli/setup.cmake @@ -55,21 +55,28 @@ else() message(FATAL_ERROR "Unknown target architecture") endif() -if(${CLI_CMAKE_RUNTIME_ID} STREQUAL "") +if("${CLI_CMAKE_RUNTIME_ID}" STREQUAL "") message(FATAL_ERROR "Runtime ID not specified") else() add_definitions(-DTARGET_RUNTIME_ID="${CLI_CMAKE_RUNTIME_ID}") endif() -if(${CLI_CMAKE_HOST_POLICY_VER} STREQUAL "") +if("${CLI_CMAKE_HOST_POLICY_VER}" STREQUAL "") message(FATAL_ERROR "Host policy version is not specified") else() add_definitions(-DHOST_POLICY_PKG_VER="${CLI_CMAKE_HOST_POLICY_VER}") endif() -if(${CLI_CMAKE_PKG_RID} STREQUAL "") +if("${CLI_CMAKE_PKG_RID}" STREQUAL "") message(FATAL_ERROR "A minimum supported package rid is not specified (ex: win7-x86 or ubuntu.14.04-x64, osx.10.10-x64, rhel.7-x64)") +else() + add_definitions(-DHOST_POLICY_PKG_NAME="runtime.${CLI_CMAKE_PKG_RID}.Microsoft.NETCore.DotNetHostPolicy") + add_definitions(-DHOST_POLICY_PKG_REL_DIR="runtimes/${CLI_CMAKE_PKG_RID}/native") +endif() + +if("${CLI_CMAKE_COMMIT_HASH}" STREQUAL "") + message(FATAL_ERROR "Commit hash needs to be specified to build the host") +else() + add_definitions(-DREPO_COMMIT_HASH="${CLI_CMAKE_COMMIT_HASH}") endif() -add_definitions(-DHOST_POLICY_PKG_NAME="runtime.${CLI_CMAKE_PKG_RID}.Microsoft.NETCore.DotNetHostPolicy") -add_definitions(-DHOST_POLICY_PKG_REL_DIR="runtimes/${CLI_CMAKE_PKG_RID}/native") diff --git a/src/corehost/corehost.cpp b/src/corehost/corehost.cpp index e68aa6a1b..a904a41c7 100644 --- a/src/corehost/corehost.cpp +++ b/src/corehost/corehost.cpp @@ -96,7 +96,7 @@ int main(const int argc, const pal::char_t* argv[]) if (trace::is_enabled()) { - trace::info(_X("--- Invoked host main = {")); + trace::info(_X("--- Invoked dotnet [commit hash: %s] main = {"), _STRINGIFY(REPO_COMMIT_HASH)); for (int i = 0; i < argc; ++i) { trace::info(_X("%s"), argv[i]);