From 387da3a4205cf9d31fcc426da08a9cd17442c541 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 13 Nov 2018 10:57:50 -0500 Subject: [PATCH] ci: Verify rustfmt Split out the command into a separate `Makefile` that doesn't use Automake so we can invoke it early. Closes: #1674 Approved by: dustymabe --- Makefile-extra.inc | 13 +++++++++++++ Makefile-rpm-ostree.am | 4 ---- Makefile.am | 1 + ci/build-check.sh | 19 +++++++++++++++++++ ci/codestyle.sh | 2 ++ ci/installdeps.sh | 4 ++-- 6 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 Makefile-extra.inc diff --git a/Makefile-extra.inc b/Makefile-extra.inc new file mode 100644 index 00000000..b0d54405 --- /dev/null +++ b/Makefile-extra.inc @@ -0,0 +1,13 @@ +# -*- mode: makefile -*- +# This file defines rules that don't depend on Automake. +# The main idea here is some things we may want to execute +# from CI before we've even run automake, and secondly +# one can avoid rerunning Automake when these rules change. +# +# Specifically right now one can invoke e.g. +# `make -f Makefile-extra.inc rustfmt` directly. + +rustfmt: + rustfmt rust/src/*.rs +.PHONY: rustfmt + diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index 946b7e08..7bc419e4 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -127,10 +127,6 @@ endif rpm_ostree_CFLAGS += $(PKGDEP_RPMOSTREE_RS_CFLAGS) rpm_ostree_LDADD += $(librpmostree_rust_path) $(PKGDEP_RPMOSTREE_RS_LIBS) -rustfmt: - rustfmt $(filter %.rs,$(LIBRPMOSTREE_RUST_SRCS)) -# Outside the ifdef, otherwise automake complains -.PHONY: rustfmt # Wraps `cargo test`. This is always a debug non-release build; # the main thing here is we still drop the `target` dir in our build diff --git a/Makefile.am b/Makefile.am index 891c8cd5..c15bd617 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,7 @@ # Boston, MA 02111-1307, USA. include Makefile-decls.am +include Makefile-extra.inc newname = nts if BUILDOPT_NEW_NAME diff --git a/ci/build-check.sh b/ci/build-check.sh index 5e00e282..7477240e 100755 --- a/ci/build-check.sh +++ b/ci/build-check.sh @@ -5,6 +5,25 @@ set -xeuo pipefail dn=$(dirname $0) . ${dn}/libbuild.sh + +# Add checks here which depend on the build container +# but don't require a full build (code static analysis). +if test -x /usr/bin/rustfmt; then + echo "Verifying rustfmt" + if !git diff --quiet --exit-code; then + echo "outstanding diff before rustfmt" 1>&2 + exit 1 + fi + make -f Makefile-extra.inc rustfmt + if git diff --quiet --exit-code; then + git diff + echo "Please run rustfmt" + exit 1 + fi +else + echo "No /usr/bin/rustfmt, skipping" +fi + ${dn}/build.sh # NB: avoid make function because our RPM building doesn't # support parallel runs right now diff --git a/ci/codestyle.sh b/ci/codestyle.sh index 2b7fc531..823dc296 100755 --- a/ci/codestyle.sh +++ b/ci/codestyle.sh @@ -1,5 +1,6 @@ #!/bin/sh set -xeuo pipefail + echo "Checking for tabs:" (git grep -E '^ +' -- '*.[ch]' || true) > tabdamage.txt if test -s tabdamage.txt; then @@ -7,4 +8,5 @@ if test -s tabdamage.txt; then cat tabdamage.txt exit 1 fi + echo "ok" diff --git a/ci/installdeps.sh b/ci/installdeps.sh index 677c6430..4ee64eaa 100755 --- a/ci/installdeps.sh +++ b/ci/installdeps.sh @@ -29,5 +29,5 @@ pkg_install ostree{,-devel,-grub2} createrepo_c /usr/bin/jq PyYAML \ libubsan libasan libtsan elfutils fuse sudo python-gobject-base \ selinux-policy-devel selinux-policy-targeted python2-createrepo_c \ rsync rpm-python # provided by python2-rpm on Fedora -# For ex-container tests and clang build -pkg_install_if_os fedora parallel clang +# For more CI testing +pkg_install_if_os fedora parallel clang rustfmt-preview