编译软件时可以采取哪些步骤来确保健全的构建环境?

Chr*_*ams 1 bash centos ruby

我在 CentOS 机器上编译一个软件时遇到了困难,下面列出的问题是具体的,但我希望由此得出的正确方法可以应用于类似的问题,因为这似乎不是这个软件特有的问题。不过进入正题...

在 CentOS 5.4 上构建标准化虚拟机时,我一直遇到编译问题,并且我对 a)为什么会发生此错误以及 b)如何修复它一无所知,并希望其他人也偶然发现了这个问题,我希望有人可以帮助我在这里找到解决方案。

当我尝试运行安装程序时,我在尝试编译 Ruby Enterprise 时遇到configure: error: newly created file is older than distributed files!错误,如下所示,并且论坛上提供的解决方案(检查齿,并触摸文件以更新与它们相关的时间)不会似乎没有在这里帮忙。

我可以采取哪些步骤来找出此问题的原因?

[vagrant@vagrant-centos-5 ruby-enterprise-1.8.7-2009.10]$ sudo ./installer
Welcome to the Ruby Enterprise Edition installer
This installer will help you install Ruby Enterprise Edition 1.8.7-2009.10.
Don't worry, none of your system files will be touched if you don't want them
to, so there is no risk that things will screw up.

You can expect this from the installation process:

  1. Ruby Enterprise Edition will be compiled and optimized for speed for this
     system.
  2. Ruby on Rails will be installed for Ruby Enterprise Edition.
  3. You will learn how to tell Phusion Passenger to use Ruby Enterprise
     Edition instead of regular Ruby.

Press Enter to continue, or Ctrl-C to abort.

Checking for required software...

 * C compiler... found at /usr/bin/gcc
 * C++ compiler... found at /usr/bin/g++
 * The 'make' tool... found at /usr/bin/make
 * Zlib development headers... found
 * OpenSSL development headers... found
 * GNU Readline development headers... found
--------------------------------------------
Target directory

Where would you like to install Ruby Enterprise Edition to?
(All Ruby Enterprise Edition files will be put inside that directory.)

[/opt/ruby-enterprise] : 
--------------------------------------------
Compiling and optimizing the memory allocator for Ruby Enterprise Edition
In the mean time, feel free to grab a cup of coffee.

./configure --prefix=/opt/ruby-enterprise --disable-dependency-tracking
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... configure: error: newly created file is older than distributed files!
Check your system clock
Run Code Online (Sandbox Code Playgroud)

这是在virtualbox上运行的虚拟机,主机和虚拟机的时间是相同的,并且是最新的。我也尝试过使用 ntp 客户端更新时间后运行此命令,但没有效果。在阅读了有人遇到类似问题的这篇文章后,我尝试了这个

[vagrant@vagrant-centos-5 ruby-enterprise-1.8.7-2009.10]$ date
Tue Apr 27 08:09:05 BST 2010 
Run Code Online (Sandbox Code Playgroud)

我尝试过的另一种方法是像此处建议的那样触摸构建文件夹中的顶层文件,但这也不起作用(说实话,我不确定为什么它会起作用)

[vagrant@vagrant-centos-5 ruby-enterprise-1.8.7-2009.10]$ sudo touch ruby-enterprise-1.8.7-2009.10/*
Run Code Online (Sandbox Code Playgroud)

我不确定接下来可以做什么 - 问题似乎是返回此错误的 bash 配置脚本error: newly created file is older than distributed files!,位于第 2214 行

{ echo "$as_me:$LINENO: checking whether build environment is sane" >&5
echo $ECHO_N "checking whether build environment is sane... $ECHO_C" >&6; }
# Just in case
sleep 1
echo timestamp > conftest.file
# Do `set' in a subshell so we don't clobber the current shell's
# arguments.  Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
   set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
   if test "$*" = "X"; then
      # -L didn't work.
      set X `ls -t $srcdir/configure conftest.file`
   fi
   rm -f conftest.file
   if test "$*" != "X $srcdir/configure conftest.file" \
      && test "$*" != "X conftest.file $srcdir/configure"; then

      # If neither matched, then we have a broken ls.  This can happen
      # if, for instance, CONFIG_SHELL is bash and it inherits a
      # broken ls alias from the environment.  This has actually
      # happened.  Such a system could not be considered "sane".
      { { echo "$as_me:$LINENO: error: ls -t appears to fail.  Make sure there is not a broken
alias in your environment" >&5
echo "$as_me: error: ls -t appears to fail.  Make sure there is not a broken
alias in your environment" >&2;}
   { (exit 1); exit 1; }; }
   fi
   ### PROBLEM LINE ####
   # this line is the problem line - this is returned true, sometimes it isn't and I can't 
   # see a pattern that that determines when this will test will pass or not.
   test "$2" = conftest.file
   )
then
   # Ok.
   :
else
   { { echo "$as_me:$LINENO: error: newly created file is older than distributed files!
Check your system clock" >&5
echo "$as_me: error: newly created file is older than distributed files!
Check your system clock" >&2;}
   { (exit 1); exit 1; }; }
fi
Run Code Online (Sandbox Code Playgroud)

真正令人沮丧的是,该脚本有时会起作用,当虚拟机运行一个小时左右时,它会起作用,但在启动时不起作用。我在 crontab 中没有看到任何表明运行的每小时任务可能会改变系统状态,足以对该脚本的工作产生影响。

当谈到这里之外的调试时,我完全不知所措。这里最好采取什么方法?

谢谢

小智 5

配置 shell 脚本中的“日期健全性检查”对我来说看起来很无聊,它需要修复。看这个:

echo timestamp > conftest.file
# Do `set' in a subshell so we don't clobber the current shell's
# arguments.  Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
   set X `ls -Lt $srcdir/configure conftest.file 2> /dev/null`
   if test "$*" = "X"; then
      # -L didn't work.
      set X `ls -t $srcdir/configure conftest.file`
   fi
   rm -f conftest.file
   if test "$*" != "X $srcdir/configure conftest.file" \
      && test "$*" != "X conftest.file $srcdir/configure"; then
Run Code Online (Sandbox Code Playgroud)

所以它接触一个文件,然后尝试找出它的 mtime 是否比文件的 mtime 新$srcdir/configure,并且是通过调用ls然后将输出与固定字符串进行比较来实现的。作者写道

  # If neither matched, then we have a broken ls.  This can happen
  # if, for instance, CONFIG_SHELL is bash and it inherits a
  # broken ls alias from the environment.  This has actually
  # happened.  Such a system could not be considered "sane".
Run Code Online (Sandbox Code Playgroud)

但我认为那是垃圾。有太多的版本/风格ls和方法来改变ls输出(他们甚至命名了一个)来确定ls输出格式。

不管怎样,还有更优雅的方法可以做到这一点。例如在 bash 中(参见help test):

if [ $FILE1 -nt $FILE2 ] ; then
    echo "$FILE1 is newer than $FILE2"
elif [ $FILE2 -nt $FILE1 ] ; then
    echo "$FILE2 is newer than $FILE1"
else
    echo "$FILE1 and $FILE2 are equally new"
fi
Run Code Online (Sandbox Code Playgroud)

或者找到某个mtime是否是将来的时间!

find -L $FILE -newermt now -exec echo THE FILE {} IS COMING FROM THE FUTURE \;
Run Code Online (Sandbox Code Playgroud)

或者

find -L $FILE -mtime -0 -exec echo THE FILE {} IS COMING FROM THE PRESENT OR THE FUTURE \;
Run Code Online (Sandbox Code Playgroud)

现在自己编写补丁:-)

  • 您应该以“创建补丁很简单,留给读者作为练习”结束;) (2认同)