@@ -120,9 +120,6 @@ def validate_arg(arg, check):
120
120
validate_arg (build_type , lambda item : item in valid_build_types )
121
121
validate_arg (fx_branch , lambda item : True )
122
122
123
- if fx_commit is None :
124
- fx_commit = 'HEAD'
125
-
126
123
if clr_root is None :
127
124
clr_root = nth_dirname (os .path .abspath (sys .argv [0 ]), 3 )
128
125
else :
@@ -198,6 +195,53 @@ def main(args):
198
195
'Product' ,
199
196
'%s.%s.%s' % (clr_os , arch , build_type ))
200
197
198
+ # If the user doesn't specify a specific corefx commit hash to use, try to find the matching
199
+ # commit hash in the coreclr repro. If the matching hash can't be found, use 'HEAD'.
200
+ #
201
+ # We find the matching corefx commit hash by first parsing file 'dependencies.props' at the root
202
+ # of the coreclr repro, looking for this:
203
+ # <MicrosoftPrivateCoreFxNETCoreAppPackageVersion>4.5.0-preview1-26112-01</MicrosoftPrivateCoreFxNETCoreAppPackageVersion>
204
+ # This determines the corefx package version that matches. Next, we look for the version.txt
205
+ # file in the package cache, e.g.,
206
+ # <coreclr_root>\packages\microsoft.private.corefx.netcoreapp\4.5.0-preview1-26112-01\version.txt
207
+ # The contents of this file is exactly the git commit hash we need to use, e.g.:
208
+ # 197a0699b08087ea85581679afdd9fd7b5c465c3
209
+ # The version.txt file is created when the corefx package is restored, which happens when doing one of:
210
+ # Windows: tests\runtests.cmd GenerateLayoutOnly
211
+ # non-Windows: build-test.sh generatelayoutonly
212
+ #
213
+ # It would also be possible to not depend on the package already being downloaded, but instead
214
+ # download the correct package here, using the determined "MicrosoftPrivateCoreFxNETCoreAppPackageVersion"
215
+ # package version, e.g.:
216
+ # https://dotnet.myget.org/F/dotnet-core/api/v2/package/Microsoft.Private.CoreFx.NETCoreApp/4.5.0-preview1-26112-01
217
+ # and then extracting the ZIP archive to find the version.txt file.
218
+ #
219
+ # This might get easier if the corefx commit hash is added directly to dependencies.props, as
220
+ # discussed in https://github.com/dotnet/buildtools/issues/1141.
221
+
222
+ if fx_commit is None :
223
+ # Default to 'HEAD'; overwrite if we find an actual commit hash.
224
+ fx_commit = 'HEAD'
225
+ try :
226
+ dependencies_filename = os .path .join (clr_root , 'dependencies.props' )
227
+ if os .path .isfile (dependencies_filename ):
228
+ with open (dependencies_filename , 'r' ) as dependencies_file_handle :
229
+ dependencies_file = dependencies_file_handle .read ()
230
+ matchObj = re .search (r'.*<MicrosoftPrivateCoreFxNETCoreAppPackageVersion>(.+)</MicrosoftPrivateCoreFxNETCoreAppPackageVersion>.*' , dependencies_file )
231
+ if matchObj :
232
+ package_version_string = matchObj .group (1 )
233
+ version_filename = os .path .join (clr_root , 'packages' , 'microsoft.private.corefx.netcoreapp' , package_version_string , 'version.txt' )
234
+ if os .path .isfile (version_filename ):
235
+ with open (version_filename , 'r' ) as f :
236
+ version_file = f .readlines ()
237
+ fx_commit = version_file [0 ].strip ()
238
+ log ("Using matching corefx commit hash: %s" % fx_commit )
239
+ except :
240
+ log ("Failed to find matching corefx commit hash" )
241
+
242
+ if fx_commit == 'HEAD' :
243
+ log ("Using default corefx commit hash: HEAD" )
244
+
201
245
# corefx creates both files that are read-only and files that include non-ascii
202
246
# characters. Using onerror=del_rw allows us to delete all of the read-only files.
203
247
# To delete the files with non-ascii characters, when rmtree fails due to those
@@ -250,9 +294,6 @@ def main(args):
250
294
os .putenv ('HOME' , fx_home )
251
295
log ('HOME=' + fx_home )
252
296
253
- # Determine the RID to specify the to corefix build scripts. This seems to
254
- # be way harder than it ought to be.
255
-
256
297
# Gather up some arguments to pass to both build and build-tests.
257
298
258
299
config_args = '-Release -os:%s -buildArch:%s' % (clr_os , arch )
0 commit comments