Skip to content

Commit

Permalink
Get readline working again
Browse files Browse the repository at this point in the history
- Until we can find a solution that doesn't break things
  • Loading branch information
who-biz committed Jun 24, 2020
1 parent 3bec88a commit 9a4f0e8
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 68 deletions.
18 changes: 8 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -809,13 +809,11 @@ if(STATIC)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
endif()
set(BOOST_INCLUDE_DIR /usr/lib/boost)
find_package(Boost REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options locale)
find_package(Boost 1.58 QUIET REQUIRED COMPONENTS system filesystem thread date_time chrono regex serialization program_options locale)

set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES})

if(NOT Boost_FOUND AND NOT DEPENDS)
message(FATAL_ERROR "Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (1.58) or the equivalent")
if(NOT Boost_FOUND)
die("Could not find Boost libraries, please make sure you have installed Boost or libboost-all-dev (1.58) or the equivalent")
elseif(Boost_FOUND)
message(STATUS "Found Boost Version: ${Boost_VERSION}")
if (Boost_VERSION VERSION_LESS 10 AND Boost_VERSION VERSION_LESS 1.62.0 AND NOT (OPENSSL_VERSION VERSION_LESS 1.1))
Expand Down Expand Up @@ -856,14 +854,14 @@ endif()

list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS})

option(USE_READLINE "Build with GNU readline support." OFF)

option(USE_READLINE "Build with GNU readline support." ON)
if(USE_READLINE)
find_package(Readline)
if(READLINE_FOUND)
if(READLINE_FOUND AND GNU_READLINE_FOUND)
add_definitions(-DHAVE_READLINE)
include_directories(READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIRS})
message(STATUS "Found readline library at: ${READLINE_LIBRARIES}")
include_directories(${Readline_INCLUDE_DIR})
message(STATUS "Found readline library at: ${Readline_ROOT_DIR}")
set(EPEE_READLINE epee_readline)
else()
message(STATUS "Could not find GNU readline library so building without readline support")
endif()
Expand Down
112 changes: 88 additions & 24 deletions cmake/FindReadline.cmake
Original file line number Diff line number Diff line change
@@ -1,33 +1,97 @@
# Try to find libreadline
# Once done, this will define
# - Try to find readline include dirs and libraries
#
# READLINE_FOUND - system has readline
# READLINE_INCLUDE_DIRS - readline include directories
# READLINE_LIBRARIES - libraries need to use readline
# Usage of this module as follows:
#
# find_package(Readline)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# Readline_ROOT_DIR Set this variable to the root installation of
# readline if the module has problems finding the
# proper installation path.
#
# Variables defined by this module:
#
# READLINE_FOUND System has readline, include and lib dirs found
# GNU_READLINE_FOUND Version of readline found is GNU readline, not libedit!
# LIBEDIT_FOUND Version of readline found is libedit, not GNU readline!
# Readline_INCLUDE_DIR The readline include directories.
# Readline_LIBRARY The readline library.
# GNU_READLINE_LIBRARY The GNU readline library or empty string.
# LIBEDIT_LIBRARY The libedit library or empty string.

find_path(Readline_ROOT_DIR
NAMES include/readline/readline.h
PATHS /usr/local/opt/readline/ /opt/local/ /usr/local/ /usr/
NO_DEFAULT_PATH
)

include(FindPackageHandleStandardArgs)
find_path(Termcap_ROOT_DIR
NAMES include/curses.h
PATHS /usr/local/ /usr/ /opt/local/ /usr/local/opt/ncurses/
NO_DEFAULT_PATH
)

if(READLINE_INCLUDE_DIRS AND READLINE_LIBRARIES)
set(READLINE_FIND_QUIETLY TRUE)
else()
find_path(
READLINE_INCLUDE_DIR
find_path(Readline_INCLUDE_DIR
NAMES readline/readline.h
HINTS ${READLINE_ROOT_DIR}
PATH_SUFFIXES include)
PATHS ${Readline_ROOT_DIR}/include
NO_DEFAULT_PATH
)

find_library(
READLINE_LIBRARY
find_library(Readline_LIBRARY
NAMES readline
HINTS ${READLINE_ROOT_DIR}
PATH_SUFFIXES ${LIBRARY_PATH_PREFIX})
PATHS ${Readline_ROOT_DIR}/lib
NO_DEFAULT_PATH
)

find_library(Termcap_LIBRARY
NAMES tinfo termcap ncursesw ncurses cursesw curses
PATHS ${Termcap_ROOT_DIR}/lib
NO_DEFAULT_PATH
)

if(Readline_INCLUDE_DIR AND Readline_LIBRARY)
set(READLINE_FOUND TRUE)
else(Readline_INCLUDE_DIR AND Readline_LIBRARY)
FIND_LIBRARY(Readline_LIBRARY NAMES readline PATHS Readline_ROOT_DIR)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARY )
MARK_AS_ADVANCED(Readline_INCLUDE_DIR Readline_LIBRARY)
endif(Readline_INCLUDE_DIR AND Readline_LIBRARY)

mark_as_advanced(
Readline_ROOT_DIR
Readline_INCLUDE_DIR
Readline_LIBRARY
)

set(CMAKE_REQUIRED_INCLUDES ${Readline_INCLUDE_DIR})
set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARY})

include(CheckFunctionExists)
check_function_exists(rl_copy_text HAVE_COPY_TEXT)
check_function_exists(rl_filename_completion_function HAVE_COMPLETION_FUNCTION)

if(NOT HAVE_COMPLETION_FUNCTION)
set(CMAKE_REQUIRED_LIBRARIES ${Readline_LIBRARY} ${Termcap_LIBRARY})
check_function_exists(rl_copy_text HAVE_COPY_TEXT_TC)
check_function_exists(rl_filename_completion_function HAVE_COMPLETION_FUNCTION_TC)
set(HAVE_COMPLETION_FUNCTION ${HAVE_COMPLETION_FUNCTION_TC})
set(HAVE_COPY_TEXT ${HAVE_COPY_TEXT_TC})
if(HAVE_COMPLETION_FUNCTION)
set(Readline_LIBRARY ${Readline_LIBRARY} ${Termcap_LIBRARY})
endif(HAVE_COMPLETION_FUNCTION)
endif(NOT HAVE_COMPLETION_FUNCTION)

set(READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR})
set(READLINE_LIBRARIES ${READLINE_LIBRARY})
set(LIBEDIT_LIBRARY "")
set(GNU_READLINE_LIBRARY "")

find_package_handle_standard_args(
readline
DEFAULT_MSG READLINE_LIBRARY READLINE_INCLUDE_DIR)
if(HAVE_COMPLETION_FUNCTION AND HAVE_COPY_TEXT)
set(GNU_READLINE_FOUND TRUE)
set(GNU_READLINE_LIBRARY ${Readline_LIBRARY})
elseif(READLINE_FOUND AND NOT HAVE_COPY_TEXT)
set(LIBEDIT_FOUND TRUE)
set(LIBEDIT_LIBRARY ${Readline_LIBRARY})
endif(HAVE_COMPLETION_FUNCTION AND HAVE_COPY_TEXT)

mark_as_advanced(READLINE_LIBRARY READLINE_INCLUDE_DIR)
endif()
22 changes: 11 additions & 11 deletions contrib/epee/include/console_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string/split.hpp>

#ifdef USE_READLINE
#ifdef HAVE_READLINE
#include "readline_buffer.h"
#endif

Expand All @@ -55,7 +55,7 @@ namespace epee
, m_has_read_request(false)
, m_read_status(state_init)
{
#ifdef USE_READLINE
#ifdef HAVE_READLINE
m_readline_buffer.start();
#endif
m_reader_thread = boost::thread(std::bind(&async_stdin_reader::reader_thread_func, this));
Expand All @@ -67,7 +67,7 @@ namespace epee
catch (std::exception& e) { LOG_ERROR("Exception in async_stdin_reader destructor: \n"); LOG_ERROR(e.what()); }
}

#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::readline_buffer& get_readline_buffer()
{
return m_readline_buffer;
Expand Down Expand Up @@ -116,7 +116,7 @@ namespace epee

m_request_cv.notify_one();
m_reader_thread.join();
#ifdef USE_READLINE
#ifdef HAVE_READLINE
m_readline_buffer.stop();
#endif
}
Expand Down Expand Up @@ -204,14 +204,14 @@ namespace epee

std::string line;
bool read_ok = true;
#ifdef USE_READLINE
#ifdef HAVE_READLINE
reread:
#endif
if (wait_stdin_data())
{
if (m_run.load(std::memory_order_relaxed))
{
#ifdef USE_READLINE
#ifdef HAVE_READLINE
switch (m_readline_buffer.get_line(line))
{
case rdln::empty: goto eof;
Expand All @@ -229,7 +229,7 @@ namespace epee
read_ok = false;
}
if (std::cin.eof()) {
#ifdef USE_READLINE
#ifdef HAVE_READLINE
eof:
#endif
m_read_status = state_eos;
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace epee
private:
boost::thread m_reader_thread;
std::atomic<bool> m_run;
#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::readline_buffer m_readline_buffer;
#endif

Expand Down Expand Up @@ -317,7 +317,7 @@ namespace epee
std::string prompt = m_prompt();
if (!prompt.empty())
{
#ifdef USE_READLINE
#ifdef HAVE_READLINE
std::string color_prompt = "\001\033[1;33m\002" + prompt;
if (' ' != prompt.back())
color_prompt += " ";
Expand Down Expand Up @@ -380,7 +380,7 @@ namespace epee
}
else
{
#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::suspend_readline pause_readline;
#endif
std::cout << "unknown command: " << command << std::endl;
Expand Down Expand Up @@ -510,7 +510,7 @@ namespace epee
vt.first = hndlr;
vt.second.first = description.empty() ? cmd : usage;
vt.second.second = description.empty() ? usage : description;
#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::readline_buffer::add_completion(cmd);
#endif
}
Expand Down
24 changes: 7 additions & 17 deletions contrib/epee/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,10 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


if(STATIC)
add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp)
else()
add_library(epee SHARED hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp)
endif()

if(USE_READLINE)
if (STATIC)
add_library(epee_readline STATIC readline_buffer.cpp)
else()
add_library(epee_readline SHARED readline_buffer.cpp)
endif()
set(EPEE_READLINE epee_readline)
add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp memwipe.c
connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp)
if (USE_READLINE AND GNU_READLINE_FOUND)
add_library(epee_readline STATIC readline_buffer.cpp)
endif()

if(HAVE_C11)
Expand All @@ -55,7 +45,7 @@ if (BUILD_GUI_DEPS)
endif()
install(TARGETS epee
ARCHIVE DESTINATION ${lib_folder})
if (USE_READLINE)
if (USE_READLINE AND GNU_READLINE_FOUND)
install(TARGETS epee_readline
ARCHIVE DESTINATION ${lib_folder})
endif()
Expand All @@ -71,10 +61,10 @@ target_link_libraries(epee
${OPENSSL_LIBRARIES}
${EXTRA_LIBRARIES})

if (USE_READLINE)
if (USE_READLINE AND GNU_READLINE_FOUND)
target_link_libraries(epee_readline
PUBLIC
easylogging
PRIVATE
${READLINE_LIBRARIES})
${GNU_READLINE_LIBRARY})
endif()
3 changes: 1 addition & 2 deletions src/simplewallet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ target_link_libraries(simplewallet
common
mnemonics
${EPEE_READLINE}
${READLINE_LIBRARIES}
${Boost_CHRONO_LIBRARY}
${Boost_PROGRAM_OPTIONS_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
${Boost_LOCALE_LIBRARY}
${ICU_LIBRARIES}
${Boost_THREAD_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
${OPENSSL_LIBRARIES}
${GNU_READLINE_LIBRARY}
${EXTRA_LIBRARIES})
set_property(TARGET simplewallet
PROPERTY
Expand Down
8 changes: 4 additions & 4 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include <boost/filesystem.hpp>
#endif

#ifdef USE_READLINE
#ifdef HAVE_READLINE
#include "readline_buffer.h"
#endif

Expand Down Expand Up @@ -139,7 +139,7 @@ namespace

std::string input_line(const std::string& prompt)
{
#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::suspend_readline pause_readline;
#endif
std::cout << prompt;
Expand All @@ -156,7 +156,7 @@ namespace

boost::optional<tools::password_container> password_prompter(const char *prompt, bool verify)
{
#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::suspend_readline pause_readline;
#endif
auto pwd_container = tools::password_container::prompt(verify, prompt);
Expand Down Expand Up @@ -3717,7 +3717,7 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset, bool is_init
if (reset)
m_wallet->rescan_blockchain(false);

#ifdef USE_READLINE
#ifdef HAVE_READLINE
rdln::suspend_readline pause_readline;
#endif

Expand Down

0 comments on commit 9a4f0e8

Please sign in to comment.