Skip to content

Commit

Permalink
fix(pkg/driverbuilder): use a single constant for the Cmake command.
Browse files Browse the repository at this point in the history
Moreover, add back some now unused cmake variables, ie:
* PROBE_NAME
* PROBE_VERSION
* PROBE_DEVICE_NAME

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
  • Loading branch information
FedeDP committed Feb 28, 2024
1 parent cb2c45b commit 13171b6
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 18 deletions.
30 changes: 29 additions & 1 deletion pkg/driverbuilder/builder/builders.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,25 @@ import (
)

// DriverDirectory is the directory the processor uses to store the driver.
const DriverDirectory = "/tmp/driver"
const (
DriverDirectory = "/tmp/driver"
cmakeCmdFmt = `cmake -Wno-dev \
-DUSE_BUNDLED_DEPS=On \
-DCREATE_TEST_TARGETS=Off \
-DBUILD_LIBSCAP_GVISOR=Off \
-DBUILD_LIBSCAP_MODERN_BPF=Off \
-DENABLE_DRIVERS_TESTS=Off \
-DDRIVER_NAME=%s \
-DPROBE_NAME=%s \
-DBUILD_BPF=On \
-DDRIVER_VERSION=%s \
-DPROBE_VERSION=%s \
-DGIT_COMMIT=%s \
-DDRIVER_DEVICE_NAME=%s \
-DPROBE_DEVICE_NAME=%s \
.. && \
sed -i s/'DRIVER_COMMIT ""'/'DRIVER_COMMIT "%s"'/g driver/src/driver_config.h`
)

var HeadersNotFoundErr = errors.New("kernel headers not found")

Expand Down Expand Up @@ -59,6 +77,7 @@ type commonTemplateData struct {
BuildModule bool
BuildProbe bool
GCCVersion string
CmakeCmd string
}

// Builder represents a builder capable of generating a script for a driverkit target.
Expand Down Expand Up @@ -293,6 +312,15 @@ func (c Config) toTemplateData(b Builder, kr kernelrelease.KernelRelease) common
BuildModule: len(c.ModuleFilePath) > 0,
BuildProbe: len(c.ProbeFilePath) > 0,
GCCVersion: c.GCCVersion,
CmakeCmd: fmt.Sprintf(cmakeCmdFmt,
c.DriverName,
c.DriverName,
c.DriverVersion,
c.DriverVersion,
c.DriverVersion,
c.DeviceName,
c.DeviceName,
c.DriverVersion),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/alinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/almalinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/amazonlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/archlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mv usr/lib/modules/*/build/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/centos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mv usr/src/kernels/*/* /tmp/kernel
cd {{ .DriverBuildDir }}
sed -i 's/$(MAKE) -C $(KERNELDIR)/$(MAKE) KCFLAGS="-Wno-incompatible-pointer-types" -C $(KERNELDIR)/g' driver/Makefile.in
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sourcedir=$(find . -type d -name "{{ .KernelHeadersPattern }}" | head -n 1 | xar

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/flatcar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ make KCONFIG_CONFIG=/tmp/kernel.config modules_prepare

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cd {{ .DriverBuildDir }}
{{ if .DownloadSrc }}
echo "* Configuring sources with cmake"
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}
{{ end }}
{{ end }}

Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/opensuse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sourcedir="$(find . -type d -name "linux-*-obj" | head -n 1 | xargs readlink -f)

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/oracle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/photonos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ mv usr/src/linux-*headers-*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/redhat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/rocky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ mv usr/src/kernels/*/* /tmp/kernel

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/sles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ sourcedir="$(find . -type d -name "linux-*-obj" | head -n 1 | xargs readlink -f)

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sourcedir=$(find . -type d -name "{{ .KernelHeadersPattern }}" | head -n 1 | xar

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down
2 changes: 1 addition & 1 deletion pkg/driverbuilder/builder/templates/vanilla.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export KBUILD_MODPOST_WARN=1

cd {{ .DriverBuildDir }}
mkdir -p build && cd build
cmake -DUSE_BUNDLED_DEPS=On -DCREATE_TEST_TARGETS=Off -DBUILD_LIBSCAP_GVISOR=Off -DBUILD_LIBSCAP_MODERN_BPF=Off -DENABLE_DRIVERS_TESTS=Off -DDRIVER_NAME={{ .ModuleDriverName }} -DBUILD_BPF=On ..
{{ .CmakeCmd }}

{{ if .BuildModule }}
# Build the module
Expand Down

0 comments on commit 13171b6

Please sign in to comment.