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

Commit 5ab6634

Browse files
authored
Add support for building CoreCLR using python3 (#28087)
This is a combined fix from 3 different PRs and one additional fix for 2.1: - #19043 - #19356 - #22145 The 2.1-specific fix is that python is is only used as a fallback, in case all other python program names dont work. As for the original PRs, they perform these changes: build.sh and build.cmd contain logic to identify a working version of python to use. System.Private.CoreLib ignores that and directly invokes 'python', which may not work, or even execute a different program. Fix that. The windows build scripts try finding python in order of python3, python2 and then python. The unix build scripts dont. They just try python2 variants and then fail. This change makes brings them closer together by letting users build using only python3. Use the same logic in CMakeLists.txt that's used in build.sh/build.cmd to lookup python.
1 parent fd74e6c commit 5ab6634

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)
3636
OPTION(CLR_CMAKE_WARNINGS_ARE_ERRORS "Warnings are errors" ON)
3737

3838
# Ensure that python is present
39-
find_program(PYTHON NAMES python2.7 python2 python)
39+
find_program(PYTHON NAMES python2.7 python2 python python3)
4040
if (PYTHON STREQUAL "PYTHON-NOTFOUND")
4141
message(FATAL_ERROR "PYTHON not found: Please install Python 2.7.9 or later from https://www.python.org/downloads/")
4242
endif()

build.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export ghprbCommentBody=
77

88
# resolve python-version to use
99
if [ "$PYTHON" == "" ] ; then
10-
if ! PYTHON=$(command -v python2.7 || command -v python2 || command -v python)
10+
if ! PYTHON=$(command -v python2.7 || command -v python2 || command -v python || command -v python3)
1111
then
12-
echo "Unable to locate build-dependency python2.x!" 1>&2
12+
echo "Unable to locate build-dependency python!" 1>&2
1313
exit 1
1414
fi
1515
fi
@@ -18,10 +18,12 @@ fi
1818
# useful in case of explicitly set option.
1919
if ! command -v $PYTHON > /dev/null
2020
then
21-
echo "Unable to locate build-dependency python2.x ($PYTHON)!" 1>&2
21+
echo "Unable to locate build-dependency python ($PYTHON)!" 1>&2
2222
exit 1
2323
fi
2424

25+
export PYTHON
26+
2527
usage()
2628
{
2729
echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipmscorlib] [-skiptests] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]"

src/mscorlib/System.Private.CoreLib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@
640640
<PropertyGroup>
641641
<CMakeDefinitionSaveFile>$(IntermediateOutputPath)..\cmake.definitions</CMakeDefinitionSaveFile>
642642
</PropertyGroup>
643-
<Exec Command="python $(MSBuildThisFileDirectory)..\scripts\check-definitions.py &quot;$(CMakeDefinitionSaveFile)&quot; &quot;$(DefineConstants)&quot; &quot;$(IgnoreDefineConstants)&quot; " />
643+
<Exec Command="&quot;$(PYTHON)&quot; $(MSBuildThisFileDirectory)..\scripts\check-definitions.py &quot;$(CMakeDefinitionSaveFile)&quot; &quot;$(DefineConstants)&quot; &quot;$(IgnoreDefineConstants)&quot; " />
644644
</Target>
645645
<PropertyGroup Condition="'$(BuildOS)' == 'Windows_NT'">
646646
<EnableDotnetAnalyzers Condition="'$(EnableDotnetAnalyzers)'==''">true</EnableDotnetAnalyzers>

0 commit comments

Comments
 (0)