2020-04-24 12:49:07 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# Copyright 2020 Google LLC
|
|
|
|
#
|
|
|
|
# Licensed under the the Apache License v2.0 with LLVM Exceptions (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# https://llvm.org/LICENSE.txt
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2021-08-11 16:20:03 +02:00
|
|
|
# Script runs in checked out llvm-project directory.
|
|
|
|
|
2020-09-30 12:28:46 +02:00
|
|
|
import logging
|
2020-10-02 14:04:29 +02:00
|
|
|
import os
|
2021-10-04 16:07:06 +02:00
|
|
|
from typing import Dict
|
2020-09-30 12:28:46 +02:00
|
|
|
|
2021-05-03 21:07:00 +02:00
|
|
|
from buildkite_utils import annotate, feedback_url, set_metadata
|
2020-10-02 14:04:29 +02:00
|
|
|
from choose_projects import ChooseProjects
|
|
|
|
import git
|
2021-08-11 16:20:03 +02:00
|
|
|
from steps import generic_linux, generic_windows, from_shell_output, checkout_scripts, bazel, extend_steps_env
|
2020-10-02 14:04:29 +02:00
|
|
|
import yaml
|
2020-04-24 15:43:09 +02:00
|
|
|
|
2020-10-09 11:05:19 +02:00
|
|
|
steps_generators = [
|
2023-07-12 17:00:48 +02:00
|
|
|
'${BUILDKITE_BUILD_CHECKOUT_PATH}/.ci/generate-buildkite-pipeline-premerge',
|
2020-10-09 11:05:19 +02:00
|
|
|
]
|
|
|
|
|
2020-04-24 12:49:07 +02:00
|
|
|
if __name__ == '__main__':
|
2020-12-09 17:23:01 +01:00
|
|
|
scripts_refspec = os.getenv("ph_scripts_refspec", "main")
|
2020-05-14 12:57:38 +02:00
|
|
|
diff_id = os.getenv("ph_buildable_diff", "")
|
2020-07-10 17:53:22 +02:00
|
|
|
no_cache = os.getenv('ph_no_cache') is not None
|
|
|
|
projects = os.getenv('ph_projects', 'detect')
|
2020-10-02 16:18:33 +02:00
|
|
|
log_level = os.getenv('ph_log_level', 'INFO')
|
2020-09-30 12:28:46 +02:00
|
|
|
logging.basicConfig(level=log_level, format='%(levelname)-7s %(message)s')
|
|
|
|
|
2020-10-09 12:50:44 +02:00
|
|
|
phid = os.getenv('ph_target_phid')
|
2020-11-25 15:29:50 +01:00
|
|
|
url = f"https://reviews.llvm.org/D{os.getenv('ph_buildable_revision')}?id={diff_id}"
|
|
|
|
annotate(f"Build for [D{os.getenv('ph_buildable_revision')}#{diff_id}]({url}). "
|
|
|
|
f"[Harbormaster build](https://reviews.llvm.org/harbormaster/build/{os.getenv('ph_build_id')}).\n"
|
|
|
|
f"If there is a build infrastructure issue, please [create a bug]({feedback_url()}).")
|
2021-05-03 21:07:00 +02:00
|
|
|
set_metadata('ph_buildable_diff', os.getenv("ph_buildable_diff"))
|
|
|
|
set_metadata('ph_buildable_revision', os.getenv('ph_buildable_revision'))
|
|
|
|
set_metadata('ph_build_id', os.getenv("ph_build_id"))
|
2021-08-11 16:20:03 +02:00
|
|
|
|
2021-10-04 16:07:06 +02:00
|
|
|
env: Dict[str, str] = {}
|
2021-08-11 16:20:03 +02:00
|
|
|
for e in os.environ:
|
|
|
|
if e.startswith('ph_'):
|
2021-10-04 16:07:06 +02:00
|
|
|
env[e] = os.getenv(e, '')
|
2020-09-30 12:28:46 +02:00
|
|
|
repo = git.Repo('.')
|
2021-09-17 22:31:15 +02:00
|
|
|
steps = []
|
2021-08-11 16:20:03 +02:00
|
|
|
# List all affected projects.
|
2020-09-30 12:28:46 +02:00
|
|
|
patch = repo.git.diff("HEAD~1")
|
2020-10-02 14:04:29 +02:00
|
|
|
cp = ChooseProjects('.')
|
2021-09-17 22:31:15 +02:00
|
|
|
|
2021-10-04 16:07:06 +02:00
|
|
|
linux_projects = cp.choose_projects(patch = patch, os_name = "linux")
|
|
|
|
logging.info(f'linux_projects: {linux_projects}')
|
2020-10-09 12:35:32 +02:00
|
|
|
if len(linux_projects) > 0:
|
2021-10-04 16:07:06 +02:00
|
|
|
steps.extend(generic_linux(';'.join(linux_projects), check_diff=True))
|
2021-09-17 22:31:15 +02:00
|
|
|
|
2021-10-04 16:07:06 +02:00
|
|
|
windows_projects = cp.choose_projects(patch = patch, os_name = "windows")
|
|
|
|
logging.info(f'windows_projects: {windows_projects}')
|
2020-10-09 12:35:32 +02:00
|
|
|
if len(windows_projects) > 0:
|
2021-10-04 16:07:06 +02:00
|
|
|
steps.extend(generic_windows(';'.join(windows_projects)))
|
2021-09-17 22:31:15 +02:00
|
|
|
|
2020-11-25 15:29:50 +01:00
|
|
|
# Add custom checks.
|
2021-03-19 09:22:21 +01:00
|
|
|
if os.getenv('ph_skip_generated') is None:
|
2021-10-04 16:58:52 +02:00
|
|
|
if os.getenv('BUILDKITE_COMMIT', 'HEAD') == "HEAD":
|
|
|
|
env['BUILDKITE_COMMIT'] = repo.head.commit.hexsha
|
2021-03-19 09:22:21 +01:00
|
|
|
for gen in steps_generators:
|
2021-10-04 16:07:06 +02:00
|
|
|
steps.extend(from_shell_output(gen, env=env))
|
2021-09-17 22:31:15 +02:00
|
|
|
modified_files = cp.get_changed_files(patch)
|
2021-07-28 15:50:57 +02:00
|
|
|
steps.extend(bazel(modified_files))
|
2020-09-29 17:49:38 +02:00
|
|
|
|
2020-10-09 12:50:44 +02:00
|
|
|
if phid is None:
|
2020-10-05 12:48:34 +02:00
|
|
|
logging.warning('ph_target_phid is not specified. Skipping "Report" step')
|
|
|
|
else:
|
|
|
|
steps.append({
|
|
|
|
'wait': '~',
|
|
|
|
'continue_on_failure': True,
|
|
|
|
})
|
2020-09-29 17:49:38 +02:00
|
|
|
|
2020-10-05 12:48:34 +02:00
|
|
|
report_step = {
|
2020-11-25 15:29:50 +01:00
|
|
|
'label': ':phabricator: update build status on Phabricator',
|
2020-10-05 12:48:34 +02:00
|
|
|
'commands': [
|
2020-10-12 16:25:23 +02:00
|
|
|
*checkout_scripts('linux', scripts_refspec),
|
2021-04-26 20:10:15 +02:00
|
|
|
'$${SRC}/scripts/summary.py',
|
2020-10-05 12:48:34 +02:00
|
|
|
],
|
|
|
|
'artifact_paths': ['artifacts/**/*'],
|
2021-04-26 20:10:15 +02:00
|
|
|
'agents': {'queue': 'service'},
|
2020-10-05 12:48:34 +02:00
|
|
|
'timeout_in_minutes': 10,
|
|
|
|
}
|
|
|
|
steps.append(report_step)
|
2020-10-09 12:50:44 +02:00
|
|
|
|
2021-08-11 16:20:03 +02:00
|
|
|
extend_steps_env(steps, env)
|
2020-05-25 16:42:40 +02:00
|
|
|
print(yaml.dump({'steps': steps}))
|