diff --git a/.github/actions/build-and-test/action.yml b/.github/actions/build-and-test/action.yml index b62fc1048..a19bf1042 100644 --- a/.github/actions/build-and-test/action.yml +++ b/.github/actions/build-and-test/action.yml @@ -16,12 +16,7 @@ runs: - name: configure run: | - CMAKE_OPTIONS="-LA -DBUILD_TESTS=ON" - if [ -z "${LUA_VERSION}" ]; then - CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_LUA=OFF" - else - CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_LUAJIT=${LUAJIT_OPTION}" - fi + CMAKE_OPTIONS="-LA -DBUILD_TESTS=ON -DWITH_LUAJIT=${LUAJIT_OPTION}" if [ -n "$WITH_PROJ" ]; then CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_PROJ=$WITH_PROJ" fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8ee5d005..a0093bd0e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -215,22 +215,6 @@ jobs: - uses: ./.github/actions/ubuntu-prerequisites - uses: ./.github/actions/build-and-test - ubuntu20-pg13-gcc10-release-nolua: - runs-on: ubuntu-20.04 - - env: - CC: gcc-10 - CXX: g++-10 - POSTGRESQL_VERSION: 13 - POSTGIS_VERSION: 2.5 - BUILD_TYPE: Release - PSYCOPG: 2 - - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/ubuntu-prerequisites - - uses: ./.github/actions/build-and-test - ubuntu22-pg16-clang14-jit: runs-on: ubuntu-22.04 @@ -323,23 +307,6 @@ jobs: - uses: ./.github/actions/ubuntu-prerequisites - uses: ./.github/actions/build-and-test - ubuntu22-pg16-gcc12-release-nolua: - runs-on: ubuntu-22.04 - - env: - CC: gcc-12 - CXX: g++-12 - EXTRA_FLAGS: -Wno-stringop-overread - POSTGRESQL_VERSION: 16 - POSTGIS_VERSION: 3 - BUILD_TYPE: Release - PSYCOPG: 2 - - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/ubuntu-prerequisites - - uses: ./.github/actions/build-and-test - ubuntu22-pg16-clang15-cpp20: runs-on: ubuntu-22.04 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cb2708cd..5da692841 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,6 @@ endif() option(BUILD_TESTS "Build test suite" OFF) option(BUILD_COVERAGE "Build with coverage" OFF) -option(WITH_LUA "Build with Lua support" ON) option(WITH_LUAJIT "Build with LuaJIT support" OFF) option(WITH_PROJ "Build with Projection support" ON) @@ -184,23 +183,19 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR}) find_package(Osmium 2.17.3 REQUIRED COMPONENTS io) include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR} ${CLI11_INCLUDE_DIR}) -if (WITH_LUA) - if (WITH_LUAJIT) - message(STATUS "Building with LuaJIT support") - find_package(LuaJIT REQUIRED) - include_directories(SYSTEM ${LUAJIT_INCLUDE_DIR}) - add_definitions(-DHAVE_LUAJIT=1) - else() - message(STATUS "Building with Lua support") - find_package(Lua REQUIRED) - include_directories(SYSTEM ${LUA_INCLUDE_DIR}) - endif() - add_definitions(-DHAVE_LUA=1) - find_program(LUA_EXE NAMES lua lua5.4 lua5.3 lua5.2 lua5.1) +if (WITH_LUAJIT) + message(STATUS "Building with LuaJIT support") + find_package(LuaJIT REQUIRED) + include_directories(SYSTEM ${LUAJIT_INCLUDE_DIR}) + add_definitions(-DHAVE_LUAJIT=1) else() - message(STATUS "Building without Lua support") + message(STATUS "Building with Lua (but not LuaJIT) support") + find_package(Lua REQUIRED) + include_directories(SYSTEM ${LUA_INCLUDE_DIR}) endif() +find_program(LUA_EXE NAMES lua lua5.4 lua5.3 lua5.2 lua5.1) + find_package(Boost 1.50 REQUIRED) include_directories(SYSTEM ${Boost_INCLUDE_DIR}) @@ -235,7 +230,7 @@ endif() if (LUAJIT_FOUND) list(APPEND LIBS ${LUAJIT_LIBRARIES}) -elseif (LUA_FOUND) +else() list(APPEND LIBS ${LUA_LIBRARIES}) endif() @@ -257,28 +252,24 @@ target_link_libraries(osm2pgsql osm2pgsql_lib ${LIBS}) if (${POTRACE_LIBRARY} STREQUAL "POTRACE_LIBRARY-NOTFOUND" OR NOT OPENCV_CORE_FOUND) message(STATUS "Did not find opencv and/or potrace library. Not building osm2pgsql-gen.") else() - if (WITH_LUA) - message(STATUS "Found opencv and potrace library. Building osm2pgsql-gen.") - set(BUILD_GEN 1) - include_directories(SYSTEM ${POTRACE_INCLUDE_DIR}) - add_executable(osm2pgsql-gen src/gen/osm2pgsql-gen.cpp - src/gen/canvas.cpp - src/gen/gen-base.cpp - src/gen/gen-create.cpp - src/gen/gen-discrete-isolation.cpp - src/gen/gen-rivers.cpp - src/gen/gen-tile-builtup.cpp - src/gen/gen-tile-raster.cpp - src/gen/gen-tile-sql.cpp - src/gen/gen-tile-vector.cpp - src/gen/gen-tile.cpp - src/gen/params.cpp - src/gen/raster.cpp - src/gen/tracer.cpp) - target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS}) - else() - message(STATUS "No Lua. Not building osm2pgsql-gen.") - endif() + message(STATUS "Found opencv and potrace library. Building osm2pgsql-gen.") + set(BUILD_GEN 1) + include_directories(SYSTEM ${POTRACE_INCLUDE_DIR}) + add_executable(osm2pgsql-gen src/gen/osm2pgsql-gen.cpp + src/gen/canvas.cpp + src/gen/gen-base.cpp + src/gen/gen-create.cpp + src/gen/gen-discrete-isolation.cpp + src/gen/gen-rivers.cpp + src/gen/gen-tile-builtup.cpp + src/gen/gen-tile-raster.cpp + src/gen/gen-tile-sql.cpp + src/gen/gen-tile-vector.cpp + src/gen/gen-tile.cpp + src/gen/params.cpp + src/gen/raster.cpp + src/gen/tracer.cpp) + target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS}) endif() ############################################################# diff --git a/README.md b/README.md index 0ef1c7100..003c44ede 100644 --- a/README.md +++ b/README.md @@ -53,8 +53,7 @@ Required libraries are * [OpenCV](https://opencv.org/) (Optional, for generalization only) * [potrace](https://potrace.sourceforge.net/) (Optional, for generalization only) * [PostgreSQL](https://www.postgresql.org/) client libraries -* [Lua](https://www.lua.org/) (Optional, used for Lua tag transforms - and the flex output) +* [Lua](https://www.lua.org/) * [Python](https://python.org/) (only for running tests) * [Psycopg](https://www.psycopg.org/) (only for running tests) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9ab722474..83094f608 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,71 +5,67 @@ add_library(osm2pgsql_lib STATIC) # binaries that use it. target_compile_features(osm2pgsql_lib PUBLIC cxx_std_17) +set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS + "${CMAKE_CURRENT_SOURCE_DIR}/init.lua") +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/init.lua" LUA_INIT_CODE) +configure_file(lua-init.cpp.in lua-init.cpp @ONLY) + target_sources(osm2pgsql_lib PRIVATE - command-line-app.cpp - command-line-parser.cpp - db-copy.cpp - debug-output.cpp - expire-tiles.cpp - expire-output.cpp - geom.cpp - geom-box.cpp - geom-from-osm.cpp - geom-functions.cpp - geom-pole-of-inaccessibility.cpp - idlist.cpp - input.cpp - logging.cpp - middle.cpp - middle-pgsql.cpp - middle-ram.cpp - node-locations.cpp - node-persistent-cache.cpp - ordered-index.cpp - osmdata.cpp - output-null.cpp - output-pgsql.cpp - output.cpp - pgsql.cpp - pgsql-capabilities.cpp - pgsql-helper.cpp - progress-display.cpp - properties.cpp - reprojection.cpp - table.cpp - taginfo.cpp - tagtransform-c.cpp - tagtransform.cpp - tile.cpp - thread-pool.cpp - util.cpp - wildcmp.cpp - wkb.cpp + command-line-app.cpp + command-line-parser.cpp + db-copy.cpp + debug-output.cpp + expire-output.cpp + expire-tiles.cpp + flex-index.cpp + flex-lua-expire-output.cpp + flex-lua-geom.cpp + flex-lua-index.cpp + flex-lua-table.cpp + flex-table-column.cpp + flex-table.cpp + flex-write.cpp + geom-box.cpp + geom-from-osm.cpp + geom-functions.cpp + geom-pole-of-inaccessibility.cpp + geom.cpp + idlist.cpp + input.cpp + logging.cpp + lua-setup.cpp + lua-utils.cpp + middle-pgsql.cpp + middle-ram.cpp + middle.cpp + node-locations.cpp + node-persistent-cache.cpp + ordered-index.cpp + osmdata.cpp + output-flex.cpp + output-null.cpp + output-pgsql.cpp + output.cpp + pgsql-capabilities.cpp + pgsql-helper.cpp + pgsql.cpp + progress-display.cpp + properties.cpp + reprojection.cpp + table.cpp + taginfo.cpp + tagtransform-c.cpp + tagtransform-lua.cpp + tagtransform.cpp + thread-pool.cpp + tile.cpp + util.cpp + wildcmp.cpp + wkb.cpp + ${CMAKE_CURRENT_BINARY_DIR}/lua-init.cpp + ${PROJECT_BINARY_DIR}/src/version.cpp ) -if (WITH_LUA) - set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS - "${CMAKE_CURRENT_SOURCE_DIR}/init.lua") - file(READ "${CMAKE_CURRENT_SOURCE_DIR}/init.lua" LUA_INIT_CODE) - configure_file(lua-init.cpp.in lua-init.cpp @ONLY) - target_sources(osm2pgsql_lib PRIVATE - flex-index.cpp - flex-table.cpp - flex-table-column.cpp - flex-lua-expire-output.cpp - flex-lua-geom.cpp - flex-lua-index.cpp - flex-lua-table.cpp - flex-write.cpp - lua-setup.cpp - lua-utils.cpp - output-flex.cpp - tagtransform-lua.cpp - ${CMAKE_CURRENT_BINARY_DIR}/lua-init.cpp) -endif() - -target_sources(osm2pgsql_lib PRIVATE ${PROJECT_BINARY_DIR}/src/version.cpp) - if (HAVE_PROJ6) target_sources(osm2pgsql_lib PRIVATE reprojection-generic-proj6.cpp) else() diff --git a/src/command-line-parser.cpp b/src/command-line-parser.cpp index ee252a358..4f6b575da 100644 --- a/src/command-line-parser.cpp +++ b/src/command-line-parser.cpp @@ -22,9 +22,7 @@ #include -#ifdef HAVE_LUA #include -#endif #include #include @@ -118,15 +116,11 @@ void print_version() fmt::print(stderr, "Compiled using the following library versions:\n"); fmt::print(stderr, "Libosmium {}\n", LIBOSMIUM_VERSION_STRING); fmt::print(stderr, "Proj {}\n", get_proj_version()); -#ifdef HAVE_LUA #ifdef HAVE_LUAJIT fmt::print(stderr, "{} ({})\n", LUA_RELEASE, LUAJIT_VERSION); #else fmt::print(stderr, "{}\n", LUA_RELEASE); #endif -#else - fmt::print(stderr, "Lua support not included\n"); -#endif } static void check_options_non_slim(CLI::App const &app) @@ -446,7 +440,6 @@ options_t parse_command_line(int argc, char *argv[]) ->description("Compute area column using Web Mercator coordinates.") ->group("Pgsql output options"); -#ifdef HAVE_LUA // --tag-transform-script app.add_option("--tag-transform-script", options.tag_transform_script) ->description( @@ -454,7 +447,6 @@ options_t parse_command_line(int argc, char *argv[]) ->option_text("SCRIPT") ->check(CLI::ExistingFile) ->group("Pgsql output options"); -#endif // ---------------------------------------------------------------------- // Expire options diff --git a/src/output.cpp b/src/output.cpp index f4b50b417..da3490114 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -12,16 +12,10 @@ #include "db-copy.hpp" #include "format.hpp" #include "options.hpp" +#include "output-flex.hpp" #include "output-null.hpp" #include "output-pgsql.hpp" -#ifdef HAVE_LUA -# include "output-flex.hpp" -static constexpr char const *const flex_backend = "flex, "; -#else -static constexpr char const *const flex_backend = ""; -#endif - #include #include #include @@ -36,12 +30,10 @@ output_t::create_output(std::shared_ptr const &mid, options); } -#ifdef HAVE_LUA if (options.output_backend == "flex") { return std::make_shared(mid, std::move(thread_pool), options); } -#endif if (options.output_backend == "null") { return std::make_shared(mid, std::move(thread_pool), @@ -49,8 +41,8 @@ output_t::create_output(std::shared_ptr const &mid, } throw fmt_error("Output backend '{}' not recognised. Should be one of" - " [pgsql, {}null].", - options.output_backend, flex_backend); + " [pgsql, flex, null].", + options.output_backend); } output_t::output_t(std::shared_ptr mid, diff --git a/src/tagtransform.cpp b/src/tagtransform.cpp index 4fef20387..41c25ffdc 100644 --- a/src/tagtransform.cpp +++ b/src/tagtransform.cpp @@ -7,14 +7,12 @@ * For a full list of authors see the git log. */ +#include "tagtransform.hpp" + #include "logging.hpp" #include "options.hpp" #include "tagtransform-c.hpp" -#include "tagtransform.hpp" - -#ifdef HAVE_LUA #include "tagtransform-lua.hpp" -#endif #include #include @@ -24,16 +22,10 @@ tagtransform_t::make_tagtransform(options_t const *options, export_list const &exlist) { if (!options->tag_transform_script.empty()) { -#ifdef HAVE_LUA log_debug("Using lua based tag transformations with script {}", options->tag_transform_script); return std::make_unique( &options->tag_transform_script, options->extra_attributes); -#else - throw std::runtime_error{"Error: Could not init lua tag transform, as " - "lua support was not compiled into this " - "version."}; -#endif } log_debug("Using built-in tag transformations"); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6e293eb2b..3e85a303b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -39,11 +39,12 @@ add_library(catch_main_lib STATIC catch-main.cpp) target_compile_features(catch_main_lib PUBLIC cxx_std_17) set_test(test-check-input LABELS NoDB) -set_test(test-db-copy-thread) set_test(test-db-copy-mgr) +set_test(test-db-copy-thread) set_test(test-domain-matcher LABELS NoDB) set_test(test-expire-from-geometry LABELS NoDB) set_test(test-expire-tiles LABELS NoDB) +set_test(test-flex-indexes) set_test(test-geom-box LABELS NoDB) set_test(test-geom-collections LABELS NoDB) set_test(test-geom-linestrings LABELS NoDB) @@ -53,16 +54,29 @@ set_test(test-geom-multipolygons LABELS NoDB) set_test(test-geom-null LABELS NoDB) set_test(test-geom-output LABELS NoDB) set_test(test-geom-points LABELS NoDB) -set_test(test-geom-polygons LABELS NoDB) set_test(test-geom-pole-of-inaccessibility LABELS NoDB) +set_test(test-geom-polygons LABELS NoDB) set_test(test-geom-transform LABELS NoDB) set_test(test-json-writer LABELS NoDB) +set_test(test-lua-utils) set_test(test-middle) set_test(test-node-locations LABELS NoDB) set_test(test-options-parse LABELS NoDB) set_test(test-options-projection) set_test(test-ordered-index LABELS NoDB) set_test(test-osm-file-parsing LABELS NoDB) +set_test(test-output-flex) +set_test(test-output-flex-multi-input) +set_test(test-output-flex-nodes) +set_test(test-output-flex-relation-combinations) +set_test(test-output-flex-relations) +set_test(test-output-flex-schema) +set_test(test-output-flex-stage2) +set_test(test-output-flex-tablespace LABELS Tablespace) +set_test(test-output-flex-types) +set_test(test-output-flex-uni) +set_test(test-output-flex-update) +set_test(test-output-flex-validgeom) set_test(test-output-pgsql) set_test(test-output-pgsql-area) set_test(test-output-pgsql-hstore-match-only) @@ -83,29 +97,10 @@ set_test(test-util LABELS NoDB) set_test(test-wildcard-match LABELS NoDB) set_test(test-wkb LABELS NoDB) -# these tests require LUA support -if (WITH_LUA) - set_test(test-flex-indexes) - set_test(test-lua-utils) - set_test(test-output-flex) - set_test(test-output-flex-multi-input) - set_test(test-output-flex-nodes) - set_test(test-output-flex-uni) - set_test(test-output-flex-relations) - set_test(test-output-flex-relation-combinations) - set_test(test-output-flex-schema) - set_test(test-output-flex-stage2) - set_test(test-output-flex-tablespace LABELS Tablespace) - set_test(test-output-flex-types) - set_test(test-output-flex-update) - set_test(test-output-flex-validgeom) - - set_test(test-output-flex-example-configs) - set(FLEX_EXAMPLE_CONFIGS "addresses,attributes,bbox,compatible,data-types,expire,generic,geometries,indexes,places,route-relations,simple,unitable") - # with-schema.lua is not tested because it needs the schema created in the database - set_tests_properties(test-output-flex-example-configs PROPERTIES ENVIRONMENT "EXAMPLE_FILES=${FLEX_EXAMPLE_CONFIGS}") -endif() - +set_test(test-output-flex-example-configs) +set(FLEX_EXAMPLE_CONFIGS "addresses,attributes,bbox,compatible,data-types,expire,generic,geometries,indexes,places,route-relations,simple,unitable") +# with-schema.lua is not tested because it needs the schema created in the database +set_tests_properties(test-output-flex-example-configs PROPERTIES ENVIRONMENT "EXAMPLE_FILES=${FLEX_EXAMPLE_CONFIGS}") # Fixture for creating test tablespace under a pg_virtualenv if (NOT WIN32) @@ -138,13 +133,11 @@ else() message(WARNING "Cannot find behave, BDD tests disabled") endif() -if (WITH_LUA) - if (LUA_EXE) - message(STATUS "Added test: lua-lib") - add_test(NAME lua-lib COMMAND ${LUA_EXE} lua/tests.lua - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) - set_tests_properties(lua-lib PROPERTIES LABELS NoDB) - else() - message(WARNING "Can not find Lua interpreter, test 'lua-lib' disabled") - endif() +if (LUA_EXE) + message(STATUS "Added test: lua-lib") + add_test(NAME lua-lib COMMAND ${LUA_EXE} lua/tests.lua + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + set_tests_properties(lua-lib PROPERTIES LABELS NoDB) +else() + message(WARNING "Can not find Lua interpreter, test 'lua-lib' disabled") endif() diff --git a/tests/test-options-parse.cpp b/tests/test-options-parse.cpp index be9b4971f..6ac4505b3 100644 --- a/tests/test-options-parse.cpp +++ b/tests/test-options-parse.cpp @@ -66,10 +66,8 @@ TEST_CASE("Middle selection", "[NoDB]") TEST_CASE("Lua styles", "[NoDB]") { -#ifdef HAVE_LUA REQUIRE_THROWS_WITH(opt({"--tag-transform-script", "non_existing.lua"}), Catch::Matchers::Contains("File does not exist")); -#endif } TEST_CASE("Parsing bbox", "[NoDB]")