Bug 14509

Summary: bug in make(1)
Product: Base System Reporter: Archie Cobbs <archie>
Component: binAssignee: Martin Cracauer <cracauer>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.1-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
sh.diff none

Description Archie Cobbs 1999-10-25 04:50:01 UTC
	Make is incorrectly executing a shell command. Consider this
	makefile:

	foo1:
		var1=yes; test "$$var1" = "no" && var2=". $$var2"; echo OK

	The makefile should exit successfully, yet instead it bombs out.
	Removing the "var1=yes" should have no effect, but that seems
	to fix it (see foo2 below).

Fix: 

Uknown.
How-To-Repeat: 
	$ cat makefile
	foo1:
		var1=yes; test "$$var1" = "no" && var2=". $$var2"; echo OK
	foo2:
		test "$$var1" = "no" && var2=". $$var2"; echo OK
	$ make foo1
	var1=yes; test "$var1" = "no" && var2=". $var2"; echo OK
	*** Error code 1

	Stop.
	$ make foo2
	test "$var1" = "no" && var2=". $var2"; echo OK
	OK
Comment 1 Ruslan Ermilov 1999-10-25 08:08:43 UTC
On Sun, Oct 24, 1999 at 08:44:41PM -0700, Archie Cobbs wrote:
> 
> >How-To-Repeat:
> 
> 	$ cat makefile
> 	foo1:
> 		var1=yes; test "$$var1" = "no" && var2=". $$var2"; echo OK
> 	foo2:
> 		test "$$var1" = "no" && var2=". $$var2"; echo OK
> 	$ make foo1
> 	var1=yes; test "$var1" = "no" && var2=". $var2"; echo OK
> 	*** Error code 1
> 
> 	Stop.
> 	$ make foo2
> 	test "$var1" = "no" && var2=". $var2"; echo OK
> 	OK
> 
Certainly, there is a problem somewhere above, but the following makefiles
work as expected:

# cat ~/Makefile.1
foo1:
	var1=yes; test "$$var1" = "no" && var2=". $$var2" || :; echo OK

foo2:
	test "$$var1" = "no" && var2=". $$var2" || :; echo OK

# cat ~/Makefile.2
foo1:
	var1=yes; if test "$$var1" = "no"; then var2=". $$var2"; fi; echo OK

foo2:
	if test "$$var1" = "no"; then var2=". $$var2"; fi; echo OK


Cheers,
-- 
Ruslan Ermilov		Sysadmin and DBA of the
ru@ucb.crimea.ua	United Commercial Bank,
ru@FreeBSD.org		FreeBSD committer,
+380.652.247.647	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 2 Ruslan Ermilov 1999-10-25 09:15:31 UTC
Hi!

It turns out to be a sh(1) bug:

$ sh -e -c 'test "yes" = "no" && :; echo OK'; echo $?
OK
0
$ sh -e -c ':; test "yes" = "no" && :; echo OK'; echo $?
1

Here is what sh(1) manpage says about `-e' option:
:
:-e errexit
:        If not interactive, exit immediately if any untested command
:        fails.  The exit status of a command is considered to be explicitly
:        tested if the command is used to control an if, elif, while,
:        or until; or if the command is the left hand operand of an ``&&''
:        or ``||'' operator.


On Mon, Oct 25, 1999 at 10:08:43AM +0300, Ruslan Ermilov wrote:
> On Sun, Oct 24, 1999 at 08:44:41PM -0700, Archie Cobbs wrote:
> > 
> > >How-To-Repeat:
> > 
> > 	$ cat makefile
> > 	foo1:
> > 		var1=yes; test "$$var1" = "no" && var2=". $$var2"; echo OK
> > 	foo2:
> > 		test "$$var1" = "no" && var2=". $$var2"; echo OK
> > 	$ make foo1
> > 	var1=yes; test "$var1" = "no" && var2=". $var2"; echo OK
> > 	*** Error code 1
> > 
> > 	Stop.
> > 	$ make foo2
> > 	test "$var1" = "no" && var2=". $var2"; echo OK
> > 	OK
> > 
> Certainly, there is a problem somewhere above, but the following makefiles
> work as expected:
> 
> # cat ~/Makefile.1
> foo1:
> 	var1=yes; test "$$var1" = "no" && var2=". $$var2" || :; echo OK
> 
> foo2:
> 	test "$$var1" = "no" && var2=". $$var2" || :; echo OK
> 
> # cat ~/Makefile.2
> foo1:
> 	var1=yes; if test "$$var1" = "no"; then var2=". $$var2"; fi; echo OK
> 
> foo2:
> 	if test "$$var1" = "no"; then var2=". $$var2"; fi; echo OK
> 

-- 
Ruslan Ermilov		Sysadmin and DBA of the
ru@ucb.crimea.ua	United Commercial Bank,
ru@FreeBSD.org		FreeBSD committer,
+380.652.247.647	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 3 Sheldon Hearn freebsd_committer freebsd_triage 1999-10-25 10:54:07 UTC
Responsible Changed
From-To: freebsd-bugs->cracauer

I thought I'd seen this problem with sh(1) fixed. I'm sure 
Martin will be interested. 

Comment 4 Martin Cracauer 1999-10-25 11:55:45 UTC
Could you please test the appended diff?

There are possibly other types of nodes that must be excluded from
exiting, but this seems to be the most urgent.

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
  Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536
Comment 5 Ruslan Ermilov 1999-10-25 12:27:06 UTC
On Mon, Oct 25, 1999 at 12:55:45PM +0200, Martin Cracauer wrote:
> Could you please test the appended diff?
> 
> There are possibly other types of nodes that must be excluded from
> exiting, but this seems to be the most urgent.
> 
Yup, it works now!

-- 
Ruslan Ermilov		Sysadmin and DBA of the
ru@ucb.crimea.ua	United Commercial Bank,
ru@FreeBSD.org		FreeBSD committer,
+380.652.247.647	Simferopol, Ukraine

http://www.FreeBSD.org	The Power To Serve
http://www.oracle.com	Enabling The Information Age
Comment 6 Martin Cracauer freebsd_committer freebsd_triage 1999-10-26 15:20:02 UTC
State Changed
From-To: open->closed

Diff I sent for testing committed to -current. Will be in -stable after 
some time.