Skip to content

Commit 15220ec

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24775: build: Do not modify common.init.vcxproj directly
ba0bf79 build: Do not modify `common.init.vcxproj` directly (Hennadii Stepanov) 2391fb7 build, refactor: Add set_properties() to msvc-autogen.py (Hennadii Stepanov) Pull request description: When building with MSVC, and using a non-default toolset, the following command ``` >python build_msvc\msvc-autogen.py -toolset v143 ``` actually modifies the source tree: ```diff >git diff warning: LF will be replaced by CRLF in build_msvc/common.init.vcxproj. The file will have its original line endings in your working directory diff --git a/build_msvc/common.init.vcxproj b/build_msvc/common.init.vcxproj index 0cbe2effd..44b7efff3 100644 --- a/build_msvc/common.init.vcxproj +++ b/build_msvc/common.init.vcxproj @@ -39,7 +39,7 @@ <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration"> <LinkIncremental>false</LinkIncremental> <UseDebugLibraries>false</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <CharacterSet>Unicode</CharacterSet> <GenerateManifest>No</GenerateManifest> <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> @@ -49,7 +49,7 @@ <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration"> <LinkIncremental>true</LinkIncremental> <UseDebugLibraries>true</UseDebugLibraries> - <PlatformToolset>v142</PlatformToolset> + <PlatformToolset>v143</PlatformToolset> <CharacterSet>Unicode</CharacterSet> <OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir> <IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir> ``` This PR fixes this bug. ACKs for top commit: sipsorcery: tACK ba0bf79. Tree-SHA512: 614662fdbce6aea7a09fac5bba1e3632dd921b0d8f89c448566f527bf5df049ae6bacd951662825188b88324aec7e3416b58237e0a227d7520e2a75223b0edd0
2 parents 9ce1c50 + ba0bf79 commit 15220ec

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

build_msvc/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bench_bitcoin/bench_bitcoin.vcxproj
2222
libtest_util/libtest_util.vcxproj
2323

2424
/bitcoin_config.h
25+
/common.init.vcxproj
2526

2627
*/Win32
2728
libbitcoin_qt/QtGeneratedFiles/*

build_msvc/common.init.vcxproj renamed to build_msvc/common.init.vcxproj.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
4040
<LinkIncremental>false</LinkIncremental>
4141
<UseDebugLibraries>false</UseDebugLibraries>
42-
<PlatformToolset>v142</PlatformToolset>
42+
<PlatformToolset>@TOOLSET@</PlatformToolset>
4343
<CharacterSet>Unicode</CharacterSet>
4444
<GenerateManifest>No</GenerateManifest>
4545
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
@@ -49,7 +49,7 @@
4949
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
5050
<LinkIncremental>true</LinkIncremental>
5151
<UseDebugLibraries>true</UseDebugLibraries>
52-
<PlatformToolset>v142</PlatformToolset>
52+
<PlatformToolset>@TOOLSET@</PlatformToolset>
5353
<CharacterSet>Unicode</CharacterSet>
5454
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(ProjectName)\</OutDir>
5555
<IntDir>$(Platform)\$(Configuration)\$(ProjectName)\</IntDir>

build_msvc/msvc-autogen.py

+9-14
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,6 @@ def parse_makefile(makefile):
5050
lib_sources[current_lib] = []
5151
break
5252

53-
def set_common_properties(toolset):
54-
with open(os.path.join(SOURCE_DIR, '../build_msvc/common.init.vcxproj'), 'r', encoding='utf-8') as rfile:
55-
s = rfile.read()
56-
s = re.sub('<PlatformToolset>.*?</PlatformToolset>', '<PlatformToolset>'+toolset+'</PlatformToolset>', s)
57-
with open(os.path.join(SOURCE_DIR, '../build_msvc/common.init.vcxproj'), 'w', encoding='utf-8',newline='\n') as wfile:
58-
wfile.write(s)
59-
6053
def parse_config_into_btc_config():
6154
def find_between( s, first, last ):
6255
try:
@@ -92,13 +85,18 @@ def find_between( s, first, last ):
9285
with open(os.path.join(SOURCE_DIR,'../build_msvc/bitcoin_config.h'), "w", encoding="utf8") as btc_config:
9386
btc_config.writelines(template)
9487

88+
def set_properties(vcxproj_filename, placeholder, content):
89+
with open(vcxproj_filename + '.in', 'r', encoding='utf-8') as vcxproj_in_file:
90+
with open(vcxproj_filename, 'w', encoding='utf-8') as vcxproj_file:
91+
vcxproj_file.write(vcxproj_in_file.read().replace(placeholder, content))
92+
9593
def main():
9694
parser = argparse.ArgumentParser(description='Bitcoin-core msbuild configuration initialiser.')
97-
parser.add_argument('-toolset', nargs='?',help='Optionally sets the msbuild platform toolset, e.g. v142 for Visual Studio 2019.'
95+
parser.add_argument('-toolset', nargs='?', default=DEFAULT_PLATFORM_TOOLSET,
96+
help='Optionally sets the msbuild platform toolset, e.g. v142 for Visual Studio 2019.'
9897
' default is %s.'%DEFAULT_PLATFORM_TOOLSET)
9998
args = parser.parse_args()
100-
if args.toolset:
101-
set_common_properties(args.toolset)
99+
set_properties(os.path.join(SOURCE_DIR, '../build_msvc/common.init.vcxproj'), '@TOOLSET@', args.toolset)
102100

103101
for makefile_name in os.listdir(SOURCE_DIR):
104102
if 'Makefile' in makefile_name:
@@ -110,10 +108,7 @@ def main():
110108
content += ' <ClCompile Include="..\\..\\src\\' + source_filename + '">\n'
111109
content += ' <ObjectFileName>$(IntDir)' + object_filename + '</ObjectFileName>\n'
112110
content += ' </ClCompile>\n'
113-
with open(vcxproj_filename + '.in', 'r', encoding='utf-8') as vcxproj_in_file:
114-
with open(vcxproj_filename, 'w', encoding='utf-8') as vcxproj_file:
115-
vcxproj_file.write(vcxproj_in_file.read().replace(
116-
'@SOURCE_FILES@\n', content))
111+
set_properties(vcxproj_filename, '@SOURCE_FILES@\n', content)
117112
parse_config_into_btc_config()
118113
copyfile(os.path.join(SOURCE_DIR,'../build_msvc/bitcoin_config.h'), os.path.join(SOURCE_DIR, 'config/bitcoin-config.h'))
119114
copyfile(os.path.join(SOURCE_DIR,'../build_msvc/libsecp256k1_config.h'), os.path.join(SOURCE_DIR, 'secp256k1/src/libsecp256k1-config.h'))

0 commit comments

Comments
 (0)