src/backend/Makefile CDPATH Patch

Started by Jason Tishlerover 25 years ago7 messagespatches
Jump to latest
#1Jason Tishler
Jason.Tishler@dothill.com

The attached patch solves an annoying build failure when /bin/sh is a
symlink to /bin/bash and CDPATH is set. The problem manifests itself as
the following error:

$ cd src/backend
$ make ../../src/include/parser/parse.h
prereqdir=`cd parser/ && pwd` && \
cd ../../src/include/parser/ && rm -f parse.h && \
ln -s $prereqdir/parse.h .
ln: ./parser: File exists
make: *** [../../src/include/parser/parse.h] Error 1
make: *** Deleting file `../../src/include/parser/parse.h'

The above is due to the following:

$ export CDPATH=.:/home/jt:/home/jt/src:/home/jt/lib
$ echo `cd parser/ && pwd`
/home/jt/src/pgsql/src/backend/parser /home/jt/src/pgsql/src/backend/parser

Hence, prereqdir is actually getting set to two directory names instead
of one which causes ln to fail.

If CDPATH is not set (or set differently) or /bin/sh is not /bin/bash,
then we get the expected behavior:

$ unset CDPATH
$ echo `cd parser/ && pwd`
/home/jt/src/pgsql/src/backend/parser

The the solution used in the patch is as follows:

$ export CDPATH=.:/home/jt:/home/jt/src:/home/jt/lib
$ echo `cd parser/ >/dev/null && pwd`
/home/jt/src/pgsql/src/backend/parser

Note that there are many solutions -- I just chose the one that perturbed
the Makefile the least.

Jason

--
Jason Tishler
Director, Software Engineering Phone: +1 (732) 264-8770 x235
Dot Hill Systems Corp. Fax: +1 (732) 264-8798
82 Bethany Road, Suite 7 Email: Jason.Tishler@dothill.com
Hazlet, NJ 07730 USA WWW: http://www.dothill.com

Attachments:

backend.patchtext/plain; charset=us-asciiDownload+1-1
#2Bruce Momjian
bruce@momjian.us
In reply to: Jason Tishler (#1)
Re: src/backend/Makefile CDPATH Patch

The above is due to the following:

$ export CDPATH=.:/home/jt:/home/jt/src:/home/jt/lib
$ echo `cd parser/ && pwd`
/home/jt/src/pgsql/src/backend/parser /home/jt/src/pgsql/src/backend/parser

Basically, you are telling me that if there are two matching parser
directories, pwd gets set to _both_ of them. Sorry, I don't think we
want to work around a bug like that, so we?

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#3Jason Tishler
Jason.Tishler@dothill.com
In reply to: Bruce Momjian (#2)
Re: src/backend/Makefile CDPATH Patch

Bruce,

On Mon, Apr 23, 2001 at 03:25:38PM -0400, Bruce Momjian wrote:

The above is due to the following:

$ export CDPATH=.:/home/jt:/home/jt/src:/home/jt/lib
$ echo `cd parser/ && pwd`
/home/jt/src/pgsql/src/backend/parser /home/jt/src/pgsql/src/backend/parser

Basically, you are telling me that if there are two matching parser
directories, pwd gets set to _both_ of them. Sorry, I don't think we
want to work around a bug like that, should we?

I guess that I was not explicit enough, so I will try again...

The extra directory name comes from bash's builtin cd echoing the
directory name when a match is found in the user's CDPATH. It is *not*
coming from pwd.

So, I still content that this is a bug in the Makefile. The construct
that is suspect is the following:

prereqdir=`cd $(dir $<) && pwd`

The above implicitly assumes that the "cd $(dir $<)" part does *not*
write to stdout. If it does then, prereqdir will end up as the
concatenation of "cd $(dir $<)" and "pwd".

Under bash, I get the following:

$ prereqdir=`cd parser/ && pwd`
$ echo "$prereqdir"
/home/jt/src/pgsql/src/backend/parser
/home/jt/src/pgsql/src/backend/parser

Under sh, I get the following:

$ prereqdir=`cd parser/ && pwd`
$ echo "$prereqdir"
/home/jt/src/pgsql/src/backend/parser

Hence, when the PostgreSQL build is run (where sh == bash), the ln
command generated by the Makefile:

ln -s $prereqdir/parse.h .

becomes the following:

ln -s /home/jt/src/pgsql/src/backend/parser # *** new line here ***
/home/jt/src/pgsql/src/backend/parser/parse.h .

which confuses ln and causes the make to fail.

Note this problem only occurs on our Red Hat Linux boxes because /bin/sh
is a symlink to /bin/bash. We do not have this problem under Cygwin or
Solaris.

Thanks,
Jason

--
Jason Tishler
Director, Software Engineering Phone: +1 (732) 264-8770 x235
Dot Hill Systems Corp. Fax: +1 (732) 264-8798
82 Bethany Road, Suite 7 Email: Jason.Tishler@dothill.com
Hazlet, NJ 07730 USA WWW: http://www.dothill.com

#4Bruce Momjian
bruce@momjian.us
In reply to: Jason Tishler (#3)
Re: src/backend/Makefile CDPATH Patch

Bruce,

On Mon, Apr 23, 2001 at 03:25:38PM -0400, Bruce Momjian wrote:

The above is due to the following:

$ export CDPATH=.:/home/jt:/home/jt/src:/home/jt/lib
$ echo `cd parser/ && pwd`
/home/jt/src/pgsql/src/backend/parser /home/jt/src/pgsql/src/backend/parser

Basically, you are telling me that if there are two matching parser
directories, pwd gets set to _both_ of them. Sorry, I don't think we
want to work around a bug like that, should we?

I guess that I was not explicit enough, so I will try again...

The extra directory name comes from bash's builtin cd echoing the
directory name when a match is found in the user's CDPATH. It is *not*
coming from pwd.

Oh, I understand now. Good point.

So, I still content that this is a bug in the Makefile. The construct
that is suspect is the following:

prereqdir=`cd $(dir $<) && pwd`

Yep, I can see it doing that.

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
#5Peter Eisentraut
peter_e@gmx.net
In reply to: Jason Tishler (#1)
Re: src/backend/Makefile CDPATH Patch

Jason Tishler writes:

The attached patch solves an annoying build failure when /bin/sh is a
symlink to /bin/bash and CDPATH is set.

Installed.

--
Peter Eisentraut peter_e@gmx.net http://funkturm.homeip.net/~peter

#6Jason Tishler
Jason.Tishler@dothill.com
In reply to: Peter Eisentraut (#5)
Re: src/backend/Makefile CDPATH Patch

Peter,

On Mon, Apr 23, 2001 at 10:39:45PM +0200, Peter Eisentraut wrote:

Jason Tishler writes:

The attached patch solves an annoying build failure when /bin/sh is a
symlink to /bin/bash and CDPATH is set.

Installed.

Thanks.

Jason

--
Jason Tishler
Director, Software Engineering Phone: +1 (732) 264-8770 x235
Dot Hill Systems Corp. Fax: +1 (732) 264-8798
82 Bethany Road, Suite 7 Email: Jason.Tishler@dothill.com
Hazlet, NJ 07730 USA WWW: http://www.dothill.com

#7Ross J. Reedstrom
reedstrm@rice.edu
In reply to: Bruce Momjian (#2)
Re: src/backend/Makefile CDPATH Patch

On Mon, Apr 23, 2001 at 03:25:38PM -0400, Bruce Momjian wrote:

The above is due to the following:

$ export CDPATH=.:/home/jt:/home/jt/src:/home/jt/lib
$ echo `cd parser/ && pwd`
/home/jt/src/pgsql/src/backend/parser /home/jt/src/pgsql/src/backend/parser

Basically, you are telling me that if there are two matching parser
directories, pwd gets set to _both_ of them. Sorry, I don't think we
want to work around a bug like that, so we?

No, he's saying that bash is verbose when CDPATH is set, letting you
know what directory it's actually cding to when the CDPATH is used.
Apparently, this is not the sh behavior, so his patch silences the
spurious output from cd.

Ross