Skip to contentSkip to conversation

kbuild: gitignore output directory

PATCH In review Vladimir Kondratiev 4 participants 8 messages Jan 30, 2019 – Mar 25, 2019 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kbuild: gitignore output directory

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 141653226f3c..ee66ea28869b 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
 	$(Q)ln -fsn $(srctree) source
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+	echo "# this is build directory, ignore it\n*" > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
Signature · 1 line
2.19.1
#1 lore raw
Quoted 33 lines · Vladimir Kondratiev

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -1
index 141653226f3c..ee66ea28869b 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
        $(Q)ln -fsn $(srctree) source
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+       echo "# this is build directory, ignore it\n*" > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
--
Quoted 2 lines

2.19.1

The idea looks OK to me.
The implementation must be improved.

You need to add $(Q) to suppress the annoying command echo.

Also, this patch does not work for all distributions because echo "\n"
is not portable.

GNU Make runs recipes in /bin/sh (unless SHELL variable is changed), but the implementation of /bin/sh depends on distributions.

This patch works on Ubuntu etc.
because /bin/sh is a symbolic link to dash.

But, in some distributions,
/bin/sh is a symbolic link to bash.

Docker is useful for quick tests of
various distributions. :)

See the result of echo "hello\nworld"

[Ubuntu]

foo@8ad1275125c5:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.10
DISTRIB_CODENAME=cosmic
DISTRIB_DESCRIPTION="Ubuntu 18.10"
foo@8ad1275125c5:~$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Nov 14 23:00 /bin/sh -> dash
foo@8ad1275125c5:~$ /bin/sh
$ type echo
echo is a shell builtin
$ echo "hello\nworld"
hello
world

[CentOS]

[foo@c3fbaa4b6f72 ~]$ cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [foo@c3fbaa4b6f72 ~]$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Dec 5 01:36 /bin/sh -> bash [foo@c3fbaa4b6f72 ~]$ /bin/sh
sh-4.2$ type echo
echo is a shell builtin
sh-4.2$ echo "hello\nworld"
hello\nworld

On example for workaround might be:

Makefile +1 -1
index ee66ea2..010c1c6 100644
@@ -489,7 +489,7 @@ outputmakefile:
 ifneq ($(KBUILD_SRC),)
        $(Q)ln -fsn $(srctree) source
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
-       echo "# this is build directory, ignore it\n*" > .gitignore
+       $(Q){ echo "# this is build directory, ignore it"; echo "*"; }
Quoted 1 line

.gitignore

endif

ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)

Signature · 2 lines
Best Regards
Masahiro Yamada
#2 lore raw

PATCH v2 1/1 kbuild: gitignore output directory

From: Vladimir Kondratiev <[email protected]>

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 141653226f3c..b1d651e822b1 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
 	$(Q)ln -fsn $(srctree) source
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+	$(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
Signature · 9 lines
2.19.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.
#3 lore raw
Quoted 8 lines · Vladimir Kondratiev

From: Vladimir Kondratiev <[email protected]>

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Quoted 5 lines

Generate .gitignore in output directory that ignores all its content

---

Applied to linux-kbuild.

Thanks.

Quoted 32 lines
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -1
index 141653226f3c..b1d651e822b1 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
        $(Q)ln -fsn $(srctree) source
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+       $(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
--

2.19.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Signature · 2 lines
Best Regards
Masahiro Yamada
#4 lore raw
In reply to Vladimir Kondratiev

Hi,

Quoted 7 lines

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

just found this when testing -rc1.
Unfortunately this breaks my setup, because I keep a totally separate git repository in my build directories to track (various versions of) .config. So .gitignore there is carefully crafted to ignore most build artefacts, but not .config, for instance.

I am not sure how git would interact with the build directory for you? Do you build into a subdirectory of the kernel tree?

I was hoping that we would not overwrite unrelated files in directories outside of the kernel tree. In case this is about a subdirectory of the source tree, can we somehow check for this case?

Cheers,
Andre.

Quoted 27 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -0
index 97ee0be24d52..d487fca342c4 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
 	$(Q)ln -fsn $(srctree) source
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+	$(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
Signature · 1 line
2.17.1
#5 lore raw
Quoted 17 lines · Andre Przywara

Hi,

Quoted 7 lines

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

just found this when testing -rc1.
Unfortunately this breaks my setup, because I keep a totally separate git repository in my build directories to track (various versions of) .config. So .gitignore there is carefully crafted to ignore most build artefacts, but not .config, for instance.

Quoted 6 lines

I am not sure how git would interact with the build directory for you? Do you build into a subdirectory of the kernel tree?

I was hoping that we would not overwrite unrelated files in directories outside of the kernel tree. In case this is about a subdirectory of the source tree, can we somehow check for this case?

I am not sure if it is worthwhile
adjusting the upstream kernel to
the workflow of an individual like this.

If it is, we could like this:

outputmakefile:
ifneq ($(KBUILD_SRC),)

        $(Q)ln -fsn $(srctree) source
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
        $(Q)test -e .gitignore || \
        { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore

endif

Quoted 31 lines

Cheers,
Andre.

Quoted 27 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -1
index 97ee0be24d52..d487fca342c4 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
      $(Q)ln -fsn $(srctree) source
      $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+     $(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
--

2.17.1

Signature · 2 lines
Best Regards
Masahiro Yamada
#6 lore raw

On Sun, 24 Mar 2019 11:22:11 +0900
Masahiro Yamada <[email protected]> wrote:

Hi Masahiro,

Quoted 21 lines · Andre Przywara
Quoted 20 lines

Hi,

Quoted 7 lines

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

just found this when testing -rc1.
Unfortunately this breaks my setup, because I keep a totally separate git repository in my build directories to track (various versions of) .config. So .gitignore there is carefully crafted to ignore most build artefacts, but not .config, for instance.

I am not sure how git would interact with the build directory for you? Do you build into a subdirectory of the kernel tree?

Quoted 8 lines
Quoted 3 lines

I was hoping that we would not overwrite unrelated files in directories outside of the kernel tree. In case this is about a subdirectory of the source tree, can we somehow check for this case?

I am not sure if it is worthwhile
adjusting the upstream kernel to
the workflow of an individual like this.

I would argue that we should not overwrite files in the build directory which are unrelated to the actual kernel *build*.
Another point is that one could easily add the build (sub-)directory to .git/info/exclude to make git ignore it, without touching any git monitored file at all. But I couldn't find an easy way to keep my .gitignore file in place.

Quoted 8 lines

If it is, we could like this:

outputmakefile:
ifneq ($(KBUILD_SRC),)

        $(Q)ln -fsn $(srctree) source
        $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
        $(Q)test -e .gitignore || \
        { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore

Thanks, that looks good and fixes it for me!

Cheers,
Andre.

Quoted 36 lines

endif

Quoted 31 lines

Cheers,
Andre.

Quoted 27 lines
---
 Makefile | 3 +++
 1 file changed, 3 insertions(+)
Makefile +3 -1
index 97ee0be24d52..d487fca342c4 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
 # outputmakefile generates a Makefile in the output directory, if using a
 # separate output directory. This allows convenient use of make in the
 # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
 outputmakefile:
 ifneq ($(KBUILD_SRC),)
      $(Q)ln -fsn $(srctree) source
      $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+     $(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
 endif
 
 ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
--

2.17.1

#7 lore raw
In reply to Masahiro Yamada

Agree; sending v2

Quoted 128 lines · Masahiro Yamada
Quoted 33 lines · Vladimir Kondratiev

When compiling into output directory using O=, many files created under KBUILD_OUTPUT that git considers
as new ones; git clients, ex. "git gui" lists it, and it clutters file list making it difficult to see what was really changed

Generate .gitignore in output directory that ignores all its content

---
  Makefile | 3 +++
  1 file changed, 3 insertions(+)
Makefile +3 -1
index 141653226f3c..ee66ea28869b 100644
@@ -483,10 +483,13 @@ PHONY += outputmakefile
  # outputmakefile generates a Makefile in the output directory, if using a
  # separate output directory. This allows convenient use of make in the
  # output directory.
+# At the same time when output Makefile generated, generate .gitignore to
+# ignore whole output directory
  outputmakefile:
  ifneq ($(KBUILD_SRC),)
         $(Q)ln -fsn $(srctree) source
         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
+       echo "# this is build directory, ignore it\n*" > .gitignore
  endif
 
  ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
--
Quoted 2 lines

2.19.1

The idea looks OK to me.
The implementation must be improved.

You need to add $(Q) to suppress the annoying command echo.

Also, this patch does not work for all distributions because echo "\n"
is not portable.

GNU Make runs recipes in /bin/sh (unless SHELL variable is changed), but the implementation of /bin/sh depends on distributions.

This patch works on Ubuntu etc.
because /bin/sh is a symbolic link to dash.

But, in some distributions,
/bin/sh is a symbolic link to bash.

Docker is useful for quick tests of
various distributions. :)

See the result of echo "hello\nworld"

[Ubuntu]

foo@8ad1275125c5:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.10
DISTRIB_CODENAME=cosmic
DISTRIB_DESCRIPTION="Ubuntu 18.10"
foo@8ad1275125c5:~$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Nov 14 23:00 /bin/sh -> dash
foo@8ad1275125c5:~$ /bin/sh
$ type echo
echo is a shell builtin
$ echo "hello\nworld"
hello
world

[CentOS]

[foo@c3fbaa4b6f72 ~]$ cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [foo@c3fbaa4b6f72 ~]$ ls -l /bin/sh lrwxrwxrwx 1 root root 4 Dec 5 01:36 /bin/sh -> bash [foo@c3fbaa4b6f72 ~]$ /bin/sh
sh-4.2$ type echo
echo is a shell builtin
sh-4.2$ echo "hello\nworld"
hello\nworld

On example for workaround might be:

Makefile +1 -1
index ee66ea2..010c1c6 100644
@@ -489,7 +489,7 @@ outputmakefile:
  ifneq ($(KBUILD_SRC),)
         $(Q)ln -fsn $(srctree) source
         $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
-       echo "# this is build directory, ignore it\n*" > .gitignore
+       $(Q){ echo "# this is build directory, ignore it"; echo "*"; }
Quoted 1 line

.gitignore

endif

  ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)