Page MenuHome

Add `verbose` pseudo-targets to Makefile wrapper
Needs ReviewPublic

Authored by Loren Osborn (linux_dr) on Jul 24 2022, 9:18 AM.

Details

Summary

Summary

Adds new verbose pseudo-target to ./GNUMakefile to propagate VERBOSE to cmake and generated build Makefile. This is intended purely as a developer convenience and troubleshooting aid.

Background:

When a build fails, especially when it doesn't fail immediately, it is often very helpful to execute the failing build command by itself on the command line so the problem can be identified, fixed and verified quickly, possibly multiple times, to ensure most effective use of developers time correcting this issue.

By default, traditional Makefiles echo all build commands to STDERR before executing them, to make this troubleshooting easier. Unfortunately, with large systems like Blender, this would litter the terminal with hundreds of pages of output, of very little value, when everything is building correctly. To limit confusion, and reassure developers that the build is progressing as expected, Blender has opted (via cmake) to hide this flood of long cryptic commands, and replace it with progress percentages and file names. This can make how to reproduce a failing build command on the command line non-obvious. Cmake includes a VERBOSE mode, to expose the build commands for easier troubleshooting of failed builds.

Description of the problem that is addressed in the patch:

Because GNU make is so much more ubiquitous and familiar to many developers, compared to cmake, Blender also includes a "wrapper Makefile", for "users who like to configure & build blender with a single command".

GNUMakefile:6: # This is for users who like to configure & build blender with a single command.

This wrapper Makefile does not currently respect the VERBOSE option used by the rest of the build system.

Description of the proposed solution, and a motivation as to why this is the best solution:

This patch adds support for VERBOSE mode to the wrapper Makefile, and causes it to invoke Cmake, and the nested make invocations to run in VERBOSE mode.

This is intended as part of a larger solution:

  1. The build process should make it obvious what directory each build command is running from, so it is easy for a developer to execute it from the command line. (This may simply require not hiding the "now entering"/"now leaving" banners in VERBOSE mode, when executing nested makes.)
  2. The invocations of cmake within the nested build process should be echoed to STDERR before being executed within generated Makefile. (As these are generated by cmake, this requires additional research, and may be out of scope.)
  3. Currently the Makefile dependency tree is not being correctly generated, included or utilized; causing incomplete or over-long non-clean builds. (I will issue a Task for this specific issue: make test does not always update the test executables, before running tests.)
  4. This Patch: the wrapper Makefile should echo commands before running them in VERBOSE mode.
  5. Also This Patch: the wrapper Makefile should propigate VERBOSE mode to nested make (and nested cmake) build steps.
As for why this is "the best" solution to this issue:

It provides visibility to developers of what build commands are actually being executed.

List of alternative solutions, and a motivation as to why these are undesirable:

  • We can leave the status quo
    • I know I had search google and cmake forums to learn how to enable VERBOSE mode, and I still remained confused about how persistent the verbosity is.
  • We can get rid of the wrapper Makefile, to eliminate it as a source of confusion, and move these "recipes" to the documentation
    • I think this would simply cause developers to get lost in more RTFM confusion.
  • We can leave the wrapper Makefile unsupported
    • This is just the worst of the two previous options.
  • We let each developer eradicate the leading @s in GNUMakefile when necessary
    • This seems like a lot of duplicated effort.
  • Other options I missed?

Limitations of the proposed solution:

As mentioned above, it is only addresses 2 of 5 parts of the solution.

It doesn't address the python tooling, which executes external commands; but so. far these tools appear to be detecting and respecting the VERBOSE environment variable.

It also doesn't collate command echoing with command errors and output when run in parallel execution mode. (That would make it easier to tell which command was generating the errors.)

Mock-up of the proposed user interface and a description of how users are going to interact with the new feature:

To start a build in VERBOSE mode, simply execute any of these:

% make verbose
% VERBOSE=1 make
% export VERBOSE=1
% make

Diff Detail

Repository
rB Blender

Event Timeline

Loren Osborn (linux_dr) requested review of this revision.Jul 24 2022, 9:18 AM
Loren Osborn (linux_dr) created this revision.

Better handling of '--silent' option in recursive make in VERBOSE_MODE

GNUmakefile
645

I might want to change $(SILENCE_WHEN_NOT_VERBOSE) to a real @ here, but open to a second opinion.

Loren Osborn (linux_dr) retitled this revision from Add `verbose` pseudo-target to Makefile wrapper to Add `verbose` and `very_verbose` pseudo-targets to Makefile wrapper.
Loren Osborn (linux_dr) edited the summary of this revision. (Show Details)

Renamed VERBOSE_MODE to overlap with VERBOSE used elsewhere in the build system. Also added support to trigger feature with existing VERBOSE environment variable (based on feedback from @Ray Molenkamp (LazyDodo)).

Rewriting patch description in accordance with Ingredients of a Patch (also at suggestion of @Ray Molenkamp (LazyDodo)).

(I haven't heard back, but I've asked @Campbell Barton (campbellbarton) if he could review this.)

Loren Osborn (linux_dr) edited the summary of this revision. (Show Details)Aug 6 2022, 7:09 PM
Loren Osborn (linux_dr) edited the summary of this revision. (Show Details)Aug 6 2022, 7:13 PM
Loren Osborn (linux_dr) edited the summary of this revision. (Show Details)Aug 6 2022, 7:16 PM
GNUmakefile
338

Typo… accidental :== should be :=

Fixed typo… [UNTESTED…yet]

Currently away from the keyboard… will test when I return.

While it would be nice to easily print all commands, using a variable to prefix every command is quite awkward.
Multi-lines that are already getting difficult to follow become even more cryptic.

There are some possible alternatives to this patch that are less intrusive, although all things considered I'm not sure they're a net gain,

One would be to move all targets to build_files/make_targets/ they could be Python scripts for e.g. that take their own --verbose argument.

This has the advantage that some targets could be shared with make.bat, for targets that are only 1 liners it seems like an unnecessary indirection though.


Suggest not to apply this patch:

  • Developers who want to dig into CMake better do so without using the wrapper makefile.
  • Developers who want to know which command are called can check the commands being run can open the makefile and look at it.

Currently there is a comment in the header:

# This is for users who like to configure & build blender with a single command.

Suggest to extend it:

# This is for users who like to configure & build blender with a single command.
# It also contains convenience targets for updating, generating icons and documentation.
#
# NOTE: While we may consider adding options developers find useful,
# the purpose of this Makefile is *not* to replace use of the underlying commands.
# Developers who need to investigate issues are expected to run commands directly.
GNUmakefile
164–191

This seems unreasonably complex, perhaps an environment variable could be used instead since this seems like something developers wouldn't be using often.

Simplified based on feedback from @Campbell Barton (campbellbarton). (Also broke off 2 unrelated diffs that have yet to be posted.)

Loren Osborn (linux_dr) edited the summary of this revision. (Show Details)Aug 29 2022, 6:52 AM
GNUmakefile
164–191

$(DOLLARS) is only intended as a readability aid. It is intended as a very small subset of typical "special character variables" which often include BLANK, SPACE, COMMA, OPEN_PAREN, CLOSE_PAREN and HASH.

As far as $(SILENCE_UNLESS_VERBOSE), above, there is, unfortunately no way to disable the @ prefix that silences recipe commands short of removing it with a mechanism like this. A shorter name may be beneficial, but I was trying to prioritize clarity.

GNUmakefile
645

This was actually referring to the leading @ on line 201, as I did convert this to a real @.

Loren Osborn (linux_dr) retitled this revision from Add `verbose` and `very_verbose` pseudo-targets to Makefile wrapper to Add `verbose` pseudo-targets to Makefile wrapper.Aug 29 2022, 7:10 AM
GNUmakefile
372

Reviewer note:

These were replaced by FN_EVAL_OPTION_PSEUDO_TARGET_RULE (defined above and expanded below). For each “pseudo-target”, there is a single recipe rule as follows:

  • it has a single recipe line that is a silenced comment
  • if there are no non pseudo-target goals,
    • all pseudo-targets depend on the default goal (aka “all”)
    • otherwise pseudo-targets have no dependencies.

The changes for verbose still seem too intrusive, I'd be inclined to do something simpler:

1diff --git a/GNUmakefile b/GNUmakefile
2index a82d1bedace..35ff7aa20f4 100644
3--- a/GNUmakefile
4+++ b/GNUmakefile
5@@ -132,6 +132,8 @@ Environment Variables
6 * NPROCS: Number of processes to use building (auto-detect when omitted).
7 * AUTOPEP8: Command used for Python code-formatting (used for the format target).
8
9+ * VERBOSE: When defined and not 0, show commands that are executed.
10+
11 Documentation Targets
12 Not associated with building Blender.
13
14@@ -338,6 +340,16 @@ else
15 endif
16
17
18+# -----------------------------------------------------------------------------
19+# Setup Verbose Shell (VERBOSE=1)
20+
21+ifneq ($(origin VERBOSE),undefined)
22+ ifneq ($(VERBOSE),"0")
23+ SHELL+=-x
24+ endif
25+endif
26+
27+
28 # -----------------------------------------------------------------------------
29 # Build Blender
30 all: .FORCE
.

GNUmakefile
310

This will turn the variable on, even after

GNUmakefile
310

Accidentally included this comment from a previous review, AFAICS setting CMAKE_VERBOSE_MAKEFILE to ON will make the makefile verbose even when verbose isn't set.

Printing the commands that can be found by reading GNUMakefile or running make -n I'm not really convinced about,

The cmake verbosity settings are confusing and I can see the argument for making that more discoverable. But I also think this patch adds too much complexity.

Maybe just modifying BUILD_COMMAND to be make SHELL="sh -x" and ninja -v is enough.

Maybe just modifying BUILD_COMMAND to be make SHELL="sh -x" and ninja -v is enough.

As you can see in the above discussion with @Campbell Barton (campbellbarton), we were discussing exactly this. I wanted to see how D15830 turned out before I revised this again.