Skip to content

Commit

Permalink
Merge pull request #273 from SylvainCorlay/use-dynamic-prefix-path
Browse files Browse the repository at this point in the history
Use dynamic prefix path
  • Loading branch information
SylvainCorlay committed Nov 20, 2019
2 parents 1461dd9 + 8f1f76e commit 9373554
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 15 deletions.
20 changes: 10 additions & 10 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ install:
- conda update -q conda
- conda info -a
# Install dependencies
- conda install cmake dirent xeus=0.21.1 cling=0.5.0 clangdev=5.0 clang_variant=*=cling_6.14.06 llvmdev=5 nlohmann_json=3.6.1 cppzmq=4.3.0 xtl=0.6.5 pugixml cxxopts=2.1.1 -c QuantStack -c conda-forge
#- conda install cmake dirent xeus=0.21.1 cling=0.5.0 clangdev=5.0 clang_variant=*=cling_6.14.06 llvmdev=5 nlohmann_json=3.6.1 cppzmq=4.3.0 xtl=0.6.5 pugixml cxxopts=2.1.1 -c conda-forge
# Build and install xeus-cling
- mkdir build
- cd build
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D CMAKE_BUILD_TYPE=%CONFIGURATION% -D XEXTRA_JUPYTER_DATA_DIR=%MINICONDA%\\share\\jupyter ..
- nmake
- nmake install
#- mkdir build
#- cd build
#- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D CMAKE_BUILD_TYPE=%CONFIGURATION% -D XEXTRA_JUPYTER_DATA_DIR=%MINICONDA%\\share\\jupyter ..
#- nmake
#- nmake install
# Install jupyter_kernel_test and pytest
- conda install pytest jupyter_kernel_test -c conda-forge
- cd..
- cd test
#- conda install pytest jupyter_kernel_test -c conda-forge
#- cd..
#- cd test

build_script:
# Allowing failure on jupyter kernel tests as Cling does not support windows
- py.test . & exit 0
#- py.test . & exit 0
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ set(XEUS_CLING_SRC
src/xoptions.cpp
src/xparser.cpp
src/xparser.hpp
src/xpaths.cpp
src/xpaths.hpp
src/xholder_cling.cpp
src/xmagics/execution.cpp
src/xmagics/execution.hpp
Expand All @@ -182,6 +184,13 @@ set(XEUS_CLING_HEADERS
include/xeus-cling/xpreamble.hpp
)

# xcpp sources
set(XCPP_SRC
src/main.cpp
src/xpaths.hpp
src/xpaths.cpp
)

# xcpp headers (needed at runtime by the C++ kernel)
set(XCPP_HEADERS
include/xcpp/xmime.hpp
Expand All @@ -192,7 +201,7 @@ set(XCPP_HEADERS
add_library(xeus-cling SHARED ${XEUS_CLING_SRC} ${XEUS_CLING_HEADERS})

# xcpp is the target for the kernel executable
add_executable(xcpp src/main.cpp)
add_executable(xcpp ${XCPP_SRC})
set_target_properties(xcpp PROPERTIES ENABLE_EXPORTS 1)
target_link_libraries(xcpp PRIVATE xeus-cling)

Expand Down Expand Up @@ -342,8 +351,8 @@ install(DIRECTORY ${XCPP_TAGCONFS_DIR}
DESTINATION ${XEUS_CLING_CONF_DIR})

# Add definitions for the kernel to find tagfiles.
add_definitions(-DXCPP_TAGFILES_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CLING_DATA_DIR}/tagfiles")
add_definitions(-DXCPP_TAGCONFS_DIR="${CMAKE_INSTALL_PREFIX}/${XEUS_CLING_CONF_DIR}/tags.d")
add_definitions(-DXCPP_TAGFILES_DIR="${XEUS_CLING_DATA_DIR}/tagfiles")
add_definitions(-DXCPP_TAGCONFS_DIR="${XEUS_CLING_CONF_DIR}/tags.d")

# Makes the project importable from the build directory
export(EXPORT ${PROJECT_NAME}-targets
Expand Down
7 changes: 5 additions & 2 deletions src/xinspect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "xdemangle.hpp"
#include "xparser.hpp"
#include "xpaths.hpp"

namespace xcpp
{
Expand Down Expand Up @@ -174,8 +175,10 @@ namespace xcpp

void inspect(const std::string& code, nl::json& kernel_res, cling::MetaProcessor& m_processor)
{
nl::json tagconfs = read_tagconfs(XCPP_TAGCONFS_DIR);
std::string tagfiles_dir = XCPP_TAGFILES_DIR;
std::string tagconf_dir = prefix_path() + XCPP_TAGCONFS_DIR;
std::string tagfiles_dir = prefix_path() + XCPP_TAGFILES_DIR;

nl::json tagconfs = read_tagconfs(tagconf_dir.c_str());

std::vector<std::string> check{"class", "struct", "function"};

Expand Down
96 changes: 96 additions & 0 deletions src/xpaths.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/***************************************************************************
* Copyright (c) 2018, Martin Renou, Johan Mabille, Sylvain Corlay and *
* Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#include "xpaths.hpp"

#include <string>
#include <cstring>

#if defined(__linux__)
# include <unistd.h>
#endif
#if defined(_WIN32)
# if defined(NOMINMAX)
# include <windows.h>
# else
# define NOMINMAX
# include <windows.h>
# undef NOMINMAX
# endif
#endif
#ifdef __APPLE__
# include <cstdint>
# include <mach-o/dyld.h>
#endif
#if defined(__sun)
# include <stdlib.h>
#endif

namespace xcpp
{
std::string executable_path()
{
std::string path;
char buffer[1024];
std::memset(buffer, '\0', sizeof(buffer));
#if defined(__linux__)
if (readlink("/proc/self/exe", buffer, sizeof(buffer)) != -1)
{
path = buffer;
}
else
{
// failed to determine run path
}
#elif defined (_WIN32)
if (GetModuleFileName(nullptr, buffer, sizeof(buffer)) != 0)
{
path = buffer;
}
else
{
// failed to determine run path
}
#elif defined (__APPLE__)
std::uint32_t size = sizeof(buffer);
if(_NSGetExecutablePath(buffer, &size) == 0)
{
path = buffer;
}
else
{
// failed to determine run path
}
#elif defined (__FreeBSD__)
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
if (sysctl(mib, 4, buffer, sizeof(buffer), NULL, 0) != -1)
{
path = buffer;
}
else
{
// failed to determine run path
}
#elif defined(__sun)
path = getexecname();
#endif
return path;
}

std::string prefix_path()
{
std::string path = executable_path();
#if defined (_WIN32)
char separator = '\\';
#else
char separator = '/';
#endif
return path.substr(0, path.find_last_of("/\\")) + separator + ".." + separator;
}
}
29 changes: 29 additions & 0 deletions src/xpaths.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/***************************************************************************
* Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* Copyright (c) QuantStack *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/

#ifndef XPYT_PATHS_HPP
#define XPYT_PATHS_HPP

#include <string>

namespace xcpp
{
/*******************
* executable_path *
*******************/

std::string executable_path();

/*******************
* prefix_path *
*******************/

std::string prefix_path();
}
#endif

0 comments on commit 9373554

Please sign in to comment.