Commit Graph

59 Commits

Author SHA1 Message Date
Alexei Frolov
ba4de1c27a pw_env_setup: Initial pass at prettier Windows UI
This change improves the Windows env_setup UI to mirror that of POSIX.
Not everything matches yet, and there is still no distinction between
bootstrap and activate.

Change-Id: I8680400340c7af03dbce234a248a65839287e6eb
2020-03-10 14:51:53 -07:00
Wyatt Hepler
72b87dc93b pw_presubmit: Move Python checks to own module
Move the Python checks to their own module instead of having them in the
Pigweed presubmit.

Change-Id: I27e9a8af0760864d6843268ae228b7f2bd448556
2020-03-06 15:17:36 -08:00
Wyatt Hepler
e0aef0ab4e pw_presubmit: Enable mypy and get it passing
- Fix several typing issues.
- Disable type checking in several places where mypy wasn't working
  correctly.
- Enable mypy.
- Execute individual steps in the same order as they are provided with
  --step.

Change-Id: I229cf8ee39a4db5067c1923b4acfc5fcd164f733
2020-03-06 23:13:35 +00:00
Armando Montanez
a0ace99913 pw_presubmit: ignore images in copyright check
Adds image file extensions to the ignore list when checking copyright
notice.

Change-Id: Ia78d92764e396f48bf42a488e357bf24be4adbaf
2020-03-05 23:12:11 +00:00
Wyatt Hepler
eb93a74feb pw_presubmit: Summarize files being examined
- Introduce a file summary that expresses the files being examined in a
  condensed way. It is important to clearly communicate which files are
  being checked to avoid confusion.
- Use the file summary in pw format.
- Include file count in the final presubmit summary.
- Fix some mypy complaints.

Example file summary:

  ./                1 file (1 .gni)
  docs/             2 files (1 .gn, 1 .rst)
  pw_assert/        1 file (1 .rst)
  pw_assert_basic/  2 files (1 .gn, 1 .rst)
  pw_bloat/         1 file (1 .gni)
  pw_boot_armv7m/   1 file (1 .bloaty)
  pw_env_setup/     5 files (2 .py, 1 .gn, 1 .rst, 1 other)
  pw_kvs/           3 files (2 .cc, 1 .h)
  pw_presubmit/     3 files (3 .py)
  pw_protobuf/      3 files (2 .rst, 1 .gn)
  pw_watch/         2 files (2 .py)
  (5 others)/       5 files (2 .rst, 2 .gni, 1 .py)

Bug: 105
Change-Id: I4cffc470d9b5b1d1eca8e913a041d507ba8fe3ea
2020-03-05 11:28:17 -08:00
Keir Mierle
b0270b4bc4 pw_presubmit: Add bug number to comments
Bug: 141
Change-Id: I8b1f7e81190565a07299c27cddd4039bb33b360d
2020-03-05 01:15:44 +00:00
Keir Mierle
95a980be8b pw_toolchain: Fix Mac host GN build
This fixes the long standing GN build breakage on Mac, which was due to
the CIPD-provided Clang defaulting to the system-provided libc++.

In order to restore Mac builds, this patch also:
- Disable GN GCC host build in presubmit (it's just Clang)
- Disable CMake host build (needs toolchain work)
- Disable Bazel host build (needs toolchain work)

Change-Id: I01dbe1e951af202a028a66d26d9c496cab736748
2020-03-04 16:05:44 -08:00
Wyatt Hepler
1896e2f22a pw_presubmit: Change step banner style
No longer attempt to form boxes for each step, which does not work well
when there are log messages during a step.

Example:

═══════════════════════════════════════════════════════════════════════════════╗
                          Presubmit checks for pigweed                         ║
═══════════════════════════════════════════════════════════════════════════════╝
20200304 10:28:05 INF Running 17 of 17 checks on 521 files in /home/hepler/pw/pigweed
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
   1/17   init_cipd                                                  521 files

 PASSED   init_cipd                                                     0:00.8
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
   2/17   init_virtualenv                                            521 files

 PASSED   init_virtualenv                                               0:00.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
   3/17   copyright_notice                                           453 files

20200304 10:28:06 WRN 1 file with a missing or incorrect copyright notice:
/home/hepler/pw/pigweed/pw_presubmit/py/pw_presubmit/format_code.py

 FAILED   copyright_notice                                              0:00.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
════════╦══════════════════════════════════════════════════════════╦═══════════╗
 FAILED ║ 17 checks: 2 passed, 1 failed, 14 did not run            ║    0:00.8 ║
════════╩══════════════════════════════════════════════════════════╩═══════════╝

Change-Id: Ib9bb1049b61e7b7962c22dd814f9295e1c551b8b
2020-03-04 20:03:04 +00:00
Wyatt Hepler
4ee94261ec pw_presubmit: Remove file summary
The file summary is too verbose and is not helpful in its current state.

Change-Id: Ieb01e60c9e8b69af9940e72adb52a33fed1d3be3
2020-03-04 16:35:14 +00:00
Rob Mohr
a0ba54f648 Roll GN to 239533d
This caused gn format to flag many things which were also fixed.

Change-Id: Ie1d9081a1b08047bec52c60f54d2a94366be1ba6
2020-02-28 01:33:18 +00:00
Alexei Frolov
b54e4d0627 pw_presubmit: Update code format step names
This changes the names of the code format steps to lowercase with
underscores to make them consistent with all other steps and easy to
specify via the --step CLI option.

Change-Id: Ie319f36da77fdb0218337ea418ed6e938b6ba317
2020-02-25 19:02:42 +00:00
Wyatt Hepler
93228641e3 pw_presubmit: Reorder steps; quick pre-push hook
- Set PW_ROOT if it's not set to allow running outside of the Pigweed
  environment.
- Reorder the steps in the full program to put quicker steps first.
- Have the Git pre-push hook run the quick program instead of the
  default full program.

Change-Id: I28c3a5a62bf61e4ed2d889fa9bea17003fcdeab7
2020-02-07 22:27:28 +00:00
Rob Mohr
2cc32ecdfb Move env_setup to pw_env_setup
Bug: 67
Change-Id: I285e917968b2e24e0851753ea4802cef1fbe2d67
2020-02-05 19:07:01 +00:00
Wyatt Hepler
6908e47768 pw_presubmit: Add message about the Bazel cache
Sometimes the Bazel cache gets in a bad state where it complains about
undeclared inclusions on C standard library headers. The only way to fix
this is to delete the Bazel cache. This adds a message to the presubmit
about how to clear the cache if the Bazel build fails.

Fixed: 114
Change-Id: I7c3ad45bdce919a325f721f2071e99c1e56582c0
2020-02-04 21:11:34 +00:00
Rob Mohr
fd970819a5 Reorg virtualenv env_setup
Add symlink from previous location of requirements.txt. Will remove in
a followup after recipes have been configured to point to new path.

Bug: 67
Change-Id: I0b808c99789d65ac216dbd176a684061c8b2d8a8
2020-02-04 07:46:24 -08:00
Rob Mohr
586f9609dc Reorg cipd env_setup
Add symlink from previous locations of json files. Will remove in a
followup after recipes have been configured to point to new path.

Bug: 67
Change-Id: Icff7c64860da73ba8260d1c8f2e14eab5f078ade
2020-02-03 18:06:15 +00:00
Rob Mohr
2005274a30 Store CIPD references in JSON
Store CIPD references in JSON so it's easier to automatically roll
versions of tools and parse from recipes.

Change-Id: I918421401fa19d719b3bde52dde0173bb7a69a42
Bug: 103
2020-01-28 15:26:25 -08:00
Rob Mohr
bfbc21830f Force clang use on cmake
Change-Id: Iafb01632972958eb5eb0d59d2ec567f1942456b9
2020-01-23 23:45:53 +00:00
Alexei Frolov
aad92a9060
Windows host test runner script
This change adds a test runner script for a Windows host build.

Change-Id: I2bc983b245a6c4396cab4df9db9c9b7efcb30cce
2020-01-22 11:04:50 -08:00
Rob Mohr
2d5d25f5fc Add "PW_" prefix to env vars
Change-Id: Ie0cf5aee98fdc88643098ba2a2e90db72156f3b2
2020-01-15 15:32:15 +00:00
Alexei Frolov
799be5d81f Add docs target
This change moves building documentation out of the host and disco targets
into a special docs target.

The presubmit script is updated to handle the docs target.

Change-Id: I975170c9e8941d126d85a391c0f3b355e4fa44dd
2020-01-10 00:56:50 +00:00
Rob Mohr
881d3138e8 Fix copyright check on empty files
For empty files the copyright check would keep reading but because
it was at EOF it would keep getting an empty string, for which
'not line.strip()' would always evaluate to True. This change
causes it to exit the loop when it hits EOF.

Change-Id: I0fe5d95fe1d4f1d9dcaf1ff4e1351fa40b96bd72
2020-01-09 21:44:19 +00:00
Wyatt Hepler
6afac0a518 CMake: color output; use . as test group separator
- Use . as a separator in the test group target names. For example,
  pw_run_tests_pw_varint is now pw_run_tests.pw_varint.
- Force the compiler to colorize its output.

Change-Id: I47c283974db935ec5f93402de965caab57a9750c
2020-01-08 14:27:07 -08:00
Wyatt Hepler
8c66112e7b No copyright check for .elf; fix --clean-py
Change-Id: I7bb42a4bfc5d8df7a9846af02aef585ca7bc44bd
2020-01-06 17:10:34 +00:00
Rob Mohr
8838aa9c52 Get clang_tidy check running.
Running, but not passing. Also, presubmit steps that are not yet
passing can be added to the "broken" program so they can be easily
tested.

I think it needs '-warnings-as-errors' but I get errors when adding
that. It also complains about '-Wno-psabi'.

Change-Id: I72d92cce16f6a764b523d83d36280d6ce3350440
Bug: 45
2020-01-06 07:17:15 -08:00
Wyatt Hepler
2f8851695d Run tests with CMake as a presubmit check
Change-Id: I5e1ab32e0e66af798c4613d6847fa276c9ab7b8f
2020-01-04 01:10:36 +00:00
Rob Mohr
1c38c7c1c9 Skip deleted files in presubmit.
Change-Id: I9998b3b606773ca1fdc5330c311820f977506b13
2020-01-02 10:33:46 -08:00
Wyatt Hepler
634360dbec Logging adjustments
Add function for setting the stderr log level and adjust some log
statements.

Bug: 41

Change-Id: I3cb44d78c5316949da331ca91fca25592f3f5907
2019-12-31 09:55:47 -08:00
Wyatt Hepler
3c85239a75 pw_presubmit: Use pathlib.Path; typing fixes
- Use pathlib.Path in more places.
- Fix a few type mismatches.
- Expand type annotations.

Change-Id: I6187e2d86e8e02dbab3806025d5d89d219f1c9b8
2019-12-31 17:48:37 +00:00
Rob Mohr
260039e7f7 Create a log file for each check.
Create a logger for each check. Add a FileHandler with level DEBUG to
these loggers. Since they're child loggers of the root logger, warn()
and error() send output to the log file and to stderr.

Make several changes to simplify passing these log objects around.

Add log statements to a few presubmit checks.

Change-Id: If13ad92da5c2abf9035e78c1cbe81d5025916888
Bug: 3
2019-12-20 14:36:08 -08:00
Rob Mohr
a2563c048d Add verbosity to bazel_test() presubmit.
Add verbosity to bazel_test() presubmit. Users don't see anything extra
unless there's a failure.

Change-Id: I344748f7f326f34d77fbe7f88b754141c22bd0b0
2019-12-20 09:42:43 -08:00
Rob Mohr
be6efc77b3 pw presubmit no longer cds.
The pw presubmit command no longer cds to the repository root. By default,
it puts output in repository_root/.presubmit, but output can be placed
anywhere. Both of these presubmit commands pass.

$ cd $PW_ROOT ; pw presubmit
$ cd $PW_ROOT/.. ; pw presubmit --repository ~/pigweed/pigweed \
    --output-directory .

The presubmit context object now has an output_directory member. Presubmit
checks should place output in that folder.

Change-Id: Ibb0a3c7add54de6409561006e3c74dd8c8603a25
2019-12-18 14:35:24 -08:00
Wyatt Hepler
5a235cb998 Run source_is_in_build_files on build file changes
Trigger the source_is_in_build_files presubmit check if BUILD, .bzl,
.gn, or .gni change.

Change-Id: Ic6d5f1a61b9691a87511d994534ff4a19aeb0c9e
2019-12-17 21:25:46 +00:00
Wyatt Hepler
ec4bb3d235 Check against committed files in presubmit hook
The installed pre-push hook checks against origin/master..HEAD instead
of just origin/master so that checks are only triggered by committed
changes.

Run pw presubmit --install to update the pre-push hook.

Change-Id: I6df0eef4fdec362222582592af4df1863608b95d
2019-12-17 12:58:01 -08:00
Rob Mohr
df1ee2f6f3 Use presubmit context.
Instead of passing paths into some presubmit checks and not others, always
pass a PresubmitContext object that includes paths, repository root, and can
contain additional members in the future.

For checks that used filtered paths, filter the PresubmitContext object
before it gets passed to the check.

Change-Id: Icf35b11587f89eeae2fdc578e11f6647b48e27f2
2019-12-17 10:41:17 -08:00
Keir Mierle
2cfd31423e pw_format: Disable some pylint checkers; tweaks
This disables the Pylint checker for line continuation, to avoid
fighting with YAPF. For now, the YAPF continuations are not in
accordance with PEP8, but we have decided that operationally it makes
more sense to just go with whatever YAPF suggests.

This also makes some tweaks to the format command logic better separate
out unrelated functionality.

Bug: 22
Change-Id: Ia29bc4c38c4de31dface0206d54db3b72a32c0cb
2019-12-17 10:20:57 -08:00
Rob Mohr
30bc80d8f6 Pass repo between git functions.
Change-Id: Ie7c6f5b58b20f1a3ff478a207c21b0ceab663180
2019-12-16 12:39:22 -08:00
Rob Mohr
21117d8c25 Run 'pw format --fix' on a few files.
Change-Id: I2300a824443ba9bca56ab1116fb451cb3003ea02
2019-12-16 19:06:00 +00:00
Keir Mierle
84d28f57b8 pw_presubmit: Tweaks to format warnings
Adds a copy-and-pastable command to fix formatting issues. Example:

$ pw presubmit
(... output omitted ...)
┏━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━┓
┃  14/15 │ Python format                                           │  43 files ┃
20191213 16:16:13 WRN Found 4 files with formatting errors. Format changes:

Change-Id: I9ea9058884dd32171fb7d8690ea2ffc2c2761e54
--- pw_bloat/py/bloat_output.py	(original)
+++ pw_bloat/py/bloat_output.py	(reformatted)
@@ -32,6 +32,7 @@
     @abc.abstractmethod
     def diff(self) -> str:

(... output omitted ...)

20191216 10:03:24 WRN To fix formatting, run:

  pw format --fix pw_bloat/py/bloat.py
  pw format --fix pw_bloat/py/bloat_output.py
  pw format --fix pw_presubmit/py/pw_presubmit/install_hook.py
  pw format --fix pw_protobuf_compiler/BUILD.gn

┃        │                                                         │           ┃
┃ FAILED │ Python format                                           │    0:00.5 ┃
┗━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━┛

Change-Id: I15a0fd442768b8af74920337eba911cc2066a80b
2019-12-16 10:04:41 -08:00
Wyatt Hepler
43158d0077 pw_presubmit: Fix running from different directory
Replace --repository with -C, which changes the directory before doing
anything.

Change-Id: I630ebb198122320aa402277f365dec9e44b696c6
2019-12-13 21:53:57 +00:00
Rob Mohr
0d5ea9d407 Allow running single steps in presubmit.
Add ability to run individual presubmit checks using --step.

Bug: 3
Change-Id: Ibcea8e54de2deb2e8159ae1389b86a5c82da0d14
2019-12-13 17:31:12 +00:00
Wyatt Hepler
dceb02000f pw_presubmit: Only show checks that run
- Evaluate each unique path filter once before running the checks.
- Do not output results for skipped checks.
- Add a message that calls out when no files are being checked.

Change-Id: I0d8debd50e7b5838e837693d46e29cc6d9da447e
2019-12-11 19:36:24 -08:00
Wyatt Hepler
a975821cbf pw_presubmit: Fix PATH; run Python tests
- Update the PATH to include the new CIPD directories.
- With the current Python test finding approach, Python tests must be
  run from the package directory. Update the presubmit check to do this.

Change-Id: Ie1cdf61875643d435608597b27d03695bf46d3c3
2019-12-11 14:40:09 -08:00
Wyatt Hepler
ee3e02f6cb Expand docs for a few modules
- Add missing README.md for a few modules.
- Start or expand docs.rst.

Change-Id: Ic13c5f71f02259205ba990c93e0403d43f7b44b1
2019-12-09 17:13:47 -08:00
Wyatt Hepler
fa70745e1c pw_presubmit: Update a few checks
- Fix Go formatting, which was accidentally using clang-format.
- Update source_is_in_build_files to query the build system rather than
  check build file contents.
- Remove pylint_errors_only check since full pylint is running.
- Add log_run wrapper that logs at debug then calls subprocess.run.

Change-Id: I1a335e2999b5aabcb2a39a2d8bc9fbe43d6dd75b
2019-12-09 19:20:09 +00:00
Wyatt Hepler
9113c9fea2 pw_presubmit: Always init_virtualenv; options
- Remove the path filter for init_virtualenv since the build depends on
  Python.
- Add --clean-py option for cleaning only the Python venv.
- Rename --continue to --keep-going for consistency with Bazel.
- Make updates to Git path handling to correctly handle absolute versus
  relative paths.
- Make the .presubmit directory relative to the root of the repo.

Change-Id: I9b2ce32dd4e1a9c993a10f37c252a685625c46ad
2019-12-06 16:24:11 -08:00
Alexei Frolov
d0b2d48782 Add pw_test_server module
This change adds a pw_test_server module which implements a gRPC server
for queueing and distributing unit tests across multiple test runners.
The server is implemented as a Go library which can be imported and used
by developers to build a custom unit test running infrastructure.

To use the server, a UnitTestRunner interface that processes requests to
run unit tests must be implemented and registered with the server. An
implementation of this interface which runs unit test executables
through an external command is provided alongside the server.

An example program that uses the server library to run a unit test
server is also provided within the module. This program uses the
command-based test runners to run unit tests on a local machine. It is
configurable through a config file, allowing multiple workers to be
registered with the server. The program additionally doubles as a gRPC
client for the server which can be invoked with the path to a unit test
executable to schedule it to be run.

Change-Id: I347d230370620395de09e277f9763d7df1c4abad
2019-12-06 22:55:28 +00:00
Wyatt Hepler
1ea1305312 pw_presubmit: Build file check; fatal pylint
- Check that all C, C++ sources appear in BUILD and BUILD.gn files.
- Check that all .rst files appear in BUILD.gn files.
- Make the pylint check fatal. The full presubmit will fail until some
  issues are fixed. Incremental presubmits (e.g. with the pre-push hook
  or pw presubmit --base master) will pass (unless there are errors).

Change-Id: Id42cc2e06278d0e56017a2008676db8e77ba6c20
2019-12-06 12:54:48 -08:00
Wyatt Hepler
ce14cb227e pw_presubmit: Use logging; UI improvements
- Switch many print statements to log statements.
- Only show command output when commands fail or debug logging is
  enabled.
- Add a wrapper class for check functions to consolidate running
  and logging logic for presubmit checks.

Change-Id: I72e155d602135b60c18f8973a778f40e65bb40da
2019-12-06 12:54:48 -08:00
Wyatt Hepler
b90f341ba5 pw_presubmit: Add new pw format command
- pw format (or pw_presubmit/format_code.py) supports checking and
  fixing the format of Python, C/C++, GN, and Go code.
- Move code format presubmit checks into format_code.py.
- Accept paths not in a Git repository for pw format.
- Add an explicit check that pw presubmit is run from a Git repo.

Change-Id: I74bf54057bd5ace70a90271f7d1343711455792a
2019-12-05 09:31:11 -08:00