Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile: Cleanup and generate help from comment #2669

Merged
merged 11 commits into from
Jul 12, 2024

Conversation

lambdanis
Copy link
Contributor

@lambdanis lambdanis commented Jul 12, 2024

See commits.

The main goal here is to generate Makefile help from per-target doc comments instead of having all docs in the help target, which is hard to keep up-to-date. I used the approach from https://www.thapaliya.com/en/writings/well-documented-makefiles/. The result (in reality it's nicer, there are colors):

$ make help

Usage:
  make <target>

Build and install
  tetragon           Compile the Tetragon agent.
  tetragon-operator  Compile the Tetragon operator.
  tetra              Compile the Tetragon gRPC client.
  tetragon-bpf       Compile bpf programs (use LOCAL_CLANG=0 to compile in a Docker build env).
  tetragon-bench     Compile tetragon-bench tool.
  compile-commands   Generate a compile_commands.json with bear for bpf programs.
  install            Install tetragon agent and tetra as standalone binaries.

Container images
  image              Build the Tetragon agent container image.
  image-operator     Build the Tetragon operator container image.
  images             Convenience alias for image and image-operator.

Packages
  tarball            Build Tetragon compressed tarball.
  tarball-release    Build Tetragon release tarball.

Test
  check              Run Go linters.
  test               Run Go tests.
  tester-progs       Compile helper programs for unit testing.
  bpf-test           Run BPF tests.
  verify             Verify BPF programs.
  alignchecker       Run alignchecker.
  bench              Run Go benchmarks.
  test-compile       Compile unit tests.
  e2e-test           run e2e tests
  e2e-test E2E_BUILD_IMAGES=0  run e2e tests without (re-)building images
  e2e-test E2E_TESTS=./tests/e2e/tests/skeleton  run a specific e2e test

Development
  cscope             Generate cscope for bpf files.
  kind               Create a kind cluster for Tetragon development.
  kind-install-tetragon  Install local version of Tetragon in the kind cluster.
  kind-setup         Create a kind cluster and install local version of Tetragon.

Chores and generated files
  protogen           Generate code based on .proto files.
  crds               Generate kubebuilder files.
  vendor             Tidy and vendor Go modules.
  clang-format       Run code formatter on BPF code.
  go-format          Run code formatter on Go code.
  format             Convenience alias for clang-format and go-format.
  generate-flags     Generate Tetragon daemon flags for documentation.
  metrics-docs       Generate metrics reference documentation page.
  lint-metrics-md    Check if metrics documentation is up to date.

Documentation
  help               Display this help, based on https://www.thapaliya.com/en/writings/well-documented-makefiles/
  docs               Preview documentation website.
  version            Print Tetragon version.

CLI
  cli-release        Compile tetra CLI release binaries.

Options
  TARGET_ARCH             target architecture to build for (e.g. amd64 or arm64)
  BPF_TARGET_ARCH         target architecture for BPF progs (set by TARGET_ARCH)
  GO_ARCH                 target architecture for Go progs (set by TARGET_ARCH)
  DEBUG                   enable NOOPT and NOSTRIP
  NOOPT                   disable optimization in Go build (set by DEBUG)
  NOSTRIP                 disable binary stripping in Go build (set by DEBUG)
  LOCAL_CLANG             use the local clang install for BPF compilation
  JOBS                    number of jobs to run for BPF compilation (default to nproc)
  EXTRA_GO_BUILD_LDFLAGS  extra flags to pass to the Go linker
  EXTRA_GO_BUILD_FLAGS    extra flags to pass to the Go builder
  EXTRA_TESTFLAGS         extra flags to pass to the test binary

lambdanis added 11 commits July 12, 2024 17:47
Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
Admittedly grouping multiple .PHONY annotations together makes sense, but then
it's harder to track which targets are marked as .PHONY and which not. Most of
the time it doesn't matter, but when it does it can be extremely confusing.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
It's not used. Targets for building docker images are defined in the main
Makefile.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
Makefile targets used to be documented under the help target. However, such
documentation is hard to keep up-to-date. This commit reqwrites the help target
to generate documentation from per-target comments. This approach is based on
https://www.thapaliya.com/en/writings/well-documented-makefiles/

The generated documentation doesn't group targets - this will be done in the
following commits. It also doesn't yet include additional options.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
This is only moving code around and adding groups comments. The result of `make
help` is:
```

Usage:
  make <target>

Build and install
  tetragon           Compile the Tetragon agent.
  tetragon-operator  Compile the Tetragon operator.
  tetra              Compile the Tetragon gRPC client.
  tetragon-bpf       Compile bpf programs (use LOCAL_CLANG=0 to compile in a Docker build env).
  compile-commands   Generate a compile_commands.json with bear for bpf programs.
  install            Install tetragon agent and tetra as standalone binaries.

Container images
  image              Build the Tetragon agent container image.
  image-operator     Build the Tetragon operator container image.

Packages
  tarball            Build Tetragon compressed tarball.
  tarball-release    Build Tetragon release tarball.

Test
  tester-progs       Compile helper programs for unit testing.
  test-compile       Compile unit tests.

Development

Chores and generated files
  protogen           Generate code based on .proto files.
  crds               Generate kubebuilder files.
  vendor             Tidy and vendor Go modules.
  clang-format       Run code formatter on BPF code.
  go-format          Run code formatter on Go code.
  format             Convenience alias for clang-format and go-format.
  generate-flags     Generate Tetragon daemon flags for documentation.
  metrics-docs       Generate metrics reference documentation page.
  lint-metrics-md    Check if metrics documentation is up to date.

Documentation
  help               Display this help, based on https://www.thapaliya.com/en/writings/well-documented-makefiles/
  docs               Preview documentation website.

CLI
  cli-release        Compile tetra CLI release binaries.
```

The following commits will add missing doc comments.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
Additional lines for `make help` are rendered from comments following the
format:

  ## <target with options>: ## <description>

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
These are options that were documented by former `make help`, just re-adding
them to the new target.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
Remove $(QUIET) from commands already prefixed with @, as it does nothing.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
We're using `make check` instead.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
These targets were using undefined COPYRIGHT_DIRS variable and nonexistent
contrib/copyright-headers tool. Seems a historical leftover.

Signed-off-by: Anna Kapuscinska <anna@isovalent.com>
@lambdanis lambdanis added the release-note/misc This PR makes changes that have no direct user impact. label Jul 12, 2024
@lambdanis lambdanis requested review from willfindlay and a team as code owners July 12, 2024 17:03
Copy link
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@lambdanis lambdanis merged commit b83e10c into cilium:main Jul 12, 2024
40 checks passed
@mtardy
Copy link
Member

mtardy commented Jul 15, 2024

This is awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants