From 2e51cd891a09b642d81f49ff47ad0b66ee89bd72 Mon Sep 17 00:00:00 2001 From: laura-ding <48548375+laura-ding@users.noreply.github.com> Date: Mon, 22 Jul 2019 09:49:57 +0800 Subject: [PATCH] Display version and modify the packaging script (#639) * Display version and modify the packaging script * Fix error msg --- CMakeLists.txt | 4 ++ package/make_srpm.sh | 4 +- package/nebula.spec | 102 +++++++++++---------------------- src/common/base/Base.cpp | 15 +++-- src/common/hdfs/CMakeLists.txt | 2 +- src/console/CliManager.cpp | 7 ++- src/meta/client/MetaClient.cpp | 2 + 7 files changed, 58 insertions(+), 78 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f969b811c2..064660b7a86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,6 +95,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "_build") set(NEBULA_HOME ${CMAKE_CURRENT_SOURCE_DIR}) add_definitions(-DNEBULA_HOME=${NEBULA_HOME}) +if (NEBULA_BUILD_VERSION) + add_definitions(-DNEBULA_BUILD_VERSION=${NEBULA_BUILD_VERSION}) +endif() + find_package(Git) if (GIT_FOUND AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") execute_process( diff --git a/package/make_srpm.sh b/package/make_srpm.sh index f137854bc64..c0c4927f718 100755 --- a/package/make_srpm.sh +++ b/package/make_srpm.sh @@ -55,7 +55,7 @@ echo "current version is [ $rpm_version ], release is [$rpm_release]" echo "current rpmbuild is [ $rpmbuilddir ]" # because of use the static third-party lib, the rpmbuild can't check the file in rpm packet, so change the check to warnning -sudo sed -i "s/_unpackaged_files_terminate_build.*/_unpackaged_files_terminate_build 0/g" /usr/lib/rpm/macros +sudo sed -i 's/^%__check_files/#&/' /usr/lib/rpm/macros # modify nebula.spec's version sed -i "s/@VERSION@/$rpm_version/g" nebula.spec @@ -65,4 +65,6 @@ sed -i "s/@RELEASE@/$rpm_release/g" nebula.spec rpmbuild -D"_topdir $rpmbuilddir" -D"_bindir $bindir" \ -D"_datadir $datadir" -D"_sysconfdir $sysconfdir" \ -D"_sharedir $sharedir" -D"_resourcesdir $resourcesdir" \ + -D"_version $rpm_version" -D"_release $rpm_release" \ + -D"_install_dir $prefix" \ -ba nebula.spec diff --git a/package/nebula.spec b/package/nebula.spec index 4bfcb1049d8..8ddf3d617ea 100755 --- a/package/nebula.spec +++ b/package/nebula.spec @@ -6,60 +6,51 @@ %global project_name nebula Name: %{project_name} -Version: @VERSION@ -Release: @RELEASE@%{?dist} +Version: %{_version} +Release: %{_release}%{?dist} Summary: %{project_name} License: Apache 2.0 + Common Clause 1.0 -# the url to get tar.gz -#URL: http:// -# tar name, this is a temp name -Source: %{project_name}-@VERSION@.tar.gz # BuildRoot dir BuildRoot:%(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX) # TODO: we should check dependence's version after adapt to different system versions -BuildRequires: gcc, gcc-c++ -BuildRequires: libstdc++-static -BuildRequires: cmake BuildRequires: make BuildRequires: autoconf BuildRequires: automake -BuildRequires: flex -BuildRequires: gperf BuildRequires: libtool BuildRequires: bison BuildRequires: unzip -BuildRequires: boost -BuildRequires: boost-devel -BuildRequires: boost-static -BuildRequires: openssl -BuildRequires: openssl-devel -BuildRequires: libunwind -BuildRequires: libunwind-devel +BuildRequires: readline BuildRequires: ncurses BuildRequires: ncurses-devel -BuildRequires: readline -BuildRequires: readline-devel BuildRequires: python BuildRequires: java-1.8.0-openjdk BuildRequires: java-1.8.0-openjdk-devel -#Requires: krb5 %description A high performance distributed graph database %prep -%setup -q %build -cmake ./ +cmake -DCMAKE_BUILD_TYPE=Release -DNEBULA_BUILD_VERSION=%{_version} -DCMAKE_INSTALL_PREFIX=%{_install_dir} ./ make -j2 %install rm -rf %{buildroot} make install DESTDIR=%{buildroot} +# After install, if config file is non-existent, copy default config file +%post +daemons=(metad graphd storaged) +for daemon in ${daemons[@]} +do + if [[ ! -f %{_install_dir}/etc/nebula-${daemon}.conf ]]; then + cp %{_install_dir}/etc/nebula-${daemon}.conf.default %{_install_dir}/etc/nebula-${daemon}.conf + fi +done + %package metad Summary: nebula meta server daemon Group: Applications/Databases @@ -92,64 +83,30 @@ Group: Applications/Databases # the files include exe, config file, scripts # base rpm include files %files -%{_datadir}/nebula.service -%{_datadir}/utils.sh +%attr(0755,root,root) %{_datadir}/nebula.service +%attr(0755,root,root) %{_datadir}/utils.sh # metad rpm include files %files metad -%defattr(-,root,root,-) -%{_bindir}/nebula-metad -%{_sysconfdir}/nebula-metad.conf.default -%{_datadir}/nebula-metad.service - -# after install , arg 1:install new packet, arg 2: update exist packet -#%%post metad -#%%systemd_post nebula-metad.service - -# before uninstall, arg 0:delete arg 1:update -#%%preun metad -#%%systemd_preun nebula-metad.service - -# upgrade, arg 0:delete arg 1:update -#%%postun metad -#%%systemd_postun nebula-metad.service +%attr(0755,root,root) %{_bindir}/nebula-metad +%attr(0644,root,root) %{_sysconfdir}/nebula-metad.conf.default +%attr(0755,root,root) %{_datadir}/nebula-metad.service # graphd rpm include files %files graphd -%defattr(-,root,root,-) -%{_bindir}/nebula-graphd -%config%{_sysconfdir}/nebula-graphd.conf.default -%{_datadir}/nebula-graphd.service - -#%%post graphd -#%%systemd_post nebula-graphd.service - -#%%preun graphd -#%%systemd_preun nebula-graphd.service - -#%%postun graphd -#%%systemd_postun nebula-graphd.service +%attr(0755,root,root) %{_bindir}/nebula-graphd +%attr(0644,root,root) %config%{_sysconfdir}/nebula-graphd.conf.default +%attr(0755,root,root) %{_datadir}/nebula-graphd.service # storaged rpm include files %files storaged -%defattr(-,root,root,-) -%{_bindir}/nebula-storaged -%config%{_sysconfdir}/nebula-storaged.conf.default -%{_datadir}/nebula-storaged.service - -#%%post storaged -#%%systemd_post nebula-storaged.service - -#%%preun storaged -#%%systemd_preun nebula-storaged.service - -#%%postun storaged -#%%systemd_postun nebula-storaged.service +%attr(0755,root,root) %{_bindir}/nebula-storaged +%attr(0644,root,root) %config%{_sysconfdir}/nebula-storaged.conf.default +%attr(0755,root,root) %{_datadir}/nebula-storaged.service %files nebula -%defattr(-,root,root,-) -%{_bindir}/nebula -%{_resourcesdir}/completion.json +%attr(0755,root,root) %{_bindir}/nebula +%attr(0644,root,root) %{_resourcesdir}/completion.json # storage_perf rpm @@ -157,5 +114,10 @@ Group: Applications/Databases #%%defattr(-,root,root,-) #%%{_bindir}/storage_perf +%debug_package + +# missing third-part ids +%undefine _missing_build_ids_terminate_build + %changelog diff --git a/src/common/base/Base.cpp b/src/common/base/Base.cpp index 79a2d0de683..359e53c0d2f 100644 --- a/src/common/base/Base.cpp +++ b/src/common/base/Base.cpp @@ -21,13 +21,18 @@ std::ostream& operator <<(std::ostream &os, const HostAddr &addr) { std::string versionString() { + std::string version; +#if defined(NEBULA_BUILD_VERSION) + version = folly::stringPrintf("%s, ", NEBULA_STRINGIFY(NEBULA_BUILD_VERSION)); +#endif + #if defined(GIT_INFO_SHA) - return folly::stringPrintf("Git: %s, Build Time: %s %s", - NEBULA_STRINGIFY(GIT_INFO_SHA), - __DATE__, __TIME__); -#else - return folly::stringPrintf("Build Time: %s %s", __DATE__, __TIME__); + version += folly::stringPrintf("Git: %s", NEBULA_STRINGIFY(GIT_INFO_SHA)); #endif + version += folly::stringPrintf(", Build Time: %s %s", __DATE__, __TIME__); + version += "\nThis source code is licensed under Apache 2.0 License," + " attached with Common Clause Condition 1.0."; + return version; } } // namespace nebula diff --git a/src/common/hdfs/CMakeLists.txt b/src/common/hdfs/CMakeLists.txt index 1d362b3adc9..d88941cc36b 100644 --- a/src/common/hdfs/CMakeLists.txt +++ b/src/common/hdfs/CMakeLists.txt @@ -1,5 +1,5 @@ add_library(hdfs_helper_obj OBJECT HdfsCommandHelper.cpp) -add_dependencies(process_obj fs_obj base_obj) +add_dependencies(hdfs_helper_obj fs_obj base_obj) add_subdirectory(test) diff --git a/src/console/CliManager.cpp b/src/console/CliManager.cpp index b0875901868..88f2cc6a6c7 100644 --- a/src/console/CliManager.cpp +++ b/src/console/CliManager.cpp @@ -107,7 +107,12 @@ bool CliManager::connect(const std::string& addr, auto client = std::make_unique(addr_, port_); cpp2::ErrorCode res = client->connect(user, pass); if (res == cpp2::ErrorCode::SUCCEEDED) { - std::cerr << "\nWelcome to Nebula Graph (Version 0.1)\n\n"; +#if defined(NEBULA_BUILD_VERSION) + std::cerr << "\nWelcome to Nebula Graph (Version " + << NEBULA_STRINGIFY(NEBULA_BUILD_VERSION) << ")\n\n"; +#else + std::cerr << "\nWelcome to Nebula Graph\n\n"; +#endif cmdProcessor_ = std::make_unique(std::move(client)); return true; } else { diff --git a/src/meta/client/MetaClient.cpp b/src/meta/client/MetaClient.cpp index ad7f09e0927..a053303fd34 100644 --- a/src/meta/client/MetaClient.cpp +++ b/src/meta/client/MetaClient.cpp @@ -307,6 +307,8 @@ Status MetaClient::handleResponse(const RESP& resp) { return Status::Error("existed!"); case cpp2::ErrorCode::E_NOT_FOUND: return Status::Error("not existed!"); + case cpp2::ErrorCode::E_NO_HOSTS: + return Status::Error("no hosts!"); case cpp2::ErrorCode::E_LEADER_CHANGED: { HostAddr leader(resp.get_leader().get_ip(), resp.get_leader().get_port()); {