Skip to content

Commit

Permalink
build,compat: do not patch git tracked sources; apply compat patch in…
Browse files Browse the repository at this point in the history
… build subdir instead

Split the build process in ./drbd/.
`Makefile` calls the stages, no surprise there.

`Kbuild` is used to prepare the build directory,
calculate the compat.h, and copy over the `Kbuild.drbd` template.

`Kbuild` again is used to calculate the compat.patch
using spatch via `Makefile.spatch`, and applies it,
generating the patched files in build-dir.

build-dir `Kbuild` (from the `Kbuild.drbd` template)
is then used to build the module in build-dir.

`make compat.h`

Use Kbuild to generate a `build-$(KERNELRELEASE)/` subdirectory.
Create a `build-current/` symlink, so a naive `make install` will work.
Copy over a `Kbuild` from the `Kbuild.drbd` template.
Generate `drbd_buildtag.c`.
Generate `compat.h` (relevant recipes moved to `Makefile.compat`).

`make spatch`

Find a `compat.patch` in our `cocci_cache`, and symlink from there.
Or use coccinelle spatch (or spatch-as-a-service aka SPAAS) to generate
or fetch such a patch (and put it into the cocci_cache for later re-use).
See also `Makefile.spatch`, which now also includes some paranoia:
double check md5sum of compat.h with the path it was found under.

This now passes the parameters to `gen_compat_patch.sh` via bash variables.
That script now always shows spatch .stderr output, if any,
even for spatch "success" (exit code 0).

`make prep`

Provide a list of "expected" source files in Kbuild.drbd-module-sources.

Use a new `splitdiff.pl` to split that into individual patches.

This has the side effect of using only the _last_ patch, should coccinelle put
several patches for the same file in the compat.patch.
It seems to do that for headers.

Apply, and re-diff, filter through
`annotate-diff-with-original-file-position-pragmas.pl` and apply again.
Annotates the patched file with original source file names and line numbers,
respectively with the name of the compat patch and the line number
therein for patched lines, and generate single dummy hunks with only that
annotation for "expected" files that remain unchanged.
This way compiler error messages will point to the original sources.

`make kbuild`

Implicitly calls prep stage first, then
use Kbuild to build the modules from the generated sources.

`make install` is now also using Kbuild `modules_install` target
instead of the handcrafted recipe we had before.
  • Loading branch information
lge committed Mar 24, 2024
1 parent ca25a85 commit bac82c0
Show file tree
Hide file tree
Showing 12 changed files with 835 additions and 266 deletions.
31 changes: 10 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,14 @@
*.o
*.o.*

drbd/drbd.ko
drbd/drbd.ko.unsigned
drbd/drbd_transport_tcp.ko
drbd/drbd_transport_tcp.ko.unsigned
drbd/drbd_transport_tcp.mod.c
drbd/drbd_transport_rdma.ko
drbd/drbd_transport_rdma.ko.unsigned
drbd/drbd_transport_rdma.mod.c
drbd/*.mod
drbd/.*.cmd
drbd/.compat_test.*/
drbd/.config.*.timestamp
drbd/.kernel.config.gz
drbd/.drbd_kernelrelease
drbd/.drbd_kernelrelease.new
drbd/.drbd_git_revision
drbd/.tmp_versions
drbd/Module.symvers
drbd/tags
drbd/cscope.out
drbd/build-*/
drbd/compat*.h
drbd/drbd.mod.c
drbd/drbd_buildtag.c
drbd/modules.order
drbd/compat*.patch
drbd/.drbd_git_revision
drbd/dummy-for-compat-h.c
drbd/dummy-for-patch.c

/drbd-kmod_rhel.spdx
/drbd-kmod_sles.spdx
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,11 @@ module: check-kdir check-submods
install:
$(MAKE) -C drbd install

unpatch:
$(MAKE) -C drbd unpatch

clean: unpatch
clean:
@ set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i clean; done
rm -f *~
rm -f *~ ; rm -rf tmp.km-deb.*

distclean: unpatch
distclean:
@ set -e; for i in $(SUBDIRS); do $(MAKE) -C $$i distclean; done
rm -f *~ .filelist

Expand Down Expand Up @@ -338,7 +335,7 @@ endif
ifdef DEBBUILD
.PHONY: km-deb
km-deb: check-submods distclean drbd/.drbd_git_revision
D=$$(mktemp -p . -d); \
D=$$(mktemp -p . -d tmp.km-deb.XXXXXXXXXX); \
( git ls-files --recurse-submodules ; \
echo drbd/.drbd_git_revision ) | cpio -pvmd "$$D" ; \
( cd "$$D" && $(DEBBUILD) -i -us -uc -b ) && rm -rf "$$D"
Expand Down
Loading

0 comments on commit bac82c0

Please sign in to comment.