diff mbox series

[bpf-next,v3,2/7] tools/bpftool: Force clean of out-of-tree build

Message ID 20201110164310.2600671-3-jean-philippe@linaro.org (mailing list archive)
State Accepted
Commit 9e8929fdbb9c9026bd3a732e9ac7dc9617c86309
Delegated to: BPF
Headers show
Series tools/bpftool: Some build fixes | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 4 this patch: 4
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch fail Link
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Jean-Philippe Brucker Nov. 10, 2020, 4:43 p.m. UTC
Cleaning a partial build can fail if the output directory for libbpf
wasn't created:

$ make -C tools/bpf/bpftool O=/tmp/bpf clean
/bin/sh: line 0: cd: /tmp/bpf/libbpf/: No such file or directory
tools/scripts/Makefile.include:17: *** output directory "/tmp/bpf/libbpf/" does not exist.  Stop.
make: *** [Makefile:36: /tmp/bpf/libbpf/libbpf.a-clean] Error 2

As a result make never gets around to clearing the leftover objects. Add
the libbpf output directory as clean dependency to ensure clean always
succeeds (similarly to the "descend" macro). The directory is later
removed by the clean recipe.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 tools/bpf/bpftool/Makefile | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Andrii Nakryiko Nov. 11, 2020, 4:57 a.m. UTC | #1
On Tue, Nov 10, 2020 at 8:46 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> Cleaning a partial build can fail if the output directory for libbpf
> wasn't created:
>
> $ make -C tools/bpf/bpftool O=/tmp/bpf clean
> /bin/sh: line 0: cd: /tmp/bpf/libbpf/: No such file or directory
> tools/scripts/Makefile.include:17: *** output directory "/tmp/bpf/libbpf/" does not exist.  Stop.
> make: *** [Makefile:36: /tmp/bpf/libbpf/libbpf.a-clean] Error 2
>
> As a result make never gets around to clearing the leftover objects. Add
> the libbpf output directory as clean dependency to ensure clean always
> succeeds (similarly to the "descend" macro). The directory is later
> removed by the clean recipe.
>
> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> ---
>  tools/bpf/bpftool/Makefile | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index f60e6ad3a1df..1358c093b812 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -27,11 +27,13 @@ LIBBPF = $(LIBBPF_PATH)libbpf.a
>
>  BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
>
> -$(LIBBPF): FORCE
> -       $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
> +$(LIBBPF_OUTPUT):
> +       $(QUIET_MKDIR)mkdir -p $@
> +
> +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
>         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
>
> -$(LIBBPF)-clean:
> +$(LIBBPF)-clean: $(LIBBPF_OUTPUT)

shouldn't this be `| $(LIBBPF_OUTPUT)` ?

>         $(call QUIET_CLEAN, libbpf)
>         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null
>
> --
> 2.29.1
>
Jean-Philippe Brucker Nov. 11, 2020, 8:54 a.m. UTC | #2
On Tue, Nov 10, 2020 at 08:57:51PM -0800, Andrii Nakryiko wrote:
> On Tue, Nov 10, 2020 at 8:46 AM Jean-Philippe Brucker
> <jean-philippe@linaro.org> wrote:
> >
> > Cleaning a partial build can fail if the output directory for libbpf
> > wasn't created:
> >
> > $ make -C tools/bpf/bpftool O=/tmp/bpf clean
> > /bin/sh: line 0: cd: /tmp/bpf/libbpf/: No such file or directory
> > tools/scripts/Makefile.include:17: *** output directory "/tmp/bpf/libbpf/" does not exist.  Stop.
> > make: *** [Makefile:36: /tmp/bpf/libbpf/libbpf.a-clean] Error 2
> >
> > As a result make never gets around to clearing the leftover objects. Add
> > the libbpf output directory as clean dependency to ensure clean always
> > succeeds (similarly to the "descend" macro). The directory is later
> > removed by the clean recipe.
> >
> > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > ---
> >  tools/bpf/bpftool/Makefile | 8 +++++---
> >  1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> > index f60e6ad3a1df..1358c093b812 100644
> > --- a/tools/bpf/bpftool/Makefile
> > +++ b/tools/bpf/bpftool/Makefile
> > @@ -27,11 +27,13 @@ LIBBPF = $(LIBBPF_PATH)libbpf.a
> >
> >  BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
> >
> > -$(LIBBPF): FORCE
> > -       $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
> > +$(LIBBPF_OUTPUT):
> > +       $(QUIET_MKDIR)mkdir -p $@
> > +
> > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
> >         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
> >
> > -$(LIBBPF)-clean:
> > +$(LIBBPF)-clean: $(LIBBPF_OUTPUT)
> 
> shouldn't this be `| $(LIBBPF_OUTPUT)` ?

It wouldn't have any effect here. Order-only prerequisites tell make to
only build the prerequisite before the target, but not to update the
target if the prerequisite was updated. Because $(LIBBPF)-clean is not a
file, the recipe is always run and adding the | doesn't make a difference.

Thanks,
Jean
Andrii Nakryiko Nov. 11, 2020, 6:22 p.m. UTC | #3
On Wed, Nov 11, 2020 at 12:55 AM Jean-Philippe Brucker
<jean-philippe@linaro.org> wrote:
>
> On Tue, Nov 10, 2020 at 08:57:51PM -0800, Andrii Nakryiko wrote:
> > On Tue, Nov 10, 2020 at 8:46 AM Jean-Philippe Brucker
> > <jean-philippe@linaro.org> wrote:
> > >
> > > Cleaning a partial build can fail if the output directory for libbpf
> > > wasn't created:
> > >
> > > $ make -C tools/bpf/bpftool O=/tmp/bpf clean
> > > /bin/sh: line 0: cd: /tmp/bpf/libbpf/: No such file or directory
> > > tools/scripts/Makefile.include:17: *** output directory "/tmp/bpf/libbpf/" does not exist.  Stop.
> > > make: *** [Makefile:36: /tmp/bpf/libbpf/libbpf.a-clean] Error 2
> > >
> > > As a result make never gets around to clearing the leftover objects. Add
> > > the libbpf output directory as clean dependency to ensure clean always
> > > succeeds (similarly to the "descend" macro). The directory is later
> > > removed by the clean recipe.
> > >
> > > Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
> > > ---
> > >  tools/bpf/bpftool/Makefile | 8 +++++---
> > >  1 file changed, 5 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> > > index f60e6ad3a1df..1358c093b812 100644
> > > --- a/tools/bpf/bpftool/Makefile
> > > +++ b/tools/bpf/bpftool/Makefile
> > > @@ -27,11 +27,13 @@ LIBBPF = $(LIBBPF_PATH)libbpf.a
> > >
> > >  BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
> > >
> > > -$(LIBBPF): FORCE
> > > -       $(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
> > > +$(LIBBPF_OUTPUT):
> > > +       $(QUIET_MKDIR)mkdir -p $@
> > > +
> > > +$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
> > >         $(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
> > >
> > > -$(LIBBPF)-clean:
> > > +$(LIBBPF)-clean: $(LIBBPF_OUTPUT)
> >
> > shouldn't this be `| $(LIBBPF_OUTPUT)` ?
>
> It wouldn't have any effect here. Order-only prerequisites tell make to
> only build the prerequisite before the target, but not to update the
> target if the prerequisite was updated. Because $(LIBBPF)-clean is not a
> file, the recipe is always run and adding the | doesn't make a difference.

I know. I wanted it just for consistency, because everything after |
means "make sure it's completed, but it's not my direct input". But
I'm ok either way, it's not that important. Also $(LIBBPF)-clean and
$(LIBBPF_BOOTSTRAP)-clean should be .PHONY targets, but then again in
practice won't matter, because unlikely that we'll have such files.
Would be nice to follow up with a fix, but I'll apply your patch set
as is.

>
> Thanks,
> Jean
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index f60e6ad3a1df..1358c093b812 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -27,11 +27,13 @@  LIBBPF = $(LIBBPF_PATH)libbpf.a
 
 BPFTOOL_VERSION ?= $(shell make -rR --no-print-directory -sC ../../.. kernelversion)
 
-$(LIBBPF): FORCE
-	$(if $(LIBBPF_OUTPUT),@mkdir -p $(LIBBPF_OUTPUT))
+$(LIBBPF_OUTPUT):
+	$(QUIET_MKDIR)mkdir -p $@
+
+$(LIBBPF): FORCE | $(LIBBPF_OUTPUT)
 	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) $(LIBBPF_OUTPUT)libbpf.a
 
-$(LIBBPF)-clean:
+$(LIBBPF)-clean: $(LIBBPF_OUTPUT)
 	$(call QUIET_CLEAN, libbpf)
 	$(Q)$(MAKE) -C $(BPF_DIR) OUTPUT=$(LIBBPF_OUTPUT) clean >/dev/null