Commit Graph

43 Commits

Author SHA1 Message Date
Wyatt Hepler
8b8c34647b pw_cli: Make process.py faster
- For run_async, replace the silent option with the log_output option.
  With log_output, lines are read one-by-one and logged. Otherwise, the
  output is dumped to a temporary file.
- For tests, only log the output on failure. This substantially speeds
  up verbose tests. A pw_kvs test went from 38 s to 1.2 s when
  passing, or 26 s when failing and printing the output.

Change-Id: Iba18c555c07eeaa9eb5ba79bc8d36d3ef2435485
2020-03-13 19:36:59 +00:00
Rob Mohr
1ed996b2d6 pw_doctor: check for pre-push hook
Fixed: 157
Change-Id: I94cb3295226d97f503ecbcf353f92582ce4b4f64
2020-03-13 18:29:00 +00:00
Alexei Frolov
4dcf99d274 env_setup: Split activate and bootstrap on Windows
This change creates a top level bootstrap and activate script on Windows
to mirror the Linux setup.

Change-Id: I6d06ea2112b68deceb0d6d2011c3c80699a7e77f
2020-03-11 16:32:26 +00:00
Alexei Frolov
426b9b8da0 pw_env_setup: Just use the system Python
MacOS runs into some strange issues when trying to call python3. While
the source of these issues has not been found, it was determined that
there is no longer any reason to try to prioritize python3 for env
setup, as it works with any Python version.

The environment variable to force python2 has been replaced with a
variable to force a specific version of Python.

Fixed: 151
Change-Id: Ief21cb1cf3f5326d2d7036d46c3a9fc0504ba9fa
2020-03-09 22:48:46 +00:00
Alexei Frolov
a137f970fa pw_env_setup: Improve POSIX CLI output
This change updates the output of the bootstrap and env_setup scripts to
make it more detailed and prettier.

The POSIX-side improvements are handled here; Windows will come in a
follow-up change.

Example output:

  WELCOME TO...

 ▒█████▄   █▓  ▄███▒  ▒█    ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
  ▒█░  █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█  ▒█   ▀  ▒█   ▀  ▒█  ▀█▌
  ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█  ▒███    ▒███    ░█   █▌
  ▒█▀     ░█░ ▓█   █▓ ░█░ █ ▒█  ▒█   ▄  ▒█   ▄  ░█  ▄█▌
  ▒█      ░█░ ░▓███▀   ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀

  BOOTSTRAP! Bootstrap may take a few minutes; please be patient.

Downloading and installing packages into local source directory:

  Setting up CIPD package manager...done
  Setting up Python environment.....done
  Setting up Pigweed host tools.....done
  Setting up Rust's cargo...........done

Activating environment (setting environment variables):

  Setting environment variables for CIPD package manager...done
  Setting environment variables for Python environment.....done
  Setting environment variables for Pigweed host tools.....done
  Setting environment variables for Rust's cargo...........skipped
    Note: Re-run bootstrap with PW_CARGO_SETUP=1 set in your environment
          to enable Rust.

Sanity checking the environment:

20200306 12:48:12 ℹ️  Pigweed environment passes all checks!

Environment looks good; you are ready to go!

To activate this environment in the future, run this in your terminal:

  . pw_env_setup/env_setup.sh

Bug: 143
Change-Id: If91457888cecfa117d5b8907c82c396413c640e8
2020-03-07 00:15:37 +00: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
Alexei Frolov
728048b892 pw_cli: Add argument to hide banner
This change adds an argument to the pw command which prevents it from
printing the Pigweed banner. This is useful when pw is called from
scripts to avoid polluting the output.

Bug: 143

Change-Id: I30af43bd7815aa0472a1cb1ac2ca3f5ef49976dc
2020-03-06 00:03:52 +00:00
Rob Mohr
5880a97c08 Disable cargo setup by default
Fixes: 109
Change-Id: I6dc2ed9b5ebc87a4a6c313ebae6745ed96040f65
2020-01-30 18:26:18 -08:00
Rob Mohr
e07c20d9eb Add output and run doctor in env setup
Echo info about steps in generated env setup script.

Also run 'pw doctor' at end of env setup script.

Non-warning/error output can be suppressed by setting
PW_ENVSETUP_QUIET to '1'.

Change-Id: Ief333779dabbdb4613db05726d00f80d3fca325a
2020-01-28 15:01:03 -08:00
Alexei Frolov
3a746c547e env_setup: enable host build in Windows
This change fixes pw_exec to work with Windows GOPATHs and enables ANSI
color codes in cmd.exe. This should be the final change required to run
host builds within Windows, so it is added back into the env_setup
steps.

Fixes: 97
Change-Id: I389e9374ec685f2b94de8d7651733207e7b1ecf8
2020-01-24 21:21:03 +00:00
Alexei Frolov
3ef4f9a219 Improve test runner logging
This change switches the test runner from coloredlogs to pw_cli.log with
the timestamp removed to improve its output when running from Ninja.

Change-Id: Ieb6dd09988309eb3244f13345a73c7b9053a5065
2020-01-17 22:20:02 +00:00
Rob Mohr
59381020fe Add new vars to env.py
Change-Id: Ifc3ebcb67219b228faa69996f79ca1f8cfe75522
2020-01-14 07:40:41 -08:00
Alexei Frolov
1e72d49439 envparse: Accept emoji as booleans
This change updates the envparse strict_bool type to accept emoji.

Change-Id: I585445399367e07cb2e30605f62cf44f882ee2cd
2020-01-13 23:29:05 +00:00
Alexei Frolov
e1115f1728 pw_cli: Add emoji for log levels
This change enables emoji in pw_cli logs with PW_EMOJI=1.

Bug: 56
Change-Id: Iaafaa2a1dc2c3f3defe613442a32d6a006f4feba
2020-01-13 18:14:35 +00:00
Wyatt Hepler
8d7f82d0c4 pw_cli: Handle decoding errors for log statement
Change-Id: I71c22f624253fc35524ae6500e90ee04e06e89f3
2020-01-10 01:14:10 +00:00
Alexei Frolov
7dadcce567 pw_watch: Add emoji
This change adds emoji support to the watch command.

Change-Id: Ic42569668ed7caec51678cd02a122a89f23b7319
2020-01-10 00:35:00 +00:00
Rob Mohr
4fef7c6d65 Reduce env_setup output.
$ source env_setup/bootstrap.sh
Setting up cipd...done.
Setting up python...done.
Setting up host_tools...done.

Fixes: 40
Change-Id: I8ed2500d1dd3e17c8f65b5788c2fb3ce42275cdb
2020-01-07 22:33:01 +00:00
Rob Mohr
9b178ca51f Move watch outside of pw_cli.
Create new module for 'pw watch' command.

Change-Id: Id0cb4b8204fe6201935f13ff99101ef554d3c80b
2020-01-07 22:27:21 +00:00
Alexei Frolov
7b8528e85d pw_cli: Define Pigweed environment variables
This change adds an environment module to pw_cli which defines all of
the environment variables used by Pigweed.
A new variable named PW_USE_COLOR added, forcing the use of log colors
even if not printing to a TTY. This is set by the watch command for its
subprocesses.
The check for the PW_SUBPROCESS variable in logging is updated to use
the environment module.

Change-Id: I84007691f3ae9bb262c6bf6471afa43db831268f
2020-01-03 23:57:15 +00:00
Alexei Frolov
77e7a61be2 pw_cli: Add envparse module
This change adds a Python module which implements an environment
variable parser that allows defining and typing environment variables
for a Python program.

Change-Id: Icda61c8dabcf4e4bc6902707f6ebed9c50d31d71
2020-01-03 01:43:47 +00: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
Alexei Frolov
67ffe1f262 Ignore presubmit directory in pw watch
This change extends the watch command to ignore the presubmit directory
in addition to its build directories.

Change-Id: I7880fcbd4e2887a8af736ee93ffccd404d60256e
2019-12-27 18:10:26 +00:00
Keir Mierle
313e26058a pw_watch: Set log level for build result log line
Change-Id: I4323441465f19323771e253b5ac3062f9db7d124
2019-12-26 12:45:02 -08:00
Alexei Frolov
300dcea444 pw_test_server -> pw_target_runner
This change renames the pw_test_server module to pw_target_runner and
integrates it into the GN build using the new Go templates. The module
is updated to match the GOPATH structure under its go/ directory, and
its protos are moved into the module protos directory. Additionally,
the simple server and client are split into two separate programs
instead of combining them into one.

Change-Id: I44adeca0989dc7e15cb1a169a6ce183139dde2ce
2019-12-26 18:38:24 +00:00
Keir Mierle
4f96c062ed pw_watch: Ignore changes inside build directories
Before this patch, creating or modifying source files inside build
directories would re-trigger the build in the watcher. Until recently
this was not a problem, but with the introduction of Go support, we are
generating files in the out directory that trigger the watcher. This
change filters out all changes coming from the build directory.

Change-Id: Iecb33b23bfef623fd7ca83194b44e0157554da31
2019-12-26 18:31:55 +00:00
Keir Mierle
1489ce6709 pw_watch: Fix lint problem
Change-Id: I362bd4c50d5deb566bcfe1def80f32d6cb8b9e32
2019-12-23 13:34:48 -08:00
Keir Mierle
e94839312b pw_watch: Clear screen and add build banner
This makes the watcher clear the terminal before starting a build, to
make it clearer what terminal output is associated with the current
build. Additionally, a "BUILD" banner is now printed at the top to
indicate that a build is starting.

The approach of clearing the screen is also what various file watchers
from the JavaScript world do.

Example output:

  ██████╗ ██╗   ██╗██╗██╗     ██████╗
  ██╔══██╗██║   ██║██║██║     ██╔══██╗
  ██████╔╝██║   ██║██║██║     ██║  ██║
  ██╔══██╗██║   ██║██║██║     ██║  ██║
  ██████╔╝╚██████╔╝██║███████╗██████╔╝
  ╚═════╝  ╚═════╝ ╚═╝╚══════╝╚═════╝

20191223 12:41:11 INF Change detected: ./pw_varint/varint_test.cc
20191223 12:41:11 INF Starting build with 2 directories
20191223 12:41:11 INF [1/2] Starting build: out/disco

ninja: Entering directory `out/disco'
ninja: no work to do.

20191223 12:41:11 INF [1/2] Finished build: out/disco (OK)
20191223 12:41:11 INF [2/2] Starting build: out/host

ninja: Entering directory `out/host'
ninja: no work to do.

20191223 12:41:11 INF [2/2] Finished build: out/host (OK)
20191223 12:41:11 INF Finished; all successful.

 .------------------------------------
 |
 |   OK    out/disco
 |   OK    out/host
 |
 '------------------------------------

  ██████╗  █████╗ ███████╗███████╗██╗
  ██╔══██╗██╔══██╗██╔════╝██╔════╝██║
  ██████╔╝███████║███████╗███████╗██║
  ██╔═══╝ ██╔══██║╚════██║╚════██║╚═╝
  ██║     ██║  ██║███████║███████║██╗
  ╚═╝     ╚═╝  ╚═╝╚══════╝╚══════╝╚═╝

Bug: 39
Change-Id: I4383ff489aa3d51b8320fa514001e95529b8db85
2019-12-23 12:46:45 -08: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
Wyatt Hepler
1ccce6b953 pw_cli: Disable colors if the output is not a tty
Bug: 19

Change-Id: Ibdc1f72643415acb12dbf731cd45a9cb786a9fd2
2019-12-17 18:40:46 +00:00
Keir Mierle
028ee9feb3 Lint fixes
Change-Id: I00b93c8e951d28deb2212bbba660dd6528433502
2019-12-16 10:08:55 -08:00
Keir Mierle
7178877ec2 pw watch: Minor UI/logging tweaks
Change-Id: I85da72f666ee111b7fe03f2f3d209167449286d7
2019-12-13 20:49:23 +00:00
Alexei Frolov
942adf02d6 Add pw_protobuf_compiler module
This change adds a module responsible for invoking the protobuf compiler
to generate code from .proto definition files. It provides a GN template
which performs the codegen operation on a list of input .proto files.
The template currently only supports C++.

Change-Id: I5558fd5b4282e0d6f09f8fafebda972738dc1e83
2019-12-13 19:38:27 +00:00
Rob Mohr
8edfeaeec0 Rename help to short_help.
Change-Id: Ibd41f06c2701b6c68a4a45c08a07c335679b976c
2019-12-09 13:45:01 -08:00
Rob Mohr
e023ba9577 Fix pylint warnings.
Change-Id: I8ef482776bcb5ec89afde39f215bd52c950a4b1b
2019-12-09 09:59:51 -08:00
Wyatt Hepler
becb431e5f Apply pw format to the repository
Change-Id: I3c8e4f956dfe6c9e81d3069f72c30c5950852074
2019-12-05 09:31:11 -08:00
Armando Montanez
93e445e84b pw_cli: Remove date/time from subprocess logs
When python scripts are run using pw_cli.subprocess, the output of their
lgos will be prefixed with a date/time stamp. This change prevents
subprocesses from adding a second timestamp.

Example:
~/pigweed/pigweed$ pw test --root out/stm32f429i-disc1/ --runner stm32f429i_disc1_unit_test_runner -- --port /dev/ttyACM0

 ▒█████▄   █▓  ▄███▒  ▒█    ▒█ ░▓████▒ ░▓████▒ ▒▓████▄
  ▒█░  █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█  ▒█   ▀  ▒█   ▀  ▒█  ▀█▌
  ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█  ▒███    ▒███    ░█   █▌
  ▒█▀     ░█░ ▓█   █▓ ░█░ █ ▒█  ▒█   ▄  ▒█   ▄  ░█  ▄█▌
  ▒█      ░█░ ░▓███▀   ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀

20191202 14:30:07 INF Scanning for tests...
20191202 14:30:07 INF Found 4 test groups (10 tests).
20191202 14:30:07 INF Running test groups //pw_status:tests, //pw_preprocessor:tests, //pw_string:tests, //pw_span:tests
20191202 14:30:07 INF Test  1/10: [RUN] concat_test
20191202 14:30:07 OUT [24930] INF Flashing firmware to device...
20191202 14:30:07 OUT [24930] INF Successfully flashed firmware to device!
20191202 14:30:07 OUT [24930] INF Test passed!
20191202 14:30:08 INF stm32f429i_disc1_unit_test_runner exited successfully
20191202 14:30:08 INF Test  1/10: [PASS] concat_test
20191202 14:30:08 INF Test  2/10: [RUN] type_to_string_test
20191202 14:30:08 OUT [24947] INF Flashing firmware to device...
20191202 14:30:09 OUT [24947] INF Successfully flashed firmware to device!
20191202 14:30:11 OUT [24947] INF Test passed!
20191202 14:30:11 INF stm32f429i_disc1_unit_test_runner exited successfully

Change-Id: I9ea7cafcde2183132f54e135ecadd7b2878f71f0
2019-12-03 18:32:43 +00:00
Alexei Frolov
572ca89be2 Add environment variable to pw_cli.process module
This change sets an environment variable in the subprocess run by
pw_cli.process.run() to indicate that it is running as a subprocess.

Change-Id: I1def3259b62578a156a4b374d41af99692147699
2019-12-02 21:48:12 +00:00
Wyatt Hepler
dac350b8e1 presubmit: Improve venv setup; expand checks
- Use env_setup/virtualenv/init.py to setup the Python venv.
- Improve diff colorization.
- Add function for finding Python packages from .py file changes.
- Add check that runs Python tests.
- Enable full pylint and yapf as warnings.
- Delete unused code in watch.py that used an undefined variable.
- Enable required python -E check.

Change-Id: I5ba9882ea9ec93f006260d5636031dd0b5005a85
2019-12-02 21:37:19 +00:00
Wyatt Hepler
c3844d9c3e Clean up requirements.txt
- Have requirements.in only include what is necessary for the build.
- Update requirements.txt.
- Remove pw_cli/requirements.txt since the dependencies are noted in the
  setup.py.

Change-Id: I622d066312c0436074d10fe6e8345feed1c31d06
2019-11-27 22:34:02 +00:00
Wyatt Hepler
1a96094ce6 Fix copyright notices
- Add missing copright header in conf.py.
- Fix inconsistent copyright notice line breaking.

Change-Id: Ib78f7768643069c49ff986a48a176df9fd06e891
2019-11-27 22:34:02 +00:00
Keir Mierle
ab847d9479 pw_module: Start the Pigweed meta-module
This starts a basic Pigweed meta-module tool. The first tool is a simple
checker invoked with

  pw module-check

which for now does two super-simple checks. Example output:

$ pw module-check pw_module
20191125 07:53:57 PM INF Checking module: pw_module
20191125 07:53:57 PM INF OK: Module pw_module looks good; no errors or warnings found

$ pw module-check pw_foo
20191125 07:54:00 PM INF Checking module: pw_foo
20191125 07:54:00 PM ERR PWCK001: Python code present but no setup.py.
20191125 07:54:00 PM ERR PWCK002: C++ code present but no tests at all (you monster).
20191125 07:54:00 PM ERR FAIL: Found errors when checking module pw_foo

Change-Id: I6eb3bfa941abc450a33affbec3e005477b9b2dc4
2019-11-27 21:33:13 +00:00
Alexei Frolov
8253ad8d66 Module to run subprocesses with captured output
This change adds a module within pw_cli that provides a function for
running a subprocess and capturing its stdout and stderr to the main
pw log. A new log level is defined for the captured output.

The pw_unit_test runner script is updated to use this function instead
of running its subprocess directly.

The pw command is updated to run its subcommand in an async context,
preventing subcommands from needing to create their own. Fully
synchronous subcommands continue to function transparently to this.

Change-Id: Ia9efb1fbda8a38ef91a0e14113929711038710a8
2019-11-27 20:34:16 +00:00
Keir Mierle
54f457f205 Rename pw_cmd to pw_cli
This renames pw_cmd to pw_cli, since our plan is for the cli module to
contain general command line interface related tooling, rather than just
the pw_cmd itself.

Change-Id: I1dc7185db25b89d725601ac5d47e0793ea907bf1
2019-11-25 22:16:02 +00:00