build cmd
zookeeper 3.4.6 使用的是ant,后边儿改用maven了
所以需要先安装ant:参见https://blog.csdn.net/m0_37039484/article/details/80798139
build参考链接:https://cwiki.apache.org/confluence/display/ZOOKEEPER/HowToContribute
我们要执行的命令:
$ cd zookeeper_src_home
#带test太慢了
$ ant -Djavac.args="-Xlint -Xmaxwarns 1000" clean test tar
$ ant -Djavac.args="-Xlint -Xmaxwarns 1000" clean tar
# 还可以直接打包rpm
$ ant -Djavac.args="-Xlint -Xmaxwarns 1000" clean rpm
这个test会执行大量junit test,需要时间挺久的
去掉test,tar包很快就会生成,大概二十多秒的样子吧
详细ant 打包方式参见build.xml中target,特别丰富
build 过程问题解决
1. 替换失效repo
http://repo2.maven.org/maven2 替换成https://repo.hortonworks.com/content/groups/public
build.xml
<!-- <property name="ivy.url"
value="http://repo2.maven.org/maven2/org/apache/ivy/ivy" /> -->
<property name="ivy.url"
value="https://repo.hortonworks.com/content/groups/public/org/apache/ivy/ivy/" />
<!-- <property name="mvnrepo" value="http://repo2.maven.org/maven2"/> -->
<property name="mvnrepo" value="https://repo.hortonworks.com/content/groups/public"/>
Ivysettings.xml
<!-- <property name="repo.maven.org"
value="http://repo1.maven.org/maven2/" override="false"/> -->
<property name="repo.maven.org"
value="https://repo.hortonworks.com/content/groups/public/" override="false"/>
2. error: possibly undefined macro: AM_PATH_CPPUNIT
create-cppunit-configure:
[exec] configure.ac:37: warning: macro 'AM_PATH_CPPUNIT' not found in library
[exec] libtoolize: putting auxiliary files in `.'.
[exec] libtoolize: copying file `./ltmain.sh'
[exec] libtoolize: Consider adding `AC_CONFIG_MACRO_DIR([m4])' to configure.ac and
[exec] libtoolize: rerunning libtoolize, to keep the correct libtool macros in-tree.
[exec] libtoolize: Consider adding `-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
[exec] configure.ac:37: warning: macro 'AM_PATH_CPPUNIT' not found in library
[exec] configure.ac:37: error: possibly undefined macro: AM_PATH_CPPUNIT
[exec] If this token and others are legitimate, please use m4_pattern_allow.
[exec] See the Autoconf documentation.
[exec] autoreconf: /usr/bin/autoconf failed with exit status: 1
BUILD FAILED
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1516: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1475: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1462: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1454: exec returned: 1
报错信息:error: possibly undefined macro: AM_PATH_CPPUNIT
查到是因为缺少cppunit包,所以安装即可
Centos:
yum install cppunit cppunit-devel
Debian/ubuntu
sudo apt-get install libcppunit-dev
3. error: cannot find install-sh, install.sh, or shtool
create-cppunit-configure:
[mkdir] Created dir: /root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build/test/test-cppunit
[exec] checking for doxygen... /usr/bin/doxygen
[exec] checking for perl... /usr/bin/perl
[exec] checking for dot... no
[exec] configure: error: cannot find install-sh, install.sh, or shtool in "/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/src/c" "/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/src/c/.." "/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/src/c/../.."
BUILD FAILED
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1516: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1475: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1467: exec returned: 1
解决办法:
$ yum install doxygen -y
$ yum install perl -y
$ yum install shtool -y
$ yum install graphviz -y
$ yum install cppunit cppunit-devel #这个问题2已经安装了
$ yum install automake #已装
$ yum install autoconf #已装
$ yum install libtool
#
$ cd /root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/src/c
$ autoreconf -i
4. ant rpm报错
当我们直接使用ant rpm
命令打包rpm的时候,会报错如下:
rpm:
[mkdir] Created dir: /tmp/zkpython_build_root/BUILD
[mkdir] Created dir: /tmp/zkpython_build_root/RPMS
[mkdir] Created dir: /tmp/zkpython_build_root/SRPMS
[mkdir] Created dir: /tmp/zkpython_build_root/SOURCES
[mkdir] Created dir: /tmp/zkpython_build_root/SPECS
[copy] Copying 1 file to /tmp/zkpython_build_root/SOURCES
[copy] Copying 1 file to /tmp/zkpython_build_root/SPECS
[rpm] Building the RPM based on the zkpython.spec file
[rpm] + umask 022
[rpm] Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Rp7ccl
[rpm] Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.S4JMA3
[rpm] + cd /tmp/zkpython_build_root/BUILD
[rpm] Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.j1xXZL
[rpm] + tar fxz /tmp/zkpython_build_root/SOURCES/ZooKeeper-0.4.linux-x86_64.tar.gz -C /tmp/zkpython_build_root/BUILD
[rpm] + exit 0
[rpm] + umask 022
[rpm] + cd /tmp/zkpython_build_root/BUILD
[rpm] + exit 0
[rpm] + umask 022
[rpm] + cd /tmp/zkpython_build_root/BUILD
[rpm] + '[' /tmp/zkpython_build_root/BUILD '!=' / ']'
[rpm] + rm -rf /tmp/zkpython_build_root/BUILD
[rpm] ++ dirname /tmp/zkpython_build_root/BUILD
[rpm] + mkdir -p /tmp/zkpython_build_root
[rpm] + mkdir /tmp/zkpython_build_root/BUILD
[rpm] + /usr/lib/rpm/check-buildroot
[rpm] shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] + /usr/lib/rpm/redhat/brp-compress
[rpm] shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] chdir: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] + /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
[rpm] shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] + /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
[rpm] shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] + /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
[rpm] Processing files: zkpython-3.4.6-1.x86_64
[rpm]
[rpm]
[rpm] RPM build errors:
[rpm] shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] + /usr/lib/rpm/brp-python-bytecompile
[rpm] shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
[rpm] error: File not found: /tmp/zkpython_build_root/BUILD/usr
[rpm] File not found: /tmp/zkpython_build_root/BUILD/usr
BUILD FAILED
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/build.xml:1045: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/src/contrib/build.xml:75: The following error occurred while executing this line:
/root/jiazz/hortonworks/zookeeper-release-HDP-3.1.5.1-2-tag/src/contrib/zkpython/build.xml:144: '/usr/bin/rpmbuild' failed with exit code 1
解决办法:
修改相应文件
http://zookeeper-user.578899.n2.nabble.com/Cannot-build-zookeeper-3-4-5-RPM-on-CentOS-6-3-td7578336.html
build.xml
<rpm specFile="zookeeper.spec" command="-ba --buildroot=${package.buildroot}/BUILD" topDir="${package.buildroot}" cleanBuildDir="true" failOnError="true"/>
改成
<rpm specFile="zookeeper.spec" command="-ba" topDir="${package.buildroot}" cleanBuildDir="true" failOnError="true"/>
src/contrib/zkpython/src/packages/rpm/spec/zkpython.spec
# %install 添加%{__mv} %{_build_dir}/* %{buildroot}
%install
%{__mv} %{_build_dir}/* %{buildroot}
src/contrib/zkpython/build.xml
<rpm specFile="${name}.spec" command="-ba --buildroot=${package.buildroot}/BUILD" topDir="${package.buildroot}" cleanBuildDir="true" failOnError="true" />
改成
<rpm specFile="${name}.spec" command="-ba" topDir="${package.buildroot}" cleanBuildDir="true" failOnError="true" />
src/packages/rpm/spec/zookeeper.spec
# 1 Requires
Requires: sh-utils, textutils, /usr/sbin/useradd, /usr/sbin/usermod, /sbin/chkconfig, /sbin/service, jdk >= 1.6
改成
Requires: sh-utils, textutils, /usr/sbin/useradd, /usr/sbin/usermod, /sbin/chkconfig, /sbin/service, java >= 1.6
# 2 %prep
%prep
%setup -D -b 1 -n %{_final_name}
%setup -D -a 0 -n %{_final_name}
改成
%prep
%setup -q -D -b 1 -n %{_final_name}
%setup -q -D -a 0 -n %{_final_name}
# 3 %build
# 删除%build下的这几行
%ifarch amd64 x86_64
mkdir -p ${RPM_BUILD_DIR}%{_lib64_dir}
%endif
# 4 %install
%install
pushd ${RPM_BUILD_DIR}
mv ${RPM_BUILD_DIR}/%{_final_name}/bin/* ${RPM_BUILD_DIR}%{_bin_dir}
mv ${RPM_BUILD_DIR}/%{_final_name}/libexec/* ${RPM_BUILD_DIR}%{_libexec_dir}
mv ${RPM_BUILD_DIR}/%{_final_name}/share/zookeeper/* ${RPM_BUILD_DIR}%{_share_dir}
mv ${RPM_BUILD_DIR}/%{_final_name}/conf/* ${RPM_BUILD_DIR}%{_conf_dir}
mv ${RPM_BUILD_DIR}/%{_final_name}/sbin/* ${RPM_BUILD_DIR}%{_sbin_dir}
cp -f ${RPM_BUILD_DIR}%{_conf_dir}/zoo_sample.cfg ${RPM_BUILD_DIR}%{_conf_dir}/zoo.cfg
popd ${RPM_BUILD_DIR}
rm -rf ${RPM_BUILD_DIR}/%{_final_name}
改成
%install
pushd ${RPM_BUILD_DIR}
cp -a ${RPM_BUILD_DIR}/%{_final_name}/bin/*.sh ${RPM_BUILD_DIR}%{_bin_dir}
cp -a ${RPM_BUILD_DIR}/%{_final_name}/libexec/*.sh ${RPM_BUILD_DIR}%{_libexec_dir}
cp -a ${RPM_BUILD_DIR}/%{_final_name}/share/zookeeper/* ${RPM_BUILD_DIR}%{_share_dir}
cp -a ${RPM_BUILD_DIR}/%{_final_name}/conf/* ${RPM_BUILD_DIR}%{_conf_dir}
cp -a ${RPM_BUILD_DIR}/%{_final_name}/sbin/*.sh ${RPM_BUILD_DIR}%{_sbin_dir}
rm -r ${RPM_BUILD_DIR}/usr/include
rm -r ${RPM_BUILD_DIR}/usr/man
mv etc usr var %{buildroot}
popd ${RPM_BUILD_DIR}
# 5 %files
%files
%defattr(-,root,root)
%attr(0755,root,hadoop) %{_log_dir}
%attr(0775,root,hadoop) %{_pid_dir}
%attr(0775,root,hadoop) /etc/init.d/zookeeper
%config(noreplace) %{_conf_dir}/*
%{_prefix}
改成
%defattr(-,root,root)
%attr(0755,root,hadoop) %{_log_dir}
%attr(0775,root,hadoop) %{_pid_dir}
%attr(0775,root,hadoop) %{_var_dir}
%attr(0775,root,hadoop) /etc/init.d/zookeeper
%dir %{_conf_dir}/
%config(noreplace) %{_conf_dir}/*
%{_libexec_dir}/*
%{_sbin_dir}/*
%{_share_dir}/*
%{_log_dir}/
%{_pid_dir}/
%{_var_dir}/
#6 %files lib
#%{_prefix}/bin --> %{_prefix}/bin/*
%files lib
%defattr(-,root,root)
%{_prefix}/lib/*
%{_prefix}/bin
改成
%files lib
%defattr(-,root,root)
%{_prefix}/lib/*
%{_prefix}/bin/*
我们重新打包rpm:
ant -Djavac.args="-Xlint -Xmaxwarns 1000" clean rpm
很快在build目录下生成rpm
网友评论