소스 검색

Changes for MicroBuild v2.

Doug Ilijev 10 년 전
부모
커밋
27402cbcad

+ 5 - 0
.gitignore

@@ -2,10 +2,12 @@
 *.sdf
 *.suo
 *.opensdf
+*.VC.db
 *.opendb
 *.user
 *.i
 Build/VCBuild/
+Build/VCBuild.NoJIT/
 Build/ipch/
 Build/.vs/
 build_*.log
@@ -14,6 +16,8 @@ build_*.err
 buildchk.*
 buildfre.*
 Build/swum-cache.txt
+ComputedEnvironment.cmd
+packages/
 *.tlog/
 .*.swp
 sd.ini
@@ -27,3 +31,4 @@ profile.dpl.*
 Build/Chakra.Core.VC.opendb
 test/benchmarks/*.txt
 test/benchmarks/*.dpl
+*.nupkg

+ 1 - 1
Build/Chakra.Build.ProjectConfiguration.props

@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="Common.Build.ProjectConfiguration.props" />
+  <Import Project="MicroBuildv2.Build.ProjectConfiguration.props" />
 </Project>
-

+ 9 - 1
Build/Common.Build.Default.props

@@ -40,7 +40,15 @@
     <CharacterSet>Unicode</CharacterSet>
   </PropertyGroup>
 
-  <!-- Alternate platform names-->
+  <!-- Change configuration name to output to a different folder -->
+  <!-- POGO instrumentation -->
+  <PropertyGroup>
+    <IsPogoBuild />
+    <IsPogoBuild Condition="('$(POGO_TYPE)'=='PGO' OR '$(POGO_TYPE)'=='PGI')">true</IsPogoBuild>
+    <OutDirName Condition="'$(IsPogoBuild)'=='true'">$(Configuration.ToLower())_pogo</OutDirName>
+  </PropertyGroup>
+
+  <!-- Alternate platform names -->
   <PropertyGroup>
     <!-- PlatformPathName is used in OutDir/IntDir name-->
     <PlatformPathName>$(Platform)</PlatformPathName>

+ 24 - 0
Build/MicroBuildv2.Build.ProjectConfiguration.props

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <MicroBuildV2Dir>$(SolutionDir)packages\MicroBuild.Core.0.2.0\build</MicroBuildV2Dir>
+    <MicroBuildV2Props>$(MicroBuildV2Dir)\MicroBuild.Core.props</MicroBuildV2Props>
+    <MicroBuildV2Targets>$(MicroBuildV2Dir)\MicroBuild.Core.targets</MicroBuildV2Targets>
+  </PropertyGroup>
+
+  <Import Project="$(MicroBuildV2Props)"
+    Condition="'$(VSO_MICROBUILD_V2)'=='True' AND Exists('$(MicroBuildV2Props)')" />
+
+  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
+    <PropertyGroup>
+      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
+    </PropertyGroup>
+    <Error Text="$([System.String]::Format('$(ErrorText)', '$(MicroBuildV2Props)'))"
+      Condition="'$(VSO_MICROBUILD_V2)'=='True' AND !Exists('$(MicroBuildV2Props)')" />
+    <Error Text="$([System.String]::Format('$(ErrorText)', '$(MicroBuildV2Targets)'))"
+      Condition="'$(VSO_MICROBUILD_V2)'=='True' AND !Exists('$(MicroBuildV2Targets)')" />
+  </Target>
+
+  <Import Project="$(MicroBuildV2Targets)"
+    Condition="'$(VSO_MICROBUILD_V2)'=='True' AND Exists('$(MicroBuildV2Targets)')" />
+</Project>

+ 30 - 0
Build/Microsoft.ChakraCore.nuspec

@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
+    <metadata>
+        <id>Microsoft.ChakraCore</id>
+        <version>1.2</version>
+        <authors>Chakra Team</authors>
+        <owners>Chakra Team</owners>
+        <licenseUrl>https://github.com/Microsoft/ChakraCore/blob/master/LICENSE.txt</licenseUrl>
+        <projectUrl>https://github.com/Microsoft/ChakraCore</projectUrl>
+        <requireLicenseAcceptance>false</requireLicenseAcceptance>
+        <developmentDependency>true</developmentDependency>
+        <description>ChakraCore is the core part of the Chakra Javascript engine that powers Microsoft Edge.</description>
+        <!--
+        <releaseNotes>**** TODO: need link</releaseNotes>
+        -->
+        <copyright>Copyright (C) 2016 Microsoft</copyright>
+        <language>en-US</language>
+        <tags>Chakra,ChakraCore</tags>
+    </metadata>
+    <files>
+        <file src="..\x86_release\ChakraCore.dll" target="x86\ChakraCore.dll" />
+        <file src="..\x86_release\ChakraCore.pdb" target="x86\ChakraCore.pdb" />
+        <file src="..\x86_release\ch.exe" target="x86\ch.exe" />
+        <file src="..\x86_release\ch.pdb" target="x86\ch.pdb" />
+        <file src="..\x64_release\ChakraCore.dll" target="x64\ChakraCore.dll" />
+        <file src="..\x64_release\ChakraCore.pdb" target="x64\ChakraCore.pdb" />
+        <file src="..\x64_release\ch.exe" target="x64\ch.exe" />
+        <file src="..\x64_release\ch.pdb" target="x64\ch.pdb" />
+    </files>
+</package>

+ 47 - 0
Build/scripts/compose_build.ps1

@@ -0,0 +1,47 @@
+#-------------------------------------------------------------------------------------------------------
+# Copyright (C) Microsoft. All rights reserved.
+# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+#-------------------------------------------------------------------------------------------------------
+
+# Compose Build script
+#
+# Aggregate metadata about a build and produce a file with useful information about the build
+# for tools to consume and get a quick overview of the status of a completed build.
+
+param (
+    [Parameter(Mandatory=$True)]
+    [string]$rootPath
+)
+
+#
+# Aggregate build metadata and produce build.json
+#
+
+$outputJsonFile = Join-Path -Path $rootPath -ChildPath "build.json"
+$buildInfo = New-Object System.Object
+
+$changeJson = (Get-ChildItem -Path $rootPath "change.json" -Recurse)[0] | % { $_.FullName }
+$changeInfo = (Get-Content $changeJson) -join "`n" | ConvertFrom-Json
+
+# Determine the overall build status. Mark the build as "passed" until "failed" is encountered.
+$overallBuildStatus = "passed"
+
+$files = Get-ChildItem -Path $rootPath "*.json" -Recurse `
+    | ? { ($_.Name -ne "change.json") -and ($_.Name -ne "build.json") } `
+    | % { $_.FullName }
+$builds = New-Object System.Collections.ArrayList
+foreach ($file in $files) {
+    $json = (Get-Content $file) -join "`n" | ConvertFrom-Json
+    $_ = $builds.Add($json)
+
+    if ($json.status -eq "failed") {
+        $overallBuildStatus = "failed"
+    }
+}
+
+$buildInfo | Add-Member -type NoteProperty -name status -value $overallBuildStatus
+$buildInfo | Add-Member -type NoteProperty -name change -value $changeInfo
+$buildInfo | Add-Member -type NoteProperty -name builds -value $builds
+
+$buildInfo | ConvertTo-Json | Write-Output
+$buildInfo | ConvertTo-Json | Out-File $outputJsonFile -Encoding ascii

+ 54 - 0
Build/scripts/finalize_build.ps1

@@ -0,0 +1,54 @@
+#-------------------------------------------------------------------------------------------------------
+# Copyright (C) Microsoft. All rights reserved.
+# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+#-------------------------------------------------------------------------------------------------------
+
+# Finalize Build Script
+#
+# This script is run as the final step in a build definition
+# to clean up and produce metadata about the build.
+
+#
+# Copy _pogo binary folder, if present.
+#
+
+$PogoFolder = Join-Path $Env:BinariesDirectory "bin\${Env:BuildType}_pogo"
+if (Test-Path $PogoFolder) {
+    $BinDropPath = Join-Path $Env:DropPath "bin"
+    Write-Output "Copying `"$PogoFolder`" to `"$BinDropPath`"..."
+    Copy-Item $PogoFolder $BinDropPath -Recurse -Force
+}
+
+#
+# Clean up the sentinel which previously marked this build flavor as incomplete.
+#
+
+Remove-Item -Path $Env:FlavorBuildIncompleteFile -Force
+
+#
+# Create build status JSON file for this flavor.
+#
+
+$BuildLogsPath = Join-Path $Env:DropPath "buildlogs"
+$buildFlavorErrFile = Join-Path $BuildLogsPath "build_${Env:BuildPlatform}${Env:BuildConfiguration}.err"
+
+# If build_{}{}.err contains any text then there were build errors and we record that the build failed.
+$BuildFailed = $false
+if (Test-Path $buildFlavorErrFile) {
+    $BuildFailed = (Get-Item $buildFlavorErrFile).length -gt 0
+}
+
+$status = "passed"
+if ($BuildFailed) {
+    $status = "failed"
+}
+
+$buildFlavorJsonFile = Join-Path $Env:DropPath "${Env:BuildType}.json"
+$buildFlavorJson = New-Object System.Object
+
+$buildFlavorJson | Add-Member -type NoteProperty -name status -value $status
+$buildFlavorJson | Add-Member -type NoteProperty -name arch -value $Env:BuildPlatform
+$buildFlavorJson | Add-Member -type NoteProperty -name flavor -value $Env:BuildConfiguration
+
+$buildFlavorJson | ConvertTo-Json | Write-Output
+$buildFlavorJson | ConvertTo-Json | Out-File $buildFlavorJsonFile -Encoding ascii

+ 160 - 0
Build/scripts/init_build.ps1

@@ -0,0 +1,160 @@
+#-------------------------------------------------------------------------------------------------------
+# Copyright (C) Microsoft. All rights reserved.
+# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+#-------------------------------------------------------------------------------------------------------
+
+# Init Build Script
+#
+# Run this as the very first step in the build to configure the environment.
+# This is distinct from the Pre-Build script as there may be more non-script steps that need to be
+# taken before setting up and running the build.
+# For example, this script creates a cmd script which should be run to initialize environment variables.
+
+param (
+    [string]$envconfig = "ComputedEnvironment.cmd",
+
+    [string[]]$SupportedPogoBuildTypes = @("x64_release", "x86_release"),
+
+    [Parameter(Mandatory=$True)]
+    [string]$oauth
+)
+
+$branch = $env:BUILD_SOURCEBRANCH
+if (-not $branch) {
+    $branch = $(git rev-parse --symbolic-full-name HEAD)
+}
+
+$BranchName = $branch.split('/',3)[2]
+$BranchPath = $BranchName.replace('/','\')
+$CommitHash = $env:BUILD_SOURCEVERSION
+if (-not $CommitHash) {
+    $CommitHash = $(git rev-parse HEAD)
+}
+
+$Username = $(git log $CommitHash -1 --pretty=%ae).split('@')[0]
+$CommitDateTime = [DateTime]$(git log $CommitHash -1 --pretty=%aD)
+$CommitTime = Get-Date $CommitDateTime -Format yyMMdd.HHmm
+
+#
+# (borrowed from pre_build.ps1)
+# Get PushID and PushDate from VSO
+# TODO (doilij) refactor this into a method in a util script.
+#
+
+# Get the git remote path and construct the rest API URI
+$remote = (iex "git remote -v")[0].split()[1].replace("_git", "_apis/git/repositories");
+$remote = $remote.replace("mshttps", "https")
+
+# Get the pushId and push date time to use that for build number and build date time
+$uri = ("{0}/commits/{1}?api-version=1.0" -f $remote, $commitHash)
+$oauthToken = Get-Content $oauth
+$header = @{ Authorization=("Basic {0}" -f $oauthToken) }
+$info = Invoke-RestMethod -Headers $header -Uri $uri -Method GET
+
+$BuildPushDate = [datetime]$info.push.date
+$PushDate = Get-Date $BuildPushDate -Format yyMMdd.HHmm
+$buildPushId = $info.push.pushId
+$buildPushIdPart1 = [int]([math]::Floor($buildPushId / 65536))
+$buildPushIdPart2 = [int]($buildPushId % 65536)
+
+$PushID = "{0}.{1}" -f $buildPushIdPart1.ToString("00000"), $buildPushIdPart2.ToString("00000")
+$VersionString = "${Env:VERSION_MAJOR}.${Env:VERSION_MINOR}.${PushID}"
+$PreviewVersionString = "${VersionString}-preview"
+
+#
+# (end code borrowed from pre_build.ps1)
+#
+
+# unless it is a build branch, subdivide the output directory by month
+if ($BranchPath.StartsWith("build")) {
+    $YearAndMonth = ""
+} else {
+    $YearAndMonth = (Get-Date $BuildPushDate -Format yyMM) + "\"
+}
+
+$BuildIdentifier = "${PushID}_${PushDate}_${Username}_${CommitHash}"
+$ComputedDropPathSegment = "${BranchPath}\${YearAndMonth}${BuildIdentifier}"
+$BuildType = "${Env:BuildPlatform}_${Env:BuildConfiguration}"
+$BinariesDirectory = "${Env:BUILD_SOURCESDIRECTORY}\Build\VcBuild"
+
+# Create a sentinel file for each build flavor to track whether the build is complete.
+# * ${arch}_${flavor}.incomplete       # will be deleted when the build of this flavor completes
+
+$buildIncompleteFileContentsString = @"
+{0} in progress.
+The contents of this directory should not be relied on until the build completes.
+"@
+
+$DropPath = Join-Path $env:DROP_ROOT $ComputedDropPathSegment
+New-Item -ItemType Directory -Force -Path $DropPath
+New-Item -ItemType Directory -Force -Path (Join-Path $Env:BUILD_SOURCESDIRECTORY "test\logs")
+New-Item -ItemType Directory -Force -Path (Join-Path $BinariesDirectory "testlogs")
+New-Item -ItemType Directory -Force -Path (Join-Path $BinariesDirectory "buildlogs")
+New-Item -ItemType Directory -Force -Path (Join-Path $BinariesDirectory "logs")
+
+$flavorBuildIncompleteFile = Join-Path $DropPath "${BuildType}.incomplete"
+
+if (-not (Test-Path $flavorBuildIncompleteFile)) {
+    ($buildIncompleteFileContentsString -f "Build of ${BuildType}") `
+        | Out-File $flavorBuildIncompleteFile -Encoding Ascii
+}
+
+$PogoConfig = $SupportedPogoBuildTypes -contains "${Env:BuildPlatform}_${Env:BuildConfiguration}"
+
+# Write the $envconfig script.
+
+@"
+set BranchName=${BranchName}
+set BranchPath=${BranchPath}
+set YearAndMonth=${YearAndMonth}
+set BuildIdentifier=${BuildIdentifier}
+
+set PushID=${PushID}
+set VersionString=${VersionString}
+set PreviewVersionString=${PreviewVersionString}
+set PushDate=${PushDate}
+set CommitTime=${CommitTime}
+set Username=${Username}
+set CommitHash=${CommitHash}
+
+set ComputedDropPathSegment=${ComputedDropPathSegment}
+set BinariesDirectory=${BinariesDirectory}
+set DropPath=${DropPath}
+set BuildType=${BuildType}
+
+set FlavorBuildIncompleteFile=${flavorBuildIncompleteFile}
+
+set PogoConfig=${PogoConfig}
+"@ `
+    | Out-File $envconfig -Encoding Ascii
+
+# Use the MBv2 environment to construct a MBv1 VSO environment
+# for the sake of reusing the pre-build and post-build scripts as they are.
+
+@"
+set TF_BUILD_SOURCEGETVERSION=LG:${branch}:${CommitHash}
+set TF_BUILD_DROPLOCATION=${BinariesDirectory}
+set TF_BUILD_BINARIESDIRECTORY=${BinariesDirectory}
+set TF_BUILD_SOURCESDIRECTORY=${Env:BUILD_SOURCESDIRECTORY}
+
+set TF_BUILD_BUILDDEFINITIONNAME=${Env:BUILD_DEFINITIONNAME}
+set TF_BUILD_BUILDNUMBER=${Env:BUILD_BUILDNUMBER}
+set TF_BUILD_BUILDURI=${Env:BUILD_BUILDURI}
+"@ `
+    | Out-File $envconfig -Encoding Ascii -Append
+
+# Set VSO variables that can be consumed by other VSO tasks.
+# Uses command syntax documented here:
+# https://github.com/Microsoft/vso-agent-tasks/blob/master/docs/authoring/commands.md
+# Lines written to stdout that match this pattern are interpreted with this command syntax.
+
+Write-Output "Setting VSO variable VSO_DropPath = ${DropPath}"
+Write-Output "##vso[task.setvariable variable=VSO_DropPath;]${DropPath}"
+
+Write-Output "Setting VSO variable VSO_VersionString = ${VersionString}"
+Write-Output "##vso[task.setvariable variable=VSO_VersionString;]${VersionString}"
+
+# TODO (doilij): move this up and assign values
+
+# Inferable Environment (if not specified, inferred by pre_post_util.ps1):
+#   $Env:TF_BUILD_BUILDDIRECTORY    (a.k.a. $objpath)

+ 66 - 0
Build/scripts/pgo/pogo_training.ps1

@@ -0,0 +1,66 @@
+#-------------------------------------------------------------------------------------------------------
+# Copyright (C) Microsoft. All rights reserved.
+# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+#-------------------------------------------------------------------------------------------------------
+
+# PGO Build Workflow:
+# - pre_pgi.cmd
+# - build (with PGI instrumentation enabled)
+# - post_pgi.cmd
+# * pogo_training.ps1
+# - pre_pgo.cmd
+# - build (using PGO profile)
+# - post_pgo.cmd
+
+param (
+    [string[]]$scenarios = @(),
+
+    [Parameter(Mandatory=$True)]
+    [string]$binary,
+
+    [Parameter(Mandatory=$True)]
+    [string]$arch,
+
+    # force callers to specify this in case of future use
+    [Parameter(Mandatory=$True)]
+    [string]$flavor,
+
+    [string]$vcinstallroot = ${env:ProgramFiles(x86)},
+    [string]$vcbinpath = "Microsoft Visual Studio 14.0\VC\bin",
+    [string]$dllname = "pgort140.dll"
+)
+
+if (${Env:PogoConfig} -eq "False") {
+    Write-Host "---- Not a Pogo Config. Skipping step."
+    return 0
+}
+
+$binpath = Split-Path -Path $binary -Parent
+$pgoOutDll = Join-Path $binpath $dllname;
+if (-not (Test-Path ($pgoOutDll))) {
+    if ($arch -eq "x64") {
+        $dllname = Join-Path "amd64" $dllname
+    } elseif ($arch -eq "arm") {
+        $dllname = Join-Path "arm" $dllname
+    }
+    $pgoSrcDll = Join-Path $vcinstallroot (Join-Path $vcbinpath $dllname)
+    Copy-Item $pgoSrcDll $pgoOutDll
+}
+
+for ($i = 0; $i -lt $scenarios.Length; $i = $i + 1) {
+    $path = $scenarios[$i]
+
+    $items = @()
+    if (Test-Path $path -PathType Container) {
+        # *.js files in directories
+        $items = Get-ChildItem -Path $path -Filter "*.js" | % {join-path $path $_ }
+    } else {
+        $items = @($path)
+    }
+
+    for ($j = 0; $j -lt $items.Length; $j = $j + 1) {
+        $testFile = $items[$j]
+        Write-Host "$binary $testFile"
+        iex "$binary $testFile"
+    }
+}

+ 25 - 0
Build/scripts/pgo/post_pgi.cmd

@@ -0,0 +1,25 @@
+::-------------------------------------------------------------------------------------------------------
+:: Copyright (C) Microsoft. All rights reserved.
+:: Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+::-------------------------------------------------------------------------------------------------------
+
+:: PGO Build Workflow:
+:: - pre_pgi.cmd
+:: - build (with PGI instrumentation enabled)
+:: * post_pgi.cmd
+:: - pogo_training.ps1
+:: - pre_pgo.cmd
+:: - build (using PGO profile)
+:: - post_pgo.cmd
+
+@echo off
+
+if "%PogoConfig%"=="False" (
+    echo ---- Not a Pogo Config. Skipping step.
+    exit /b 0
+)
+
+set _LINK_=
+set POGO_TYPE=
+
+goto:eof

+ 43 - 0
Build/scripts/pgo/post_pgo.cmd

@@ -0,0 +1,43 @@
+::-------------------------------------------------------------------------------------------------------
+:: Copyright (C) Microsoft. All rights reserved.
+:: Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+::-------------------------------------------------------------------------------------------------------
+
+:: PGO Build Workflow:
+:: - pre_pgi.cmd
+:: - build (with PGI instrumentation enabled)
+:: - post_pgi.cmd
+:: - pogo_training.ps1
+:: - pre_pgo.cmd
+:: - build (using PGO profile)
+:: * post_pgo.cmd
+
+@echo off
+
+if "%PogoConfig%"=="False" (
+    echo ---- Not a Pogo Config. Skipping step.
+    exit /b 0
+)
+
+set binpath_pgo=%1
+
+if "%binpath_pgo%"=="" (
+  goto:usage
+)
+
+set POGO_TYPE=
+
+REM Clean binaries we no longer need
+if exist %binpath_pgo%\*.pgc ( del %binpath_pgo%\*.pgc )
+if exist %binpath_pgo%\*.pgd ( del %binpath_pgo%\*.pgd )
+if exist %binpath_pgo%\pgort* ( del %binpath_pgo%\pgort* )
+
+goto:eof
+
+:usage
+  echo Invalid/missing arguments
+  echo.
+  echo Usage: post_pgo.cmd ^<binary_path^>
+  echo   - binary_path: output path of your binaries
+
+exit /b 1

+ 59 - 0
Build/scripts/pgo/pre_pgi.cmd

@@ -0,0 +1,59 @@
+::-------------------------------------------------------------------------------------------------------
+:: Copyright (C) Microsoft. All rights reserved.
+:: Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+::-------------------------------------------------------------------------------------------------------
+
+:: PGO Build Workflow:
+:: * pre_pgi.cmd
+:: - build (with PGI instrumentation enabled)
+:: - post_pgi.cmd
+:: - pogo_training.ps1
+:: - pre_pgo.cmd
+:: - build (using PGO profile)
+:: - post_pgo.cmd
+
+@echo off
+
+if "%PogoConfig%"=="False" (
+    echo ---- Not a Pogo Config. Skipping step.
+    exit /b 0
+)
+
+set arch_pgi=%1
+set flavor_pgi=%2
+set binpath_pgi=%3
+set builderror=
+
+if "%arch_pgi%"=="" (
+  goto:usage
+)
+if "%flavor_pgi%"=="" (
+  goto:usage
+)
+if "%binpath_pgi%"=="" (
+  goto:usage
+)
+
+if not exist %binpath_pgi% (
+  md %binpath_pgi%
+) else (
+  if exist %binpath_pgi%\*.pgc ( del %binpath_pgi%\*.pgc )
+)
+
+REM Build with pgo instrumentation
+set POGO_TYPE=PGI
+
+REM Temporary fix around pgo bug, todo:: check if still necessary once toolset is updated
+set _LINK_=/cgthreads:1
+
+goto:eof
+
+:usage
+  echo Invalid/missing arguments
+  echo.
+  echo Usage: pre_pgi.cmd ^<arch^> ^<flavor^> ^<binary_path^>
+  echo   - arch  : Architecture you want to build pogo
+  echo   - flavor: flavor you want to build pogo
+  echo   - binary_path: output path of your binaries
+
+exit /b 1

+ 25 - 0
Build/scripts/pgo/pre_pgo.cmd

@@ -0,0 +1,25 @@
+::-------------------------------------------------------------------------------------------------------
+:: Copyright (C) Microsoft. All rights reserved.
+:: Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
+::-------------------------------------------------------------------------------------------------------
+
+:: PGO Build Workflow:
+:: - pre_pgi.cmd
+:: - build (with PGI instrumentation enabled)
+:: - post_pgi.cmd
+:: - pogo_training.ps1
+:: * pre_pgo.cmd
+:: - build (using PGO profile)
+:: - post_pgo.cmd
+
+@echo off
+
+if "%PogoConfig%"=="False" (
+    echo ---- Not a Pogo Config. Skipping step.
+    exit /b 0
+)
+
+REM Optimize build with PGO data
+set POGO_TYPE=PGO
+
+goto:eof

+ 21 - 9
Build/scripts/post_build.ps1

@@ -3,9 +3,18 @@
 # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 #-------------------------------------------------------------------------------------------------------
 
+# Post-Build Script
+#
+# Run this script after the build step to consume the artifacts produced by the build,
+# run tests, and process and deploy build logs.
+#
+# There may be more non-script tasks in the build definition following this script.
+# Any final tasks that need to be done at the end of the build are contained in the
+# Finalize Build Script, which should be invoked at the very end of the build.
+
 param (
     [ValidateSet("x86", "x64", "arm", "*")]
-    [string]$arch="*",
+    [string]$arch = "*",
 
     [ValidateSet("debug", "release", "test", "codecoverage", "*")]
     [string]$flavor = "*",
@@ -14,14 +23,19 @@ param (
     [string]$binpath = "",
     [string]$objpath = "",
 
-    [string]$srcsrvcmdpath = "Build\script\srcsrv.bat",
-    [string]$bvtcmdpath="",
+    [Parameter(Mandatory=$True)]
+    [string]$srcsrvcmdpath,
+
+    [string]$bvtcmdpath = "",
     [string]$repo = "core",
     [string]$logFile = "",
 
     # comma separated list of [arch,flavor,arch2,flavor2,...] to build
     [string[]]$pogo = @(),
-    [string]$pogoscript="",
+    [string]$pogoscript = "",
+
+    # Support output folders with e.g. _pogo suffix
+    [string]$buildTypeSuffix = "",
 
     [switch]$noaction
 )
@@ -43,17 +57,16 @@ if ($arch -eq "*") {
     }
 
 } else {
-    $OutterScriptRoot = $PSScriptRoot;
+    $OuterScriptRoot = $PSScriptRoot;
     . "$PSScriptRoot\pre_post_util.ps1"
 
     if (($logFile -eq "") -and (Test-Path Env:\TF_BUILD_BINARIESDIRECTORY)) {
-        $logFile = "$Env:TF_BUILD_BINARIESDIRECTORY\logs\post_build_$arch_$flavor.log"
+        $logFile = "${Env:TF_BUILD_BINARIESDIRECTORY}\logs\post_build_${arch}_${flavor}.log"
         if (Test-Path -Path $logFile) {
             Remove-Item $logFile -Force
         }
     }
 
-
     WriteMessage "======================================================================================"
     WriteMessage "Post build script for $arch $flavor";
     WriteMessage "======================================================================================"
@@ -63,7 +76,7 @@ if ($arch -eq "*") {
     WriteMessage "BVT Command  : $bvtcmdpath"
     WriteMessage ""
 
-    $srcsrvcmd = ("{0} {1} {2} {3}\bin\{4}_{5}\*.pdb" -f $srcsrvcmdpath, $repo, $srcpath, $binpath, $arch, $flavor);
+    $srcsrvcmd = ("{0} {1} {2} {3}\bin\{4}_{5}{6}\*.pdb" -f $srcsrvcmdpath, $repo, $srcpath, $binpath, $arch, $flavor, $buildTypeSuffix);
     $pogocmd = ("{0} {1} {2}" -f $pogoscript, $arch, $flavor);
     $prefastlog = ("{0}\logs\PrefastCheck_{1}_{2}.log" -f $binpath, $arch, $flavor);
     $prefastcmd = "$PSScriptRoot\check_prefast_error.ps1 -directory $objpath -logFile $prefastlog";
@@ -95,4 +108,3 @@ if ($arch -eq "*") {
 }
 
 exit $global:exitcode
-

+ 70 - 20
Build/scripts/pre_build.ps1

@@ -3,7 +3,6 @@
 # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 #-------------------------------------------------------------------------------------------------------
 
-#
 # Pre-Build script
 #
 # This script is fairly simple. It checks if it's running
@@ -13,20 +12,25 @@
 # output to make it easy to inspect builds.
 #
 # Require Environment:
-#   $TF_BUILD_SOURCEGETVERSION
-#   $TF_BUILD_DROPLOCATION
+#   $Env:TF_BUILD_SOURCEGETVERSION
+#   $Env:TF_BUILD_DROPLOCATION
 #
-# Inferable Environment:
-#   $TF_BUILD_SOURCESDIRECTORY
-#   $TF_BUILD_BUILDBINARIESDIRECTORY
-#   $TF_BUILD_BUILDDIRECTORY
+# Inferable Environment (if not specified, inferred by pre_post_util.ps1):
+#   $Env:TF_BUILD_SOURCESDIRECTORY  (a.k.a. $srcpath)
+#   $Env:TF_BUILD_BUILDDIRECTORY    (a.k.a. $objpath)
+#   $Env:TF_BUILD_BINARIESDIRECTORY (a.k.a. $binpath)
 #
 # Optional information:
-#   $TF_BUILD_BUILDDEFINITIONNAME
-#   $TF_BUILD_BUILDNUMBER
-#   $TF_BUILD_BUILDURI
+#   $Env:TF_BUILD_BUILDDEFINITIONNAME
+#   $Env:TF_BUILD_BUILDNUMBER
+#   $Env:TF_BUILD_BUILDURI
 
 param (
+    [ValidateSet("x86", "x64", "arm", "")]
+    [string]$arch = "",
+    [ValidateSet("debug", "release", "test", "codecoverage", "")]
+    [string]$flavor = "",
+
     [string]$srcpath = "",
     [string]$binpath = "",
     [string]$objpath = "",
@@ -34,13 +38,13 @@ param (
     [string]$oauth
 )
 
-$OutterScriptRoot = $PSScriptRoot;
+$OuterScriptRoot = $PSScriptRoot;
 . "$PSScriptRoot\pre_post_util.ps1"
 if (($logFile -eq "") -and (Test-Path Env:\TF_BUILD_BINARIESDIRECTORY)) {
     if (-not(Test-Path -Path "$Env:TF_BUILD_BINARIESDIRECTORY\logs")) {
         $dummy = New-Item -Path "$Env:TF_BUILD_BINARIESDIRECTORY\logs" -ItemType Directory -Force
     }
-    $logFile = "$Env:TF_BUILD_BINARIESDIRECTORY\logs\pre_build.log"
+    $logFile = "$Env:TF_BUILD_BINARIESDIRECTORY\logs\pre_build_${arch}_${flavor}.log"
     if (Test-Path -Path $logFile) {
         Remove-Item $logFile -Force
     }
@@ -48,6 +52,30 @@ if (($logFile -eq "") -and (Test-Path Env:\TF_BUILD_BINARIESDIRECTORY)) {
 
 WriteCommonArguments;
 
+#
+# Create packages.config files
+#
+
+$packagesConfigFileText = @"
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="MicroBuild.Core" version="0.2.0" targetFramework="native" developmentDependency="true" />
+</packages>
+"@
+
+$PackagesFiles = Get-ChildItem -Path $Env:TF_BUILD_SOURCESDIRECTORY *.vcxproj -Recurse `
+    | % { Join-Path $_.DirectoryName "packages.config" }
+
+foreach ($file in $PackagesFiles) {
+    if (-not (Test-Path $file)) {
+        Write-Output $packagesConfigFileText | Out-File $file -Encoding utf8
+    }
+}
+
+#
+# Create build metadata
+#
+
 if (Test-Path Env:\TF_BUILD_SOURCEGETVERSION)
 {
     $commitHash = ($Env:TF_BUILD_SOURCEGETVERSION).split(':')[2]
@@ -67,7 +95,6 @@ if (Test-Path Env:\TF_BUILD_SOURCEGETVERSION)
     Write-Output "TF_BUILD_BUILDURI = $Env:TF_BUILD_BUILDURI" | Out-File $outputFile -Append
     Write-Output "" | Out-File $outputFile -Append
 
-
     # Get the git remote path and construct the rest API URI
     $remote = (iex "$gitExe remote -v")[0].split()[1].replace("_git", "_apis/git/repositories");
     $remote = $remote.replace("mshttps", "https");
@@ -79,21 +106,41 @@ if (Test-Path Env:\TF_BUILD_SOURCEGETVERSION)
     $info = Invoke-RestMethod -Headers $header -Uri $uri -Method GET
 
     $buildDate = ([datetime]$info.push.date).toString("yyMMdd-HHmm")
-    $buildPushId = $info.push.pushId;
-    $buildPushIdPart1 = [int]($buildPushId / 65536);
-    $buildPushIdPart2 = [int]($buildPushId % 65536);
-    Write-Output ("PushId = $buildPushId ({0}.{1})" -f $buildPushIdPart1.ToString("00000"), $buildPushIdPart2.ToString("00000")) | Out-File $outputFile -Append
-    Write-Output "PushDate = $buildDate" | Out-File $outputFile -Append
-    Write-Output "" | Out-File $outputFile -Append
+    $buildPushId = $info.push.pushId
+    $buildPushIdPart1 = [int]([math]::Floor($buildPushId / 65536))
+    $buildPushIdPart2 = [int]($buildPushId % 65536)
+    $buildPushIdString = "{0}.{1}" -f $buildPushIdPart1.ToString("00000"), $buildPushIdPart2.ToString("00000")
+
+    Write-Output "PushId = $buildPushId $buildPushIdString" | Out-File $outputFile -Append
+    Write-Output "PushDate = $buildDate"                    | Out-File $outputFile -Append
+    Write-Output ""                                         | Out-File $outputFile -Append
 
     # commit message
     $command = "$gitExe log -1 --name-status -p $commitHash"
     iex $command | Out-File $outputFile -Append
     Pop-Location
 
-
     # commit hash
     $buildCommit = ($Env:TF_BUILD_SOURCEGETVERSION).SubString(14);
+    $commitHash = $buildCommit.Split(":")[1]
+
+    $outputJsonFile = Join-Path -Path $outputDir -ChildPath "change.json"
+    $changeJson = New-Object System.Object
+
+    $changeJson | Add-Member -type NoteProperty -name BuildDefinitionName -value $Env:TF_BUILD_BUILDDEFINITIONNAME
+    $changeJson | Add-Member -type NoteProperty -name BuildNumber -value $Env:TF_BUILD_BUILDNUMBER
+    $changeJson | Add-Member -type NoteProperty -name BuildDate -value $buildDate
+    $changeJson | Add-Member -type NoteProperty -name BuildUri -value $Env:TF_BUILD_BUILDURI
+    $changeJson | Add-Member -type NoteProperty -name Branch -value $Env:BranchName
+    $changeJson | Add-Member -type NoteProperty -name CommitHash -value $commitHash
+    $changeJson | Add-Member -type NoteProperty -name PushId -value $buildPushId
+    $changeJson | Add-Member -type NoteProperty -name PushIdPart1 -value $buildPushIdPart1
+    $changeJson | Add-Member -type NoteProperty -name PushIdPart2 -value $buildPushIdPart2
+    $changeJson | Add-Member -type NoteProperty -name PushIdString -value $buildPushIdString
+    $changeJson | Add-Member -type NoteProperty -name SourceGetVersion -value $Env:TF_BUILD_SOURCEGETVERSION
+
+    $changeJson | ConvertTo-Json | Write-Output
+    $changeJson | ConvertTo-Json | Out-File $outputJsonFile -Encoding ascii
 
     $buildInfoOutputDir = $objpath
     if (-not(Test-Path -Path $buildInfoOutputDir)) {
@@ -118,7 +165,10 @@ if (Test-Path Env:\TF_BUILD_SOURCEGETVERSION)
     Write-Output ($propsFile -f $binpath, $objpath, $buildPushIdPart1, $buildPushIdPart2, $buildCommit, $buildDate) | Out-File $buildInfoOutputFile
 }
 
+#
 # Clean up code analysis summary files in case they get left behind
+#
+
 if (Test-Path $objpath) {
     Get-ChildItem $objpath -include vc.nativecodeanalysis.all.xml -recurse | Remove-Item
 }

+ 4 - 7
Build/scripts/pre_post_util.ps1

@@ -20,8 +20,7 @@ function WriteCommonArguments() {
     WriteMessage "Binaries Path: $binpath"
 }
 
-function GetGitPath()
-{
+function GetGitPath() {
     $gitExe = "git.exe"
 
     if (!(Get-Command $gitExe -ErrorAction SilentlyContinue)) {
@@ -33,8 +32,6 @@ function GetGitPath()
     return $gitExe;
 }
 
-$srcpath = UseValueOrDefault $srcpath "$env:TF_BUILD_SOURCESDIRECTORY" (Resolve-Path "$OutterScriptRoot\..\..");
-$binpath = UseValueOrDefault $binpath "$env:TF_BUILD_BINARIESDIRECTORY" "$srcpath\Build\VcBuild\bin\$arch_$flavor";
-$objpath = UseValueOrDefault $objpath "$env:TF_BUILD_BUILDDIRECTORY" "$srcpath\Build\VcBuild\obj\$arch_$flavor";
-
-
+$srcpath = UseValueOrDefault $srcpath "$env:TF_BUILD_SOURCESDIRECTORY" (Resolve-Path "$OuterScriptRoot\..\..");
+$objpath = UseValueOrDefault $objpath "$env:TF_BUILD_BUILDDIRECTORY" "${srcpath}\Build\VcBuild\obj\${arch}_${flavor}";
+$binpath = UseValueOrDefault $binpath "$env:TF_BUILD_BINARIESDIRECTORY" "${srcpath}\Build\VcBuild";

+ 4 - 8
Build/scripts/util.ps1

@@ -3,20 +3,16 @@
 # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 #-------------------------------------------------------------------------------------------------------
 
-function WriteMessage($str)
-{
+function WriteMessage($str) {
     Write-Output $str
-    if ($logFile -ne "")
-    {
+    if ($logFile -ne "") {
         Write-Output $str | Out-File $logFile -Append
     }
 }
 
-function WriteErrorMessage($str)
-{
+function WriteErrorMessage($str) {
     $host.ui.WriteErrorLine($str);
-    if ($logFile -ne "")
-    {
+    if ($logFile -ne "") {
         Write-Output $str | Out-File $logFile -Append
     }
 }

+ 19 - 0
bin/ChakraCore/ChakraCore.vcxproj

@@ -80,6 +80,19 @@
       </AdditionalIncludeDirectories>
     </ResourceCompile>
   </ItemGroup>
+  <PropertyGroup Condition="'$(IsPogoBuild)'=='true'" Label="Configuration">
+    <WholeProgramOptimization Condition="'$(POGO_TYPE)'=='PGI'">PGInstrument</WholeProgramOptimization>
+    <WholeProgramOptimization Condition="'$(POGO_TYPE)'=='PGO'">PGOptimize</WholeProgramOptimization>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(IsPogoBuild)'=='true'">
+    <Link>
+      <LinkTimeCodeGeneration Condition="'$(POGO_TYPE)'=='PGI'">PGInstrument</LinkTimeCodeGeneration>
+      <LinkTimeCodeGeneration Condition="'$(POGO_TYPE)'=='PGO'">PGOptimization</LinkTimeCodeGeneration>
+    </Link>
+    <ClCompile>
+      <WholeProgramOptimization>true</WholeProgramOptimization>
+    </ClCompile>
+  </ItemDefinitionGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\lib\jsrt\Chakra.Jsrt.vcxproj">
       <Project>{706083f7-6aa4-4558-a153-6352ef9220f5}</Project>
@@ -139,6 +152,12 @@
   <ItemGroup>
     <ClInclude Include="TestHooks.h" />
   </ItemGroup>
+  <!-- Conditionally include the group of files to sign because MBv2 knows what to do with this but the old build definition gets confused. -->
+  <ItemGroup Condition="'$(VSO_MICROBUILD_V2)'=='True' AND '$(POGO_TYPE)'!='PGI'">
+    <FilesToSign Include="$(OutDir)\ChakraCore.dll">
+      <Authenticode>Microsoft</Authenticode>
+    </FilesToSign>
+  </ItemGroup>
   <Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
 </Project>

+ 6 - 0
bin/ch/ch.vcxproj

@@ -77,6 +77,12 @@
       <Project>{1876e800-ad77-48c4-a2f7-e5265f24ac38}</Project>
     </ProjectReference>
   </ItemGroup>
+  <!-- Conditionally include the group of files to sign because MBv2 knows what to do with this but the old build definition gets confused. -->
+  <ItemGroup Condition="'$(VSO_MICROBUILD_V2)'=='True' AND '$(POGO_TYPE)'!='PGI'">
+    <FilesToSign Include="$(OutDir)\ch.exe">
+      <Authenticode>Microsoft</Authenticode>
+    </FilesToSign>
+  </ItemGroup>
   <Import Project="$(BuildConfigPropsPath)Chakra.Build.targets" Condition="exists('$(BuildConfigPropsPath)Chakra.Build.targets')" />
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
 </Project>

+ 1 - 0
jenkins/check_copyright.sh

@@ -29,6 +29,7 @@ git diff --name-only `git merge-base origin/master HEAD` HEAD |
     grep -v -E '\.vcxproj$' |
     grep -v -E '\.filters$' |
     grep -v -E '\.targets$' |
+    grep -v -E '\.nuspec$' |
     grep -v -E '\.def$' |
     grep -v -E '\.inc$' |
     grep -v -E 'test/benchmarks/.*\.js$' |

+ 2 - 0
test/es6/rlexe.xml

@@ -121,6 +121,7 @@
       <tags>BugFix</tags>
     </default>
   </test>
+  <!-- OS BUG 7117880
   <test>
     <default>
       <files>toStringTag.js</files>
@@ -128,6 +129,7 @@
       <tags>exclude_dynapogo</tags>
     </default>
   </test>
+  -->
   <test>
     <default>
       <files>proto_basic.js</files>