Skip to content

Commit

Permalink
Implement scheme to more clever pass the directories from the build p…
Browse files Browse the repository at this point in the history
…rocess to the run-time

We will now try to evaluate the toplevel install directory from the configured binary dir.
We will use this toplever directory when searching for other directories.
  • Loading branch information
dothebart committed Aug 24, 2016
1 parent 71db758 commit 1f162ac
Show file tree
Hide file tree
Showing 20 changed files with 159 additions and 36 deletions.
2 changes: 2 additions & 0 deletions 3rdParty/V8/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@ if (WIN32)
DESTINATION "bin/share/arangodb/"
RENAME ${ICU_DT_DEST})
else()
# other platforms don't install ICU:
set(ICU_DT_DEST "" PARENT_SCOPE)
add_custom_target(nonthinV8
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/../../Installation/archive-de-thinner.sh ${V8_REL_TARGET_PATH}
COMMENT de-thins V8 .a files)
Expand Down
10 changes: 10 additions & 0 deletions arangod/RestServer/DatabaseFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "DatabaseFeature.h"

#include "Basics/StringUtils.h"
#include "Basics/ArangoGlobalContext.h"
#include "Cluster/ServerState.h"
#include "Cluster/v8-cluster.h"
#include "GeneralServer/GeneralServerFeature.h"
Expand Down Expand Up @@ -129,6 +130,15 @@ void DatabaseFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
// strip trailing separators
_databasePath = StringUtils::rTrim(_directory, TRI_DIR_SEPARATOR_STR);

auto ctx = ArangoGlobalContext::CONTEXT;

if (ctx == nullptr) {
LOG(ERR) << "failed to get global context. ";
FATAL_ERROR_EXIT();
}

ctx->getCheckPath(_databasePath, "database.directory");

if (_maximalJournalSize < TRI_JOURNAL_MINIMAL_SIZE) {
LOG(FATAL) << "invalid value for '--database.maximal-journal-size'. "
"expected at least "
Expand Down
3 changes: 2 additions & 1 deletion arangod/RestServer/arangod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"
#include "Basics/tri-strings.h"

#include "Actions/ActionFeature.h"
Expand Down Expand Up @@ -80,7 +81,7 @@ using namespace arangodb;
using namespace arangodb::wal;

static int runServer(int argc, char** argv) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, SBIN_DIRECTORY);
context.installSegv();
context.runStartupChecks();

Expand Down
12 changes: 12 additions & 0 deletions arangod/V8Server/V8DealerFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "Basics/ConditionLocker.h"
#include "Basics/StringUtils.h"
#include "Basics/WorkMonitor.h"
#include "Basics/ArangoGlobalContext.h"
#include "Cluster/ServerState.h"
#include "Dispatcher/DispatcherFeature.h"
#include "Dispatcher/DispatcherThread.h"
Expand Down Expand Up @@ -147,6 +148,15 @@ void V8DealerFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
// remove trailing / from path and set path
_startupPath = StringUtils::rTrim(_startupPath, TRI_DIR_SEPARATOR_STR);

auto ctx = ArangoGlobalContext::CONTEXT;

if (ctx == nullptr) {
LOG(ERR) << "failed to get global context. ";
FATAL_ERROR_EXIT();
}

ctx->getCheckPath(_startupPath, "javascript.startup-directory");

_startupLoader.setDirectory(_startupPath);
ServerState::instance()->setJavaScriptPath(_startupPath);

Expand All @@ -156,6 +166,8 @@ void V8DealerFeature::validateOptions(std::shared_ptr<ProgramOptions> options) {
FATAL_ERROR_EXIT();
}

ctx->getCheckPath(_appPath, "javascript.app-directory");

// use a minimum of 1 second for GC
if (_gcFrequency < 1) {
_gcFrequency = 1;
Expand Down
3 changes: 2 additions & 1 deletion arangosh/Benchmark/arangobench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"

#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
Expand All @@ -41,7 +42,7 @@ using namespace arangodb::basics;
using namespace arangodb::rest;

int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();

std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(
Expand Down
3 changes: 2 additions & 1 deletion arangosh/Dump/arangodump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"

#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
Expand All @@ -38,7 +39,7 @@ using namespace arangodb;
using namespace arangodb::application_features;

int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();

std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(
Expand Down
3 changes: 2 additions & 1 deletion arangosh/Import/arangoimp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"

#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
Expand All @@ -39,7 +40,7 @@ using namespace arangodb;
using namespace arangodb::application_features;

int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();

std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(
Expand Down
3 changes: 2 additions & 1 deletion arangosh/Restore/arangorestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"

#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
Expand All @@ -39,7 +40,7 @@ using namespace arangodb;
using namespace arangodb::application_features;

int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();

std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(
Expand Down
10 changes: 10 additions & 0 deletions arangosh/Shell/V8ShellFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "Basics/StringUtils.h"
#include "Basics/Utf8Helper.h"
#include "Basics/shell-colors.h"
#include "Basics/ArangoGlobalContext.h"
#include "Logger/Logger.h"
#include "ProgramOptions/ProgramOptions.h"
#include "ProgramOptions/Section.h"
Expand Down Expand Up @@ -809,6 +810,15 @@ void V8ShellFeature::initGlobals() {
TRI_V8_ASCII_STRING2(_isolate, "ARANGO_QUIET"),
v8::Boolean::New(_isolate, _console->quiet()));

auto ctx = ArangoGlobalContext::CONTEXT;

if (ctx == nullptr) {
LOG(ERR) << "failed to get global context. ";
FATAL_ERROR_EXIT();
}

ctx->getCheckPath(_startupDirectory, "javascript.startup-directory");

// initialize standard modules
std::string modules =
FileUtils::buildFilename(_startupDirectory, "client/modules") + ";" +
Expand Down
3 changes: 2 additions & 1 deletion arangosh/Shell/arangosh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"

#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/LanguageFeature.h"
Expand All @@ -43,7 +44,7 @@ using namespace arangodb;
using namespace arangodb::application_features;

int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();

std::string name = context.binaryName();
Expand Down
3 changes: 2 additions & 1 deletion arangosh/VPack/arangovpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
////////////////////////////////////////////////////////////////////////////////

#include "Basics/Common.h"
#include "Basics/directories.h"

#include "ApplicationFeatures/ConfigFeature.h"
#include "ApplicationFeatures/ShutdownFeature.h"
Expand All @@ -36,7 +37,7 @@ using namespace arangodb;
using namespace arangodb::application_features;

int main(int argc, char* argv[]) {
ArangoGlobalContext context(argc, argv);
ArangoGlobalContext context(argc, argv, BIN_DIRECTORY);
context.installHup();

std::shared_ptr<options::ProgramOptions> options(new options::ProgramOptions(
Expand Down
19 changes: 13 additions & 6 deletions cmake/ArangoDBInstall.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ set(CMAKE_INSTALL_SYSCONFDIR_ARANGO "${CMAKE_INSTALL_SYSCONFDIR}/arangodb3")
set(CMAKE_INSTALL_FULL_SYSCONFDIR_ARANGO "${CMAKE_INSTALL_FULL_SYSCONFDIR}/arangodb3")

file(TO_NATIVE_PATH "${CMAKE_INSTALL_FULL_SYSCONFDIR_ARANGO}" ETCDIR_NATIVE)
STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ETCDIR_ESCAPED "${ETCDIR_NATIVE}")
add_definitions("-D_SYSCONFDIR_=\"${ETCDIR_ESCAPED}\"")

# database directory
FILE(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/var/lib/arangodb3")
Expand Down Expand Up @@ -84,6 +82,15 @@ install(
DIRECTORY ${PROJECT_BINARY_DIR}/var/lib/arangodb3-apps
DESTINATION ${CMAKE_INSTALL_LOCALSTATEDIR}/lib)

################################################################################
### @brief propagate the locations into our programms:
################################################################################

configure_file (
"${CMAKE_CURRENT_SOURCE_DIR}/lib/Basics/directories.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/lib/Basics/directories.h"
NEWLINE_STYLE UNIX
)

# sub directories --------------------------------------------------------------

Expand All @@ -106,8 +113,8 @@ install(


#--------------------------------------------------------------------------------
#get_cmake_property(_variableNames VARIABLES)
#foreach (_variableName ${_variableNames})
# message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
#--------------------------------------------------------------------------------
2 changes: 1 addition & 1 deletion cmake/packages/client/rpm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(PROJECT_SOURCE_DIR @PROJECT_SOURCE_DIR@)
################################################################################
# Get the final values for cpack:
################################################################################
set(CPACK_GENERATOR "DEB")
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_VERSION "${ARANGODB_VERSION}")
set(CPACK_PACKAGE_NAME "arangodb3-client")
set(CPACK_PACKAGE_CONTACT ${ARANGODB_PACKAGE_CONTACT})
Expand Down
37 changes: 25 additions & 12 deletions lib/ApplicationFeatures/ConfigFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

#include <iostream>

#include "Basics/directories.h"
#include "Basics/FileUtils.h"
#include "Basics/StringUtils.h"
#include "Basics/ArangoGlobalContext.h"
#include "Logger/Logger.h"
#include "ProgramOptions/IniFileParser.h"
#include "ProgramOptions/ProgramOptions.h"
Expand Down Expand Up @@ -119,38 +121,49 @@ void ConfigFeature::loadConfigFile(std::shared_ptr<ProgramOptions> options,
//
// clang-format on

auto context = ArangoGlobalContext::CONTEXT;
std::string basename = name + ".conf";
std::string filename =
FileUtils::buildFilename(FileUtils::currentDirectory(), basename);
std::string filename;

LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
if (context != nullptr) {
filename = FileUtils::buildFilename(FileUtils::buildFilename(context->runRoot(), _SYSCONFDIR_), basename);
LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";
}

if (!FileUtils::exists(filename)) {
filename = FileUtils::buildFilename(FileUtils::currentDirectory(),
"etc/relative/" + basename);
if (filename.length() == 0 || !FileUtils::exists(filename)) {

filename = FileUtils::buildFilename(FileUtils::currentDirectory(), basename);

LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";


if (!FileUtils::exists(filename)) {
filename =
FileUtils::buildFilename(FileUtils::homeDirectory(), basename);
filename = FileUtils::buildFilename(FileUtils::currentDirectory(),
"etc/relative/" + basename);

LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";

if (!FileUtils::exists(filename)) {
filename =
FileUtils::buildFilename(FileUtils::configDirectory(), basename);
FileUtils::buildFilename(FileUtils::homeDirectory(), basename);

LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";

if (!FileUtils::exists(filename)) {
LOG_TOPIC(DEBUG, Logger::CONFIG) << "cannot find any config file";
return;
filename =
FileUtils::buildFilename(FileUtils::configDirectory(), basename);

LOG_TOPIC(DEBUG, Logger::CONFIG) << "checking '" << filename << "'";

if (!FileUtils::exists(filename)) {
LOG_TOPIC(DEBUG, Logger::CONFIG) << "cannot find any config file";
return;
}
}
}
}
}

IniFileParser parser(options.get());

std::string local = filename + ".local";
Expand Down
21 changes: 17 additions & 4 deletions lib/Basics/ArangoGlobalContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@

#include "Basics/debugging.h"
#include "Basics/files.h"
#ifdef __arm__
#include "Basics/FileUtils.h"
#endif
#include "Logger/LogAppender.h"
#include "Logger/Logger.h"
#include "Rest/InitializeRest.h"
Expand Down Expand Up @@ -110,8 +108,11 @@ LONG CALLBACK unhandledExceptionHandler(EXCEPTION_POINTERS* e) {

ArangoGlobalContext* ArangoGlobalContext::CONTEXT = nullptr;

ArangoGlobalContext::ArangoGlobalContext(int argc, char* argv[])
: _binaryName(TRI_BinaryName(argv[0])), _ret(EXIT_FAILURE), _useEventLog(true) {
ArangoGlobalContext::ArangoGlobalContext(int argc, char* argv[], const char *InstallDirectory)
: _binaryName(TRI_BinaryName(argv[0])),
_runRoot(TRI_GetInstallRoot(TRI_LocateBinaryPath(argv[0]), InstallDirectory)),
_ret(EXIT_FAILURE),
_useEventLog(true) {

static char const* serverName = "arangod";
if (_binaryName.size() < strlen(serverName) ||
Expand Down Expand Up @@ -271,3 +272,15 @@ void ArangoGlobalContext::tempPathAvailable() {
"\\minidump_" + std::to_string(GetCurrentProcessId()) + ".dmp";
#endif
}

void ArangoGlobalContext::getCheckPath(std::string &path, const char *whichPath) {
if (!arangodb::basics::FileUtils::exists(path)) {
std::string directory;
directory = arangodb::basics::FileUtils::buildFilename(_runRoot, path);
if (!arangodb::basics::FileUtils::exists(directory)) {
LOG(ERR) << "failed to locate " << whichPath << " directory, its neither available in '" << path << "' nor in '" << directory << "'";
FATAL_ERROR_EXIT();
}
path = directory;
}
}
5 changes: 4 additions & 1 deletion lib/Basics/ArangoGlobalContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ class ArangoGlobalContext {
static ArangoGlobalContext* CONTEXT;

public:
ArangoGlobalContext(int argc, char* argv[]);
ArangoGlobalContext(int argc, char* argv[], const char *InstallDirectory);
~ArangoGlobalContext();

public:
std::string binaryName() { return _binaryName; }
std::string runRoot() { return _runRoot; }
void getCheckPath(std::string &path, const char *whichPath);
int exit(int ret);
void installHup();
void installSegv();
Expand All @@ -47,6 +49,7 @@ class ArangoGlobalContext {

private:
std::string _binaryName;
std::string _runRoot;
int _ret;
bool _useEventLog;
};
Expand Down
7 changes: 7 additions & 0 deletions lib/Basics/directories.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define LOCCAL_STATE_DIR "@CMAKE_INSTALL_FULL_LOCALSTATEDIR@"
#define _SYSCONFDIR_ "@ETCDIR_NATIVE@"
#define STARTUP_DIRECTORY "@PKGDATADIR@/js"
#define DESTINATION_DIR "@CMAKE_INSTALL_DATAROOTDIR_ARANGO@/js"
#define ICU_DESTINATION_DIRECTORY "@ICU_DT_DEST@"
#define SBIN_DIRECTORY "@CMAKE_INSTALL_SBINDIR@"
#define BIN_DIRECTORY "@CMAKE_INSTALL_BINDIR@"
Loading

0 comments on commit 1f162ac

Please sign in to comment.