Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Ricardo Koller <ricarkol@google.com>
To: kvm@vger.kernel.org
Cc: Andrew Jones <drjones@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Ricardo Koller <ricarkol@google.com>,
	Jim Mattson <jmattson@google.com>,
	Oliver Upton <oupton@google.com>
Subject: [kvm-unit-tests PATCH] Makefile: fix use of PWD in target "all"
Date: Fri, 11 Dec 2020 19:43:31 +0000	[thread overview]
Message-ID: <20201211194331.3830000-1-ricarkol@google.com> (raw)

The "all" target creates the build-head file in the wrong location when
using "make -C" or "sudo make". The reason is that the PWD environment
variable gets the value of the current directory when calling "make -C"
(before the -C changes directories), or is unset in the case of "sudo
make".  Note that the PWD is not changed by the previous "cd $(SRCDIR)".

	/a/b/c $ make -C ../kvm-unit-tests
	=====> creates /a/b/c/build-head

	/a/b/kvm-unit-tests $ sudo make
	=====> creates /build-head
		(note the root)

The consequence of this is that the standalone script can't find the
build-head file:

	/a/b/c $ make -C kvm-unit-tests standalone
	cat: build-head: No such file or directory
	...

	/a/b/kvm-unit-tests $ sudo make standalone
	cat: build-head: No such file or directory
	...

The fix is to not use PWD. "cd $SRCDIR && git rev-parse" is run in a
subshell in order to not break out-of-tree builds, which expect
build-head in the current directory (/a/b/c/build-head below).

Tested:
	out-of-tree build:
	/a/b/c $ ../kvm-unit-tests/configure && make standalone
	
	sudo make:
	/a/b/kvm-unit-tests $ ./configure && sudo make standalone
	
	make -C:
	/a/b/c $ (cd ../kvm-unit-tests && ./configure) && \
				make -C ../kvm-unit-tests standalone

Signed-off-by: Ricardo Koller <ricarkol@google.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
Reviewed-by: Oliver Upton <oupton@google.com>
---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 0e21a49..e0828fe 100644
--- a/Makefile
+++ b/Makefile
@@ -101,7 +101,7 @@ directories:
 
 -include */.*.d */*/.*.d
 
-all: directories $(shell cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD >$(PWD)/build-head 2>/dev/null)
+all: directories $(shell (cd $(SRCDIR) && git rev-parse --verify --short=8 HEAD) >build-head 2>/dev/null)
 
 standalone: all
 	@scripts/mkstandalone.sh
-- 
2.29.2.576.ga3fc446d84-goog


             reply	other threads:[~2020-12-11 21:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 19:43 Ricardo Koller [this message]
2020-12-11 19:58 ` [kvm-unit-tests PATCH] Makefile: fix use of PWD in target "all" Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201211194331.3830000-1-ricarkol@google.com \
    --to=ricarkol@google.com \
    --cc=drjones@redhat.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=oupton@google.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox