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.
|
|
|
|
|
2020-09-30 12:28:46 +02:00
|
|
|
import logging
|
2020-10-02 14:04:29 +02:00
|
|
|
import os
|
2020-09-30 12:28:46 +02:00
|
|
|
|
2020-10-02 14:04:29 +02:00
|
|
|
from choose_projects import ChooseProjects
|
|
|
|
import git
|
2020-10-02 16:18:33 +02:00
|
|
|
from steps import libcxx, generic_linux, generic_windows
|
2020-10-02 14:04:29 +02:00
|
|
|
import yaml
|
2020-04-24 15:43:09 +02:00
|
|
|
|
2020-04-24 12:49:07 +02:00
|
|
|
if __name__ == '__main__':
|
2020-09-29 17:49:38 +02:00
|
|
|
scripts_refspec = os.getenv("ph_scripts_refspec", "master")
|
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
|
|
|
|
filter_output = '--filter-output' if os.getenv('ph_no_filter_output') is None else ''
|
|
|
|
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')
|
|
|
|
|
|
|
|
# List all affected projects.
|
|
|
|
repo = git.Repo('.')
|
|
|
|
patch = repo.git.diff("HEAD~1")
|
2020-10-02 14:04:29 +02:00
|
|
|
cp = ChooseProjects('.')
|
2020-10-02 16:18:33 +02:00
|
|
|
modified_files = cp.get_changed_files(patch)
|
|
|
|
modified_projects, unmapped_changes = cp.get_changed_projects(modified_files)
|
|
|
|
if unmapped_changes:
|
|
|
|
logging.warning('There were changes that could not be mapped to a project. Checking everything')
|
|
|
|
modified_projects = cp.all_projects
|
|
|
|
logging.info(f'modified projects: {modified_projects}')
|
|
|
|
# Add projects that depend on modified.
|
|
|
|
affected_projects = cp.get_affected_projects(modified_projects)
|
2020-09-29 17:49:38 +02:00
|
|
|
|
2020-10-02 16:18:33 +02:00
|
|
|
# Handle special checks.
|
|
|
|
checked = set()
|
|
|
|
generic_projects = set()
|
|
|
|
logging.info(f'all affected projects: {affected_projects}')
|
2020-05-14 12:57:38 +02:00
|
|
|
steps = []
|
2020-10-02 16:18:33 +02:00
|
|
|
for p in affected_projects:
|
|
|
|
if p == 'libcxx' or p == 'libcxxabi':
|
|
|
|
if 'libcxx' not in checked:
|
|
|
|
logging.info('Adding custom steps for "libc++"')
|
|
|
|
checked.add('libcxx')
|
|
|
|
steps.extend(libcxx())
|
|
|
|
else:
|
|
|
|
generic_projects.add(p)
|
2020-09-30 12:28:46 +02:00
|
|
|
|
2020-10-02 16:18:33 +02:00
|
|
|
if len(generic_projects) > 0:
|
|
|
|
# Add dependencies
|
2020-10-08 11:52:57 +02:00
|
|
|
projects = cp.add_dependencies(generic_projects)
|
|
|
|
logging.info(f'all projects {projects}')
|
|
|
|
excluded_linux = cp.get_excluded('linux')
|
|
|
|
logging.info(f'excluded for linux: {excluded_linux}')
|
|
|
|
steps.extend(generic_linux(';'.join(sorted(projects - excluded_linux)), True))
|
|
|
|
excluded_windows = cp.get_excluded('windows')
|
|
|
|
logging.info(f'excluded for windows: {excluded_windows}')
|
|
|
|
steps.extend(generic_windows(';'.join(sorted(projects - excluded_windows))))
|
2020-10-02 16:18:33 +02:00
|
|
|
else:
|
|
|
|
logging.info('No projects for default checks')
|
2020-09-29 17:49:38 +02:00
|
|
|
|
2020-10-05 12:48:34 +02:00
|
|
|
if os.getenv('ph_target_phid') is None:
|
|
|
|
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 = {
|
|
|
|
'label': ':spiral_note_pad: report',
|
|
|
|
'commands': [
|
|
|
|
'mkdir -p artifacts',
|
|
|
|
'buildkite-agent artifact download "*_result.json" .',
|
2020-10-02 10:17:00 +02:00
|
|
|
|
2020-10-05 12:48:34 +02:00
|
|
|
# Clone scripts.
|
|
|
|
'export SRC=${BUILDKITE_BUILD_PATH}/llvm-premerge-checks',
|
|
|
|
'rm -rf ${SRC}',
|
|
|
|
'git clone --depth 1 https://github.com/google/llvm-premerge-checks.git "${SRC}"',
|
|
|
|
'cd ${SRC}',
|
|
|
|
f'git fetch origin "{scripts_refspec}":x',
|
|
|
|
'git checkout x',
|
|
|
|
'echo "llvm-premerge-checks commit"',
|
|
|
|
'git rev-parse HEAD',
|
|
|
|
'cd "$BUILDKITE_BUILD_CHECKOUT_PATH"',
|
|
|
|
'${SRC}/scripts/summary.py',
|
|
|
|
],
|
|
|
|
'artifact_paths': ['artifacts/**/*'],
|
|
|
|
'agents': {'queue': 'linux'},
|
|
|
|
'timeout_in_minutes': 10,
|
|
|
|
}
|
|
|
|
steps.append(report_step)
|
2020-05-25 16:42:40 +02:00
|
|
|
print(yaml.dump({'steps': steps}))
|