Skip to content

Commit

Permalink
Fix JIT rolling build issue with non-JIT changes (#64480)
Browse files Browse the repository at this point in the history
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 #64392
  • Loading branch information
BruceForstall authored Jan 29, 2022
1 parent 964b1d7 commit 9122424
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eng/pipelines/coreclr/templates/build-jit-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
- script: $(PipScript) install --user --upgrade pip && $(PipScript) install --user azure.storage.blob==12.5.0 --force-reinstall
displayName: Upgrade Pip to latest and install azure-storage-blob Python package

- script: $(PythonScript) $(Build.SourcesDirectory)/src/coreclr/scripts/jitrollingbuild.py upload -build_type $(buildConfig) -arch $(archType) -host_os $(osGroup) -git_hash $(Build.SourceVersion)
- 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
displayName: Upload JIT to Azure Storage
env:
CLRJIT_AZ_KEY: $(clrjit_key1) # secret key stored as variable in pipeline
Expand Down
41 changes: 40 additions & 1 deletion src/coreclr/scripts/jitrollingbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@

git_hash_help = "git hash"

use_latest_jit_change_help = """\
Starting with the given git hash, look backwards in the git log for the first change that includes any JIT
change. We want to ensure that any git hash uploaded to the JIT rolling build store is a JIT change. This
addresses a problem where Azure DevOps sometimes builds changes that come soon after a JIT change, instead of
the JIT change itself.
"""

target_dir_help = "Directory to put the downloaded JIT."

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

upload_parser.add_argument("-git_hash", required=True, help=git_hash_help)
upload_parser.add_argument("--use_latest_jit_change", action="store_true", help=use_latest_jit_change_help)
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.")
upload_parser.add_argument("--skip_cleanup", action="store_true", help=skip_cleanup_help)

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

# Figure out which git hash to use for the upload. By default, it is the required coreclr_args.git_hash argument.
# However, if "--use_latest_jit_change" is passed, we look backwards in the git log for the nearest git commit
# with a JIT change (it could, and often will be, the same as the argument git_hash).
jit_git_hash = coreclr_args.git_hash

if coreclr_args.use_latest_jit_change:
# Do all the remaining commands, including a number of 'git' commands including relative paths,
# from the root of the runtime repo.

with ChangeDir(coreclr_args.runtime_repo_location):
# Enumerate the last change, starting with the jit_git_hash, that included JIT changes.
command = [ "git", "log", "--pretty=format:%H", jit_git_hash, "-1", "--", "src/coreclr/jit/*" ]
print("Invoking: {}".format(" ".join(command)))
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
stdout_change_list, _ = proc.communicate()
return_code = proc.returncode
change_list_hashes = []
if return_code == 0:
change_list_hashes = stdout_change_list.decode('utf-8').strip().splitlines()

if len(change_list_hashes) == 0:
print("Couldn't find any JIT changes! Just using the argument git_hash")
else:
jit_git_hash = change_list_hashes[0]
print("Using git_hash {}".format(jit_git_hash))

print("Uploading:")
for item in files:
print(" {}".format(item))
Expand All @@ -472,7 +506,7 @@ def upload_blob(file, blob_name):
raise RuntimeError("Missing azure storage package.")

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

total_bytes_uploaded = 0

Expand Down Expand Up @@ -684,6 +718,11 @@ def setup_spmi_location_arg(spmi_location):
lambda unused: True,
"Unable to set git_hash")

coreclr_args.verify(args,
"use_latest_jit_change",
lambda unused: True,
"Unable to set use_latest_jit_change")

coreclr_args.verify(args,
"az_storage_key",
lambda item: item is not None,
Expand Down

0 comments on commit 9122424

Please sign in to comment.