Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 96f2027

Browse files
Daniel Poddergkhanna79
authored andcommitted
Fix optdata restore functionality (port #11935) (#12044)
* Port [Fix optdata restore functionality (#11935)] from master * Fixup optdata package version
1 parent 33ceeb7 commit 96f2027

File tree

11 files changed

+102
-102
lines changed

11 files changed

+102
-102
lines changed

build.cmd

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,6 @@ REM === Restore optimization profile data
236236
REM ===
237237
REM =========================================================================================
238238

239-
REM Parse the package version out of project.json so that we can pass it on to CMake
240-
where /q python || (
241-
echo %__MsgPrefix%Error: Python not found on PATH, please make sure that it is installed.
242-
exit /b 1
243-
)
244-
set OptDataProjectJsonPath=%__ProjectDir%\src\.nuget\optdata\project.json
245-
if EXIST "%OptDataProjectJsonPath%" (
246-
for /f "tokens=*" %%s in ('python "%__ProjectDir%\extract-from-json.py" -rf "%OptDataProjectJsonPath%" dependencies optimization.PGO.CoreCLR') do @(
247-
set __PgoOptDataVersion=%%s
248-
)
249-
for /f "tokens=*" %%s in ('python "%__ProjectDir%\extract-from-json.py" -rf "%OptDataProjectJsonPath%" dependencies optimization.IBC.CoreCLR') do @(
250-
set __IbcOptDataVersion=%%s
251-
)
252-
)
253-
254239
if %__RestoreOptData% EQU 1 (
255240
echo %__MsgPrefix%Restoring the OptimizationData Package
256241
@call %__ProjectDir%\run.cmd sync -optdata
@@ -260,6 +245,20 @@ if %__RestoreOptData% EQU 1 (
260245
)
261246
)
262247

248+
REM Parse the optdata package versions out of msbuild so that we can pass them on to CMake
249+
set DotNetCli=%__ProjectDir%\Tools\dotnetcli\dotnet.exe
250+
if not exist "%DotNetCli%" (
251+
echo Assertion failed: dotnet.exe not found at path "%DotNetCli%"
252+
exit /b 1
253+
)
254+
set OptDataProjectFilePath=%__ProjectDir%\src\.nuget\optdata\optdata.csproj
255+
for /f "tokens=*" %%s in ('%DotNetCli% msbuild "%OptDataProjectFilePath%" /t:DumpPgoDataPackageVersion /nologo') do @(
256+
set __PgoOptDataVersion=%%s
257+
)
258+
for /f "tokens=*" %%s in ('%DotNetCli% msbuild "%OptDataProjectFilePath%" /t:DumpIbcDataPackageVersion /nologo') do @(
259+
set __IbcOptDataVersion=%%s
260+
)
261+
263262
REM =========================================================================================
264263
REM ===
265264
REM === Build the CLR VM

build.proj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,8 @@
2424
<Delete Files="$(BinDir)System.Private.CoreLib.*" />
2525
</Target>
2626

27-
<PropertyGroup>
28-
<OptDataProjectJson>$(SourceDir).nuget/optdata/project.json</OptDataProjectJson>
29-
<OptDataPackageFeed>https://dotnet.myget.org/F/dotnet-core-optimization-data/api/v3/index.json</OptDataPackageFeed>
30-
</PropertyGroup>
3127
<Target Name="RestoreOptData">
32-
<Exec Condition="Exists('$(OptDataProjectJson)')" Command="$(DnuRestoreCommand) &quot;$(OptDataProjectJson)&quot; --source &quot;$(OptDataPackageFeed)&quot;" />
28+
<Exec Command="$(DotnetRestoreCommand) $(SourceDir).nuget/optdata/optdata.csproj" />
3329
</Target>
3430

3531
<!--

build.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ restore_optdata()
141141
echo "Failed to restore the optimization data package."
142142
exit 1
143143
fi
144+
145+
# Parse the optdata package versions out of msbuild so that we can pass them on to CMake
146+
local DotNetCli="$__ProjectRoot/Tools/dotnetcli/dotnet"
147+
if [ ! -f $DotNetCli ]; then
148+
echo "Assertion failed: dotnet CLI not found at '$DotNetCli'"
149+
exit 1
150+
fi
151+
local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj"
152+
__PgoOptDataVersion=$($DotNetCli msbuild $OptDataProjectFilePath /t:DumpPgoDataPackageVersion /nologo | sed 's/^\s*//')
153+
__IbcOptDataVersion=$($DotNetCli msbuild $OptDataProjectFilePath /t:DumpIbcDataPackageVersion /nologo | sed 's/^\s*//')
144154
fi
145155
}
146156

@@ -899,13 +909,6 @@ if [ $__CrossBuild == 1 ]; then
899909
fi
900910
fi
901911

902-
# Parse the optdata package version from its project.json file
903-
optDataProjectJsonPath="$__ProjectRoot/src/.nuget/optdata/project.json"
904-
if [ -f $optDataProjectJsonPath ]; then
905-
__PgoOptDataVersion=$("$__ProjectRoot/extract-from-json.py" -rf $optDataProjectJsonPath dependencies optimization.PGO.CoreCLR)
906-
__IbcOptDataVersion=$("$__ProjectRoot/extract-from-json.py" -rf $optDataProjectJsonPath dependencies optimization.IBC.CoreCLR)
907-
fi
908-
909912
# init the target distro name
910913
initTargetDistroRid
911914

dir.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
<RoslynPackageName>Microsoft.Net.ToolsetCompilers</RoslynPackageName>
2222
</PropertyGroup>
2323

24+
<!-- Profile-based optimization data package versions -->
25+
<PropertyGroup>
26+
<PgoDataPackageVersion>2.0.0-release-20170531-3000</PgoDataPackageVersion>
27+
<!--<IbcDataPackageVersion></IbcDataPackageVersion>-->
28+
</PropertyGroup>
29+
2430
<!--
2531
Switching to the .NET Core version of the BuildTools tasks seems to break numerous scenarios, such as VS intellisense and resource designer
2632
as well as runnning the build on mono. Until we can get these sorted out we will continue using the .NET 4.5 version of the tasks.

extract-from-json.py

Lines changed: 0 additions & 56 deletions
This file was deleted.

pgosupport.cmake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ function(add_pgo TargetName)
2020
"${CLR_CMAKE_PACKAGES_DIR}/${CLR_CMAKE_OPTDATA_PACKAGEWITHRID}/${CLR_CMAKE_OPTDATA_VERSION}/data/${ProfileFileName}"
2121
ProfilePath
2222
)
23+
# NuGet packages are restored to lowercase paths
24+
string(TOLOWER "${ProfilePath}" ProfilePath)
2325

2426
if(CLR_CMAKE_PGO_INSTRUMENT)
2527
if(WIN32)
@@ -40,7 +42,7 @@ function(add_pgo TargetName)
4042
else(WIN32)
4143
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
4244
if(HAVE_LTO)
43-
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath})
45+
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-use=${ProfilePath} -Wno-profile-instr-out-of-date)
4446
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-ld=gold -fprofile-instr-use=${ProfilePath}")
4547
endif(HAVE_LTO)
4648
endif(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)

src/.nuget/optdata/nuget.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="myget.org dotnet-core-optimization-data" value="https://dotnet.myget.org/F/dotnet-core-optimization-data/api/v3/index.json" />
5+
</packageSources>
6+
</configuration>

src/.nuget/optdata/optdata.csproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
5+
<PropertyGroup>
6+
<TargetFramework>netstandard</TargetFramework>
7+
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
8+
<RuntimeIdentifiers>win7-x64;win7-x86;linux-x64</RuntimeIdentifiers>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="optimization.PGO.CoreCLR" Version="$(PgoDataPackageVersion)" Condition="'$(PgoDataPackageVersion)'!=''" />
13+
<PackageReference Include="optimization.IBC.CoreCLR" Version="$(IbcDataPackageVersion)" Condition="'$(IbcDataPackageVersion)'!=''" />
14+
</ItemGroup>
15+
16+
<Target Name="DumpPgoDataPackageVersion">
17+
<Message Importance="high" Text="$(PgoDataPackageVersion)" />
18+
</Target>
19+
20+
<Target Name="DumpIbcDataPackageVersion">
21+
<Message Importance="high" Text="$(IbcDataPackageVersion)" />
22+
</Target>
23+
24+
</Project>

tests/scripts/optdata/bootstrap.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"""
88

99
import argparse
10-
import json
1110
import os
1211
from os import path
1312
import shutil
1413
import subprocess
1514
import sys
15+
import xml.etree.ElementTree as ET
1616

1717
# Display the docstring if the user passes -h|--help
1818
argparse.ArgumentParser(description=__doc__).parse_args()
@@ -24,8 +24,8 @@
2424
assert path.exists(NUGET_SRC_DIR), \
2525
"Expected %s to exist; please check whether REPO_ROOT is really %s" % (NUGET_SRC_DIR, REPO_ROOT)
2626

27-
ORIGIN_FILE = path.join(SCRIPT_ROOT, 'project.json')
28-
TARGET_FILE = path.join(NUGET_SRC_DIR, 'optdata', 'project.json')
27+
ORIGIN_FILE = path.join(SCRIPT_ROOT, 'optdata.csproj')
28+
TARGET_FILE = path.join(NUGET_SRC_DIR, 'optdata', 'optdata.csproj')
2929

3030
ARCH_LIST = ['x64', 'x86']
3131
TOOL_LIST = ['IBC', 'PGO']
@@ -40,9 +40,12 @@ def get_buildos():
4040

4141
def get_optdata_version(tool):
4242
"""Returns the version string specified in project.json for the given tool."""
43-
package_name = 'optimization.%s.CoreCLR' % (tool)
44-
with open(ORIGIN_FILE) as json_file:
45-
return json.load(json_file)['dependencies'][package_name]
43+
element_name = {
44+
'IBC': 'IbcDataPackageVersion',
45+
'PGO': 'PgoDataPackageVersion',
46+
}[tool]
47+
root = ET.parse(ORIGIN_FILE)
48+
return root.findtext('./PropertyGroup/{}'.format(element_name))
4649

4750
def get_optdata_dir(tool, arch):
4851
"""Returns an absolute path to the directory that should contain optdata given a tool,arch"""
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
4+
5+
<PropertyGroup>
6+
<TargetFramework>netstandard</TargetFramework>
7+
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
8+
<RuntimeIdentifiers>win7-x64;win7-x86;linux-x64</RuntimeIdentifiers>
9+
</PropertyGroup>
10+
11+
<PropertyGroup>
12+
<PgoDataPackageVersion>99.99.99-test</PgoDataPackageVersion>
13+
<IbcDataPackageVersion>99.99.99-test</IbcDataPackageVersion>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<PackageReference Include="optimization.PGO.CoreCLR" Version="$(PgoDataPackageVersion)" Condition="'$(PgoDataPackageVersion)'!=''" />
18+
<PackageReference Include="optimization.IBC.CoreCLR" Version="$(IbcDataPackageVersion)" Condition="'$(IbcDataPackageVersion)'!=''" />
19+
</ItemGroup>
20+
21+
<Target Name="DumpPgoDataPackageVersion">
22+
<Message Importance="high" Text="$(PgoDataPackageVersion)" />
23+
</Target>
24+
25+
<Target Name="DumpIbcDataPackageVersion">
26+
<Message Importance="high" Text="$(IbcDataPackageVersion)" />
27+
</Target>
28+
29+
</Project>

0 commit comments

Comments
 (0)