From a2ec47917b52199de11b737e4197e9fd040b4bfd Mon Sep 17 00:00:00 2001 From: c-parsons Date: Fri, 22 Feb 2019 17:44:48 -0500 Subject: [PATCH 1/2] fix a number of warnings found by Starlark analyzer (#114) --- lib/unittest.bzl | 20 +++++++++++++++++++- rules/analysis_test.bzl | 1 + tests/unittest_tests.bzl | 5 ++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/unittest.bzl b/lib/unittest.bzl index de81a4d..116bb0a 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -64,6 +64,12 @@ def _impl_function_name(impl): """Derives the name of the given rule implementation function. This can be used for better test feedback. + + Args: + impl: the rule implementation function + + Returns: + The name of the given function """ # Starlark currently stringifies a function as "", so we use @@ -123,6 +129,7 @@ def _make(impl, attrs = None): _ActionInfo = provider(fields = ["actions"]) def _action_retrieving_aspect_impl(target, ctx): + _ignore = [ctx] return [_ActionInfo(actions = target.actions)] _action_retrieving_aspect = aspect( @@ -282,6 +289,9 @@ def _end_analysis_test(env): Args: env: The test environment returned by `analysistest.begin`. + + Returns: + A list of providers needed to automatically register the analysis test result. """ return [AnalysisTestResultInfo( success = (len(env.failures) == 0), @@ -296,6 +306,9 @@ def _end(env): Args: env: The test environment returned by `unittest.begin`. + + Returns: + A list of providers needed to automatically register the test result. """ tc = env.ctx.toolchains[TOOLCHAIN_TYPE].unittest_toolchain_info @@ -419,7 +432,6 @@ def _expect_failure(env, expected_failure_msg = ""): """ dep = _target_under_test(env) if AnalysisFailureInfo in dep: - dep_failure = dep[AnalysisFailureInfo] actual_errors = "" for cause in dep[AnalysisFailureInfo].causes.to_list(): actual_errors += cause.message + "\n" @@ -435,6 +447,9 @@ def _target_actions(env): Args: env: The test environment returned by `analysistest.begin`. + + Returns: + A list of actions registered by the target under test """ # Validate? @@ -446,6 +461,9 @@ def _target_under_test(env): Args: env: The test environment returned by `analysistest.begin`. + + Returns: + The target under test. """ result = getattr(env.ctx.attr, "target_under_test") if types.is_list(result): diff --git a/rules/analysis_test.bzl b/rules/analysis_test.bzl index 0ac404b..a43ef90 100644 --- a/rules/analysis_test.bzl +++ b/rules/analysis_test.bzl @@ -16,6 +16,7 @@ def _analysis_test_impl(ctx): """Implementation function for analysis_test. """ + _ignore = [ctx] return [AnalysisTestResultInfo( success = True, message = "All targets succeeded analysis", diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 20fd890..01ea4de 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -69,6 +69,7 @@ def _failure_testing_test(ctx): return analysistest.end(env) def _failure_testing_fake_rule(ctx): + ignore = [ctx] fail("This rule should never work") failure_testing_fake_rule = rule( @@ -92,6 +93,7 @@ def _fail_unexpected_passing_test(ctx): return analysistest.end(env) def _fail_unexpected_passing_fake_rule(ctx): + _ignore = [ctx] return [] fail_unexpected_passing_fake_rule = rule( @@ -168,7 +170,8 @@ def unittest_passing_tests_suite(): Not all tests are included. Some unittest.bzl tests verify a test fails when assertions are not met. Such tests must be run in an e2e shell test. - This suite only includes tests which verify success tests.""" + This suite only includes tests which verify success tests. + """ unittest.suite( "unittest_tests", basic_passing_test, From e171ec16d89afe28d09d29837ce523aa10aebdc6 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Wed, 27 Feb 2019 12:21:18 -0500 Subject: [PATCH 2/2] CI updates. (#118) - Retire the use of travis for testing. - Update buildkite config: - Enable buildifier testing (close to what was on travis, and is being improved.) - Update the config to now test the latests release and the latest green, replacing the "head" testing on travis. --- .bazelci/presubmit.yml | 73 ++++++++++++++++++++++++++-- .travis.yml | 34 ------------- .travis_build.sh | 76 ----------------------------- .travis_install.sh | 107 ----------------------------------------- README.md | 1 - 5 files changed, 68 insertions(+), 223 deletions(-) delete mode 100644 .travis.yml delete mode 100755 .travis_build.sh delete mode 100755 .travis_install.sh diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index fc47833..bd50460 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -1,27 +1,42 @@ --- -platforms: - ubuntu1404: +tasks: + ubuntu1804_latest: + name: "Latest Bazel" + platform: ubuntu1804 + bazel: latest build_targets: - "..." test_targets: - "..." test_flags: - "--test_env=PATH" - ubuntu1604: + + ubuntu1604_latest: + name: "Latest Bazel" + platform: ubuntu1604 + bazel: latest build_targets: - "..." test_targets: - "..." test_flags: - "--test_env=PATH" - macos: + + macos_latest: + name: "Latest Bazel" + platform: macos + bazel: latest build_targets: - "..." test_targets: - "..." test_flags: - "--test_env=PATH" - windows: + + windows_latest: + name: "Latest Bazel" + platform: windows + bazel: latest build_targets: - "..." test_targets: @@ -30,3 +45,51 @@ platforms: # Shell tests don't run on windows. - "-//tests:analysis_test_e2e_test" - "-//tests:unittest_e2e_test" + + ubuntu1804_last_green: + name: "Last Green Bazel" + platform: ubuntu1804 + bazel: last_green + build_targets: + - "..." + test_targets: + - "..." + test_flags: + - "--test_env=PATH" + + ubuntu1604_last_green: + name: "Last Green Bazel" + platform: ubuntu1604 + bazel: last_green + build_targets: + - "..." + test_targets: + - "..." + test_flags: + - "--test_env=PATH" + + macos_last_green: + name: "Last Green Bazel" + platform: macos + bazel: last_green + build_targets: + - "..." + test_targets: + - "..." + test_flags: + - "--test_env=PATH" + + windows_last_green: + name: "Last Green Bazel" + platform: windows + bazel: last_green + build_targets: + - "..." + test_targets: + - "--" + - "..." + # Shell tests don't run on windows. + - "-//tests:analysis_test_e2e_test" + - "-//tests:unittest_e2e_test" + +buildifier: true diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index db865dd..0000000 --- a/.travis.yml +++ /dev/null @@ -1,34 +0,0 @@ -# Not really c++, but stops travis from listing a language. -language: c++ - -matrix: - include: - # ----------------------------------------------------------------- - # Linux hosted tests - - - os: linux - dist: trusty - sudo: false - env: BAZEL=HEAD - - os: linux - dist: trusty - sudo: false - env: BUILDIFIER=RELEASE - - # ----------------------------------------------------------------- - # macOS hosted tests - - - os: osx - osx_image: xcode10.1 - env: BAZEL=HEAD - # No need for a BUILDIFIER run on mac, the results will be the same. - # And linux boxes test faster on travis, so just use the one. - -before_install: - - ./.travis_install.sh - -script: - - ./.travis_build.sh - -notifications: - email: false diff --git a/.travis_build.sh b/.travis_build.sh deleted file mode 100755 index f160280..0000000 --- a/.travis_build.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. - -set -eu - -# ------------------------------------------------------------------------------------------------- -# Asked to do a bazel build. -if [[ -n "${BAZEL:-}" ]]; then - bazel test --show_progress_rate_limit=30.0 //... -fi - -# ------------------------------------------------------------------------------------------------- -# Asked to do a buildifier run. -if [[ -n "${BUILDIFIER:-}" ]]; then - FOUND_ISSUES="no" - - # buildifier supports BUILD/WORKSPACE/*.bzl files, this provides the args - # to reuse in all the finds. - FIND_ARGS=( - \( - -name BUILD - -o - -name WORKSPACE - -o - -name "*.bzl" - \) - ) - - # Check for format issues? - if [[ "${FORMAT:-yes}" == "yes" ]] ; then - echo "buildifier: validating formatting..." - if ! find . "${FIND_ARGS[@]}" -print | xargs buildifier -d ; then - echo "" - echo "Please download the latest buildifier" - echo " https://github.com/bazelbuild/buildtools/releases" - echo "and run it over the changed BUILD/.bzl files." - echo "" - FOUND_ISSUES="yes" - fi - fi - - # Check for lint issues? - if [[ "${LINT:-yes}" == "yes" ]] ; then - echo "buildifier: running lint checks..." - # NOTE: buildifier defaults to --mode=fix, so these lint runs also - # reformat the files. But since this is on travis, that is fine. - # https://github.com/bazelbuild/buildtools/issues/453 - if ! find . "${FIND_ARGS[@]}" -print | xargs buildifier --lint=warn ; then - echo "" - echo "Please download the latest buildifier" - echo " https://github.com/bazelbuild/buildtools/releases" - echo "and run it with --lint=(warn|fix) over the changed BUILD/.bzl files" - echo "and make the edits as needed." - echo "" - FOUND_ISSUES="yes" - fi - fi - - # Anything? - if [[ "${FOUND_ISSUES}" != "no" ]] ; then - exit 1 - fi -fi diff --git a/.travis_install.sh b/.travis_install.sh deleted file mode 100755 index bef55ea..0000000 --- a/.travis_install.sh +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/bash - -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# 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. - -set -eux - -if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then - OS=darwin -else - OS=linux -fi - -# ------------------------------------------------------------------------------------------------- -# Helper to use the github redirect to find the latest release. -function github_latest_release_tag() { - local PROJECT=$1 - curl \ - -s \ - -o /dev/null \ - --write-out '%{redirect_url}' \ - "https://github.com/${PROJECT}/releases/latest" \ - | sed -e 's,https://.*/releases/tag/\(.*\),\1,' -} - -# ------------------------------------------------------------------------------------------------- -# Helper to get a download url out of bazel build metadata file. -function url_from_bazel_manifest() { - local MANIFEST_URL=$1 - if [[ "${OS}" == "darwin" ]]; then - local JSON_OS="macos" - else - local JSON_OS="ubuntu1404" - fi - wget -O - "${MANIFEST_URL}" \ - | python -c "import json; import sys; print json.load(sys.stdin)['platforms']['${JSON_OS}']['url']" -} - -# ------------------------------------------------------------------------------------------------- -# Helper to install bazel. -function install_bazel() { - local VERSION="${1}" - - if [[ "${VERSION}" == "RELEASE" ]]; then - VERSION="$(github_latest_release_tag bazelbuild/bazel)" - fi - - # macOS and trusty images have jdk8, so install bazel without jdk. - if [[ "${VERSION}" == "HEAD" ]]; then - # bazelbuild/continuous-integration/issues/234 - they don't seem to have an installed - # just raw binaries? - mkdir -p "$HOME/bin" - wget -O "$HOME/bin/bazel" \ - "$(url_from_bazel_manifest https://storage.googleapis.com/bazel-builds/metadata/latest.json)" - chmod +x "$HOME/bin/bazel" - else - wget -O install.sh \ - "https://github.com/bazelbuild/bazel/releases/download/${VERSION}/bazel-${VERSION}-without-jdk-installer-${OS}-x86_64.sh" - chmod +x install.sh - ./install.sh --user - rm -f install.sh - fi - - bazel version -} - -# ------------------------------------------------------------------------------------------------- -# Helper to install buildifier. -function install_buildifier() { - local VERSION="${1}" - - if [[ "${VERSION}" == "RELEASE" ]]; then - VERSION="$(github_latest_release_tag bazelbuild/buildtools)" - fi - - if [[ "${VERSION}" == "HEAD" ]]; then - echo "buildifier head is not supported" - exit 1 - fi - - if [[ "${OS}" == "darwin" ]]; then - URL="https://github.com/bazelbuild/buildtools/releases/download/${VERSION}/buildifier.osx" - else - URL="https://github.com/bazelbuild/buildtools/releases/download/${VERSION}/buildifier" - fi - - mkdir -p "$HOME/bin" - wget -O "${HOME}/bin/buildifier" "${URL}" - chmod +x "${HOME}/bin/buildifier" - buildifier --version -} - -# ------------------------------------------------------------------------------------------------- -# Install what is requested. -[[ -z "${BAZEL:-}" ]] || install_bazel "${BAZEL}" -[[ -z "${BUILDIFIER:-}" ]] || install_buildifier "${BUILDIFIER}" diff --git a/README.md b/README.md index fe7c869..6f82d96 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # Skylib -[![Build Status](https://travis-ci.org/bazelbuild/bazel-skylib.svg?branch=master)](https://travis-ci.org/bazelbuild/bazel-skylib) [![Build status](https://badge.buildkite.com/921dc61e2d3a350ec40efb291914360c0bfa9b6196fa357420.svg)](https://buildkite.com/bazel/bazel-skylib) Skylib is a standard library that provides functions useful for manipulating