Skip to content

Commit 5a469bf

Browse files
committed
Fix JIT rolling build issue with non-JIT changes
When uploading a JIT rolling build, use the git hash of the most recent JIT change, not the git hash that was actually built. This handles the case where a JIT change kicked off an AzDO pipeline, but the pipeline didn't start until after one or more additional changes were merged. The AzDO pipelines appear to fetch with `-depth=20`, which should provide enough history for almost any case. Fixes dotnet#64392
1 parent d06d9c9 commit 5a469bf

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

eng/pipelines/coreclr/templates/build-jit-job.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
- script: $(PipScript) install --user --upgrade pip && $(PipScript) install --user azure.storage.blob==12.5.0 --force-reinstall
119119
displayName: Upgrade Pip to latest and install azure-storage-blob Python package
120120

121-
- script: $(PythonScript) $(Build.SourcesDirectory)/src/coreclr/scripts/jitrollingbuild.py upload -build_type $(buildConfig) -arch $(archType) -host_os $(osGroup) -git_hash $(Build.SourceVersion)
121+
- script: $(PythonScript) $(Build.SourcesDirectory)/src/coreclr/scripts/jitrollingbuild.py upload -build_type $(buildConfig) -arch $(archType) -host_os $(osGroup) -git_hash $(Build.SourceVersion) --use_latest_jit_change
122122
displayName: Upload JIT to Azure Storage
123123
env:
124124
CLRJIT_AZ_KEY: $(clrjit_key1) # secret key stored as variable in pipeline

src/coreclr/scripts/jitrollingbuild.py

+40-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@
7474

7575
git_hash_help = "git hash"
7676

77+
use_latest_jit_change_help = """\
78+
Starting with the given git hash, look backwards in the git log for the first change that includes any JIT
79+
change. We want to ensure that any git hash uploaded to the JIT rolling build store is a JIT change. This
80+
addresses a problem where Azure DevOps sometimes builds changes that come soon after a JIT change, instead of
81+
the JIT change itself.
82+
"""
83+
7784
target_dir_help = "Directory to put the downloaded JIT."
7885

7986
skip_cleanup_help = "Skip intermediate file removal."
@@ -97,6 +104,7 @@
97104
upload_parser = subparsers.add_parser("upload", description=upload_description, parents=[common_parser])
98105

99106
upload_parser.add_argument("-git_hash", required=True, help=git_hash_help)
107+
upload_parser.add_argument("--use_latest_jit_change", action="store_true", help=use_latest_jit_change_help)
100108
upload_parser.add_argument("-az_storage_key", help="Key for the clrjit Azure Storage location. Default: use the value of the CLRJIT_AZ_KEY environment variable.")
101109
upload_parser.add_argument("--skip_cleanup", action="store_true", help=skip_cleanup_help)
102110

@@ -458,6 +466,32 @@ def upload_blob(file, blob_name):
458466
# pdb_paths = [os.path.join(pdb_dir, item) for item in os.listdir(pdb_dir) if re.match(r'.*clrjit.*', item)]
459467
# files += pdb_paths
460468

469+
# Figure out which git hash to use for the upload. By default, it is the required coreclr_args.git_hash argument.
470+
# However, if "--use_latest_jit_change" is passed, we look backwards in the git log for the nearest git commit
471+
# with a JIT change (it could, and often will be, the same as the argument git_hash).
472+
jit_git_hash = coreclr_args.git_hash
473+
474+
if coreclr_args.use_latest_jit_change:
475+
# Do all the remaining commands, including a number of 'git' commands including relative paths,
476+
# from the root of the runtime repo.
477+
478+
with ChangeDir(coreclr_args.runtime_repo_location):
479+
# Enumerate the last change, starting with the jit_git_hash, that included JIT changes.
480+
command = [ "git", "log", "--pretty=format:%H", jit_git_hash, "-1", "--", "src/coreclr/jit/*" ]
481+
print("Invoking: {}".format(" ".join(command)))
482+
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
483+
stdout_change_list, _ = proc.communicate()
484+
return_code = proc.returncode
485+
change_list_hashes = []
486+
if return_code == 0:
487+
change_list_hashes = stdout_change_list.decode('utf-8').strip().splitlines()
488+
489+
if len(change_list_hashes) == 0:
490+
print("Couldn't find any JIT changes! Just using the argument git_hash")
491+
else:
492+
jit_git_hash = change_list_hashes[0]
493+
print("Using git_hash {}".format(jit_git_hash))
494+
461495
print("Uploading:")
462496
for item in files:
463497
print(" {}".format(item))
@@ -472,7 +506,7 @@ def upload_blob(file, blob_name):
472506
raise RuntimeError("Missing azure storage package.")
473507

474508
blob_service_client = BlobServiceClient(account_url=az_blob_storage_account_uri, credential=coreclr_args.az_storage_key)
475-
blob_folder_name = "{}/{}/{}/{}/{}".format(az_builds_root_folder, coreclr_args.git_hash, coreclr_args.host_os, coreclr_args.arch, coreclr_args.build_type)
509+
blob_folder_name = "{}/{}/{}/{}/{}".format(az_builds_root_folder, jit_git_hash, coreclr_args.host_os, coreclr_args.arch, coreclr_args.build_type)
476510

477511
total_bytes_uploaded = 0
478512

@@ -684,6 +718,11 @@ def setup_spmi_location_arg(spmi_location):
684718
lambda unused: True,
685719
"Unable to set git_hash")
686720

721+
coreclr_args.verify(args,
722+
"use_latest_jit_change",
723+
lambda unused: True,
724+
"Unable to set use_latest_jit_change")
725+
687726
coreclr_args.verify(args,
688727
"az_storage_key",
689728
lambda item: item is not None,

0 commit comments

Comments
 (0)