diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a6a74b5180a6981f335c52389af4ab4e62d55f1b..20236de05aaca3577480258e60f128c0d0237e8a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -69,7 +69,8 @@ test: - mkdir build - cd build - cmake -DENABLE_TESTS=ON -DCMAKE_CXX_FLAGS="-coverage" -DCMAKE_EXE_LINKER_FLAGS="-coverage" ../ - - make -j`nproc` all runtests install + # Do not install AOFlagger in this job. The tests should still run. + - make -j`nproc` all runtests - ctest artifacts: paths: diff --git a/CMakeLists.txt b/CMakeLists.txt index 14d3fc46978a61ee145b427fea34fbc6dbb7569d..f459281ace61e00b2942be73b7797910fb3575c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -381,6 +381,25 @@ set(ALL_NON_GUI_FILES add_library(aoflagger-lib SHARED ${ALL_NON_GUI_FILES}) set_target_properties(aoflagger-lib PROPERTIES SOVERSION 0) set_target_properties(aoflagger-lib PROPERTIES OUTPUT_NAME aoflagger) +if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY) + # By default, CMAKE_LIBRARY_OUTPUT_DIRECTORY is not defined. -> Store + # libaoflagger.so in lib/ and add the strategies in lib/aoflagger/strategies, + # so libaoflagger can find them. Using the current directory is not possible, + # since it already contains the 'aoflagger' binary, which has the same name as + # the 'aoflagger' directory. + file(MAKE_DIRECTORY lib/aoflagger) + file(COPY data/strategies DESTINATION lib/aoflagger) + set_target_properties(aoflagger-lib PROPERTIES LIBRARY_OUTPUT_DIRECTORY lib) +else() + # When CMAKE_LIBRARY_OUTPUT_DIRECTORY is set, ensure that libaoflagger.so can + # find the strategy files by adding them to that directory. (When building a + # python binary wheel, this copy is not necessary even though setup.py uses + # CMAKE_LIBRARY_OUTPUT_DIRECTORY: setup.py copies the original strategy files + # into the wheel.) + file(MAKE_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/aoflagger) + file(COPY data/strategies + DESTINATION ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/aoflagger) +endif() target_link_libraries(aoflagger-lib ${ALL_LIBRARIES}) # When building a docker image for an application that uses AOFlagger, like DP3, # the 'core_library' component allows installing only the core library using: @@ -609,7 +628,7 @@ if(ENABLE_TESTS) "${NAME}" PROPERTIES DEPENDS concatenate_frequency_integration_test_ms DEPENDS aoflagger ENVIRONMENT - PYTHONPATH=${CMAKE_BINARY_DIR}/python:${PYTHONPATH}) + PYTHONPATH=${CMAKE_BINARY_DIR}/python:$ENV{PYTHONPATH}) endforeach() endfunction() diff --git a/aoluarunner/runner.cpp b/aoluarunner/runner.cpp index b1be056daaa9b6822ad556abace5ed825694c84c..184f0d602b2e6f15e101786f5b18295190af5bc3 100644 --- a/aoluarunner/runner.cpp +++ b/aoluarunner/runner.cpp @@ -90,7 +90,7 @@ void Runner::loadStrategy( << "using the rfigui and specify it with the '-strategy " "...' parameter.\n\n"; } - executeFilename = TelescopeFile::FindStrategy("", telescopeId); + executeFilename = TelescopeFile::FindStrategy(telescopeId); if (executeFilename.empty()) { throw std::runtime_error("Could not find a strategy for telescope " + TelescopeFile::TelescopeName(telescopeId) + diff --git a/interface/aoflagger.cpp b/interface/aoflagger.cpp index 3fcfc87492d4154e1e9dda47f21074ae9d9773ff..066d98387acb62cd40f5d675a52f5c664e8337fe 100644 --- a/interface/aoflagger.cpp +++ b/interface/aoflagger.cpp @@ -9,7 +9,7 @@ namespace aoflagger { std::string AOFlagger::FindStrategyFile(enum TelescopeId telescopeId, const std::string& scenario) { return TelescopeFile::FindStrategy( - "", static_cast<TelescopeFile::TelescopeId>(telescopeId), scenario); + static_cast<TelescopeFile::TelescopeId>(telescopeId), scenario); } QualityStatistics AOFlagger::MakeQualityStatistics( diff --git a/lua/telescopefile.cpp b/lua/telescopefile.cpp index ea573114b6763b863bb71706e65c3c779faa2f49..7b4a9141d90d119f0ab2a65f8c10efaee8eafe43 100644 --- a/lua/telescopefile.cpp +++ b/lua/telescopefile.cpp @@ -1,5 +1,10 @@ #include "telescopefile.h" +#include <dlfcn.h> +#include <filesystem> + +#include <boost/algorithm/string/case_conv.hpp> + #include "../imagesets/bhfitsimageset.h" #include "../imagesets/filterbankset.h" #include "../imagesets/fitsimageset.h" @@ -8,10 +13,6 @@ #include "../structures/msmetadata.h" -#include <boost/algorithm/string/case_conv.hpp> - -#include <filesystem> - #include <version.h> std::string TelescopeFile::TelescopeName( @@ -105,8 +106,7 @@ TelescopeFile::TelescopeId TelescopeFile::TelescopeIdFromName( return GENERIC_TELESCOPE; } -std::string TelescopeFile::FindStrategy(const std::string& argv0, - enum TelescopeId telescopeId, +std::string TelescopeFile::FindStrategy(enum TelescopeId telescopeId, const std::string& scenario) { std::string filename = boost::to_lower_copy(TelescopeName(telescopeId)); if (scenario.empty()) @@ -120,14 +120,14 @@ std::string TelescopeFile::FindStrategy(const std::string& argv0, "share/aoflagger/strategies" / filename; if (std::filesystem::exists(search)) return search.string(); - if (!argv0.empty()) { - const std::filesystem::path root = - std::filesystem::path(argv0).remove_filename(); - - search = root / "../share/aoflagger/strategies" / filename; - if (std::filesystem::exists(search)) return search.string(); - - search = root / "../data/strategies" / filename; + // Try using the directory of the AOFlagger library. + // When bundled as a python binary wheel, the strategies are there. + Dl_info dl_info; + if (dladdr(reinterpret_cast<const void*>(&TelescopeFile::FindStrategy), + &dl_info)) { + std::filesystem::path aoflagger_library_path(dl_info.dli_fname); + search = aoflagger_library_path.remove_filename() / "aoflagger/strategies" / + filename; if (std::filesystem::exists(search)) return search.string(); } diff --git a/lua/telescopefile.h b/lua/telescopefile.h index ce7ce3dc866fcbefc7b4a6a383c7d19123b2ee1b..738264e9fdc09b86c1bdd21de19c568656550a2a 100644 --- a/lua/telescopefile.h +++ b/lua/telescopefile.h @@ -39,16 +39,13 @@ class TelescopeFile { /** * @brief Searches a strategy for a given telescope. * - * @param argv0 The argv[0] variable passed to main(), or empty if it is not - * available. * @param telescopeId One of the telescopes, if known, otherwise * GENERIC_TELESCOPE. * @param scenario Used as 'suffix' to the name of the telescope. This allows * multiple versions for the same telescope. * @returns Path to the strategy, or empty string if not found. */ - static std::string FindStrategy(const std::string& argv0, - enum TelescopeId telescopeId, + static std::string FindStrategy(enum TelescopeId telescopeId, const std::string& scenario = ""); static std::string TelescopeName(TelescopeFile::TelescopeId telescopeId); diff --git a/rfigui/rfiguiwindow.cpp b/rfigui/rfiguiwindow.cpp index 0123c3f6ddb37db7d942c7790937c026f55c50c1..bf34f4353326d41f6f9771f2a706e41c2251e208 100644 --- a/rfigui/rfiguiwindow.cpp +++ b/rfigui/rfiguiwindow.cpp @@ -1302,7 +1302,7 @@ void RFIGuiWindow::onStrategyOpenDefault(const std::string& name) { if (askToSaveChanges()) { const TelescopeFile::TelescopeId id = TelescopeFile::TelescopeIdFromName(name); - const std::string filename = TelescopeFile::FindStrategy("", id); + const std::string filename = TelescopeFile::FindStrategy(id); if (filename.empty()) showError("Could not find default strategy file for telescope '" + name + "' -- aoflagger is probably not installed properly"); diff --git a/test/lua/telescopefiletest.cpp b/test/lua/telescopefiletest.cpp index f914d514f642c9f050ea2a6880ad677d16e6dd34..8c139b02726e17eac4556c9bfe4f7f3ef6259b25 100644 --- a/test/lua/telescopefiletest.cpp +++ b/test/lua/telescopefiletest.cpp @@ -8,28 +8,21 @@ BOOST_AUTO_TEST_SUITE(strategy_files, *boost::unit_test::label("lua")) BOOST_AUTO_TEST_CASE(find_strategy) { - std::filesystem::path argv0 = std::filesystem::current_path() / "aoflagger"; - auto all = TelescopeFile::List(); for (TelescopeFile::TelescopeId telescope : all) { - std::string path = - TelescopeFile::FindStrategy(argv0.string(), telescope, ""); + std::string path = TelescopeFile::FindStrategy(telescope); BOOST_CHECK_NE(path, ""); } } BOOST_AUTO_TEST_CASE(find_non_existing_strategy) { - std::filesystem::path argv0 = std::filesystem::current_path() / "aoflagger"; - std::string nonExisting = TelescopeFile::FindStrategy( - argv0.string(), TelescopeFile::GENERIC_TELESCOPE, "_NonExisting"); + TelescopeFile::GENERIC_TELESCOPE, "_NonExisting"); BOOST_CHECK_EQUAL(nonExisting, ""); } void runStrategy(TelescopeFile::TelescopeId telescope, const std::string& strategy_scenario = {}) { - std::filesystem::path argv0 = std::filesystem::current_path() / "aoflagger"; - aoflagger::AOFlagger flagger; const size_t pols = 8, width = 7, height = 10; aoflagger::ImageSet imageSet = flagger.MakeImageSet(width, height, pols); @@ -56,8 +49,7 @@ void runStrategy(TelescopeFile::TelescopeId telescope, imageSet.ImageBuffer(rfiP) + rfiY * imageSet.HorizontalStride() + rfiX; *rfiPixel = 1000.0; - std::string path = - TelescopeFile::FindStrategy(argv0.string(), telescope, strategy_scenario); + std::string path = TelescopeFile::FindStrategy(telescope, strategy_scenario); BOOST_CHECK(!path.empty()); aoflagger::Strategy strategy = flagger.LoadStrategyFile(path); aoflagger::FlagMask mask = strategy.Run(imageSet);