feat(util/lean_path): add support for LEAN_PATH
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
df1b21a03d
commit
777582380f
5 changed files with 30 additions and 15 deletions
|
@ -13,6 +13,8 @@ add_test(lean_version1 ${CMAKE_CURRENT_BINARY_DIR}/lean --version)
|
||||||
add_test(lean_version2 ${CMAKE_CURRENT_BINARY_DIR}/lean --v)
|
add_test(lean_version2 ${CMAKE_CURRENT_BINARY_DIR}/lean --v)
|
||||||
add_test(lean_ghash1 ${CMAKE_CURRENT_BINARY_DIR}/lean -g)
|
add_test(lean_ghash1 ${CMAKE_CURRENT_BINARY_DIR}/lean -g)
|
||||||
add_test(lean_ghash2 ${CMAKE_CURRENT_BINARY_DIR}/lean --githash)
|
add_test(lean_ghash2 ${CMAKE_CURRENT_BINARY_DIR}/lean --githash)
|
||||||
|
add_test(lean_path1 ${CMAKE_CURRENT_BINARY_DIR}/lean -p)
|
||||||
|
add_test(lean_path2 ${CMAKE_CURRENT_BINARY_DIR}/lean --path)
|
||||||
add_test(lean_luahook1 ${CMAKE_CURRENT_BINARY_DIR}/lean --luahook=100 "${LEAN_SOURCE_DIR}/../tests/lua/big.lua")
|
add_test(lean_luahook1 ${CMAKE_CURRENT_BINARY_DIR}/lean --luahook=100 "${LEAN_SOURCE_DIR}/../tests/lua/big.lua")
|
||||||
add_test(lean_luahook2 ${CMAKE_CURRENT_BINARY_DIR}/lean -c 100 "${LEAN_SOURCE_DIR}/../tests/lua/big.lua")
|
add_test(lean_luahook2 ${CMAKE_CURRENT_BINARY_DIR}/lean -c 100 "${LEAN_SOURCE_DIR}/../tests/lua/big.lua")
|
||||||
add_test(lean_lua1 ${LEAN_SOURCE_DIR}/cmake/redirect.sh "${CMAKE_CURRENT_BINARY_DIR}/lean" "--lua" "${LEAN_SOURCE_DIR}/../tests/lua/single.lua")
|
add_test(lean_lua1 ${LEAN_SOURCE_DIR}/cmake/redirect.sh "${CMAKE_CURRENT_BINARY_DIR}/lean" "--lua" "${LEAN_SOURCE_DIR}/../tests/lua/single.lua")
|
||||||
|
|
|
@ -15,6 +15,7 @@ Author: Leonardo de Moura
|
||||||
#include "util/interrupt.h"
|
#include "util/interrupt.h"
|
||||||
#include "util/script_state.h"
|
#include "util/script_state.h"
|
||||||
#include "util/thread.h"
|
#include "util/thread.h"
|
||||||
|
#include "util/lean_path.h"
|
||||||
#include "kernel/printer.h"
|
#include "kernel/printer.h"
|
||||||
#include "kernel/environment.h"
|
#include "kernel/environment.h"
|
||||||
#include "library/io_state.h"
|
#include "library/io_state.h"
|
||||||
|
@ -55,6 +56,7 @@ static void display_help(std::ostream & out) {
|
||||||
std::cout << " --help -h display this message\n";
|
std::cout << " --help -h display this message\n";
|
||||||
std::cout << " --version -v display version number\n";
|
std::cout << " --version -v display version number\n";
|
||||||
std::cout << " --githash display the git commit hash number used to build this binary\n";
|
std::cout << " --githash display the git commit hash number used to build this binary\n";
|
||||||
|
std::cout << " --path display the path used for finding Lean libraries and extensions\n";
|
||||||
std::cout << " --luahook=num -c how often the Lua interpreter checks the interrupted flag,\n";
|
std::cout << " --luahook=num -c how often the Lua interpreter checks the interrupted flag,\n";
|
||||||
std::cout << " it is useful for interrupting non-terminating user scripts,\n";
|
std::cout << " it is useful for interrupting non-terminating user scripts,\n";
|
||||||
std::cout << " 0 means 'do not check'.\n";
|
std::cout << " 0 means 'do not check'.\n";
|
||||||
|
@ -82,6 +84,7 @@ static struct option g_long_options[] = {
|
||||||
{"help", no_argument, 0, 'h'},
|
{"help", no_argument, 0, 'h'},
|
||||||
{"lean", no_argument, 0, 'l'},
|
{"lean", no_argument, 0, 'l'},
|
||||||
{"lua", no_argument, 0, 'u'},
|
{"lua", no_argument, 0, 'u'},
|
||||||
|
{"path", no_argument, 0, 'p'},
|
||||||
{"luahook", required_argument, 0, 'c'},
|
{"luahook", required_argument, 0, 'c'},
|
||||||
{"githash", no_argument, 0, 'g'},
|
{"githash", no_argument, 0, 'g'},
|
||||||
#if defined(LEAN_USE_BOOST)
|
#if defined(LEAN_USE_BOOST)
|
||||||
|
@ -95,7 +98,7 @@ int main(int argc, char ** argv) {
|
||||||
lean::register_modules();
|
lean::register_modules();
|
||||||
input_kind default_k = input_kind::Lean; // default
|
input_kind default_k = input_kind::Lean; // default
|
||||||
while (true) {
|
while (true) {
|
||||||
int c = getopt_long(argc, argv, "lugvhc:012s:012", g_long_options, NULL);
|
int c = getopt_long(argc, argv, "lupgvhc:012s:012", g_long_options, NULL);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break; // end of command line
|
break; // end of command line
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -117,6 +120,9 @@ int main(int argc, char ** argv) {
|
||||||
case 'c':
|
case 'c':
|
||||||
script_state::set_check_interrupt_freq(atoi(optarg));
|
script_state::set_check_interrupt_freq(atoi(optarg));
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
std::cout << lean::get_lean_path() << "\n";
|
||||||
|
return 0;
|
||||||
case 's':
|
case 's':
|
||||||
lean::set_thread_stack_size(atoi(optarg)*1024);
|
lean::set_thread_stack_size(atoi(optarg)*1024);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -8,6 +8,6 @@ add_library(util trace.cpp debug.cpp name.cpp name_set.cpp
|
||||||
exception.cpp interrupt.cpp hash.cpp escaped.cpp bit_tricks.cpp
|
exception.cpp interrupt.cpp hash.cpp escaped.cpp bit_tricks.cpp
|
||||||
safe_arith.cpp ascii.cpp memory.cpp shared_mutex.cpp realpath.cpp
|
safe_arith.cpp ascii.cpp memory.cpp shared_mutex.cpp realpath.cpp
|
||||||
script_state.cpp script_exception.cpp splay_map.cpp lua.cpp
|
script_state.cpp script_exception.cpp splay_map.cpp lua.cpp
|
||||||
luaref.cpp stackinfo.cpp exe_location.cpp ${THREAD_CPP})
|
luaref.cpp stackinfo.cpp lean_path.cpp ${THREAD_CPP})
|
||||||
|
|
||||||
target_link_libraries(util ${LEAN_LIBS})
|
target_link_libraries(util ${LEAN_LIBS})
|
||||||
|
|
|
@ -5,29 +5,29 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
||||||
Author: Leonardo de Moura
|
Author: Leonardo de Moura
|
||||||
*/
|
*/
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <cstdlib>
|
||||||
#include "util/exception.h"
|
#include "util/exception.h"
|
||||||
|
|
||||||
namespace lean {
|
namespace lean {
|
||||||
static std::string g_exe_location;
|
|
||||||
#if defined(LEAN_WINDOWS)
|
#if defined(LEAN_WINDOWS)
|
||||||
// Windows version
|
// Windows version
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
static void init_exe_location() {
|
static std::string get_exe_location() {
|
||||||
HMODULE hModule = GetModuleHandleW(NULL);
|
HMODULE hModule = GetModuleHandleW(NULL);
|
||||||
WCHAR path[MAX_PATH];
|
WCHAR path[MAX_PATH];
|
||||||
GetModuleFileNameW(hModule, path, MAX_PATH);
|
GetModuleFileNameW(hModule, path, MAX_PATH);
|
||||||
g_exe_location = path;
|
return std::string(path);
|
||||||
}
|
}
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
// OSX version
|
// OSX version
|
||||||
#include <mach-o/dyld.h>
|
#include <mach-o/dyld.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
static void init_exe_location() {
|
static std::string get_exe_location() {
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
uint32_t bufsize = PATH_MAX;
|
uint32_t bufsize = PATH_MAX;
|
||||||
if (_NSGetExecutablePath(buf, &bufsize) != 0)
|
if (_NSGetExecutablePath(buf, &bufsize) != 0)
|
||||||
throw exception("failed to locate Lean executable location");
|
throw exception("failed to locate Lean executable location");
|
||||||
g_exe_location = buf;
|
return std::string(buf);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// Linux version
|
// Linux version
|
||||||
|
@ -36,7 +36,7 @@ static void init_exe_location() {
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <limits.h> // NOLINT
|
#include <limits.h> // NOLINT
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
static void init_exe_location() {
|
static std::string get_exe_location() {
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char dest[PATH_MAX];
|
char dest[PATH_MAX];
|
||||||
pid_t pid = getpid();
|
pid_t pid = getpid();
|
||||||
|
@ -44,15 +44,22 @@ static void init_exe_location() {
|
||||||
if (readlink(path, dest, PATH_MAX) == -1) {
|
if (readlink(path, dest, PATH_MAX) == -1) {
|
||||||
throw exception("failed to locate Lean executable location");
|
throw exception("failed to locate Lean executable location");
|
||||||
} else {
|
} else {
|
||||||
g_exe_location = dest;
|
return std::string(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
struct init_exe_location_proc {
|
static std::string g_lean_path;
|
||||||
init_exe_location_proc() { init_exe_location(); }
|
struct init_lean_path {
|
||||||
|
init_lean_path() {
|
||||||
|
char * r = getenv("LEAN_PATH");
|
||||||
|
if (r == nullptr)
|
||||||
|
g_lean_path = get_exe_location();
|
||||||
|
else
|
||||||
|
g_lean_path = r;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
static init_exe_location_proc g_init_exe_location_proc;
|
static init_lean_path g_init_lean_path;
|
||||||
char const * get_exe_location() {
|
char const * get_lean_path() {
|
||||||
return g_exe_location.c_str();
|
return g_lean_path.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,5 +6,5 @@ Author: Leonardo de Moura
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
namespace lean {
|
namespace lean {
|
||||||
char const * get_exe_location();
|
char const * get_lean_path();
|
||||||
}
|
}
|
Loading…
Reference in a new issue