diff --git a/generator/mwm_diff/CMakeLists.txt b/generator/mwm_diff/CMakeLists.txt index 45bdc224a8..a5e5901851 100644 --- a/generator/mwm_diff/CMakeLists.txt +++ b/generator/mwm_diff/CMakeLists.txt @@ -12,4 +12,6 @@ target_link_libraries(${PROJECT_NAME} coding ) +add_subdirectory(mwm_diff_tool) + omim_add_test_subdirectory(mwm_diff_tests) diff --git a/generator/mwm_diff/mwm_diff_tool/CMakeLists.txt b/generator/mwm_diff/mwm_diff_tool/CMakeLists.txt new file mode 100644 index 0000000000..9b68cca840 --- /dev/null +++ b/generator/mwm_diff/mwm_diff_tool/CMakeLists.txt @@ -0,0 +1,7 @@ +project(pymwm_diff) + +set(SRC mwm_diff_tool.cpp) + +omim_add_executable(${PROJECT_NAME} ${SRC}) + +target_link_libraries(${PROJECT_NAME} mwm_diff) diff --git a/generator/mwm_diff/mwm_diff_tool/mwm_diff_tool.cpp b/generator/mwm_diff/mwm_diff_tool/mwm_diff_tool.cpp new file mode 100644 index 0000000000..5af6ec2f21 --- /dev/null +++ b/generator/mwm_diff/mwm_diff_tool/mwm_diff_tool.cpp @@ -0,0 +1,32 @@ +#include "generator/mwm_diff/diff.hpp" + +#include "base/cancellable.hpp" + +#include +#include + +using namespace std; + +int main(int argc, char ** argv) +{ + if (argc < 5) + { + cout << "Usage: " << argv[0] << " make|apply olderMWMDir newerMWMDir diffDir\n" + "make\n" + " Creates the diff between newer and older MWM versions at `diffDir`\n" + "apply\n" + " Applies the diff at `diffDir` to the mwm at `olderMWMDir` and stores result at `newerMWMDir`.\n" + "WARNING: THERE IS NO MWM VALIDITY CHECK!\m"; + return -1; + } + const string olderMWMDir{argv[2]}, newerMWMDir{argv[3]}, diffDir{argv[4]}; + if (argv[1] == "make") + return generator::mwm_diff::MakeDiff(olderMWMDir, newerMWMDir, diffDir); + + // apply + base::Cancellable cancellable; + auto const res = generator::mwm_diff::ApplyDiff(olderMWMDir, newerMWMDir, diffDir, cancellable); + if (res == generator::mwm_diff::DiffApplicationResult::Ok) + return 0; + return -1; // Failed, Cancelled. +} diff --git a/generator/mwm_diff/pymwm_diff/CMakeLists.txt b/generator/mwm_diff/pymwm_diff/CMakeLists.txt deleted file mode 100644 index 3244189937..0000000000 --- a/generator/mwm_diff/pymwm_diff/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -project(pymwm_diff) - -set(SRC bindings.cpp) - -omim_add_library(${PROJECT_NAME} MODULE ${SRC}) - -target_link_libraries(${PROJECT_NAME} mwm_diff) \ No newline at end of file diff --git a/generator/mwm_diff/pymwm_diff/bindings.cpp b/generator/mwm_diff/pymwm_diff/bindings.cpp deleted file mode 100644 index 3bdb8ded79..0000000000 --- a/generator/mwm_diff/pymwm_diff/bindings.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "generator/mwm_diff/diff.hpp" - -#include "base/assert.hpp" -#include "base/cancellable.hpp" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wreorder" -#pragma GCC diagnostic ignored "-Wunused-local-typedefs" -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wunused-local-typedef" -#endif - -#include "pyhelpers/module_version.hpp" - -#include - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif -#pragma GCC diagnostic pop - -using namespace std; - -namespace -{ -// Applies the diff at |diffPath| to the mwm at |oldMwmPath|. The resulting -// mwm is stored at |newMwmPath|. -// It is assumed that the file at |oldMwmPath| is a valid mwm and the file -// at |diffPath| is a valid mwmdiff. -// Returns true on success and false on failure. -bool ApplyDiff(string const & oldMwmPath, string const & newMwmPath, string const & diffPath) -{ - base::Cancellable cancellable; - auto const result = generator::mwm_diff::ApplyDiff(oldMwmPath, newMwmPath, diffPath, cancellable); - - switch (result) - { - case generator::mwm_diff::DiffApplicationResult::Ok: - return true; - case generator::mwm_diff::DiffApplicationResult::Failed: - return false; - case generator::mwm_diff::DiffApplicationResult::Cancelled: - UNREACHABLE(); - break; - } - - UNREACHABLE(); -} -} // namespace - -BOOST_PYTHON_MODULE(pymwm_diff) -{ - using namespace boost::python; - scope().attr("__version__") = PYBINDINGS_VERSION; - - def("make_diff", generator::mwm_diff::MakeDiff); - def("apply_diff", ApplyDiff); -} diff --git a/generator/mwm_diff/pymwm_diff/setup.py b/generator/mwm_diff/pymwm_diff/setup.py deleted file mode 100644 index c40b857852..0000000000 --- a/generator/mwm_diff/pymwm_diff/setup.py +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -import os -import sys -module_dir = os.path.abspath(os.path.dirname(__file__)) -sys.path.insert(0, os.path.join(module_dir, '..', '..', '..')) - -from pyhelpers.setup import setup_omim_pybinding - - -NAME = "pymwm_diff" - -setup_omim_pybinding(name=NAME) diff --git a/tools/python/maps_generator/generator/diffs.py b/tools/python/maps_generator/generator/diffs.py index f0bc9d46cf..9b9df202b0 100644 --- a/tools/python/maps_generator/generator/diffs.py +++ b/tools/python/maps_generator/generator/diffs.py @@ -1,13 +1,8 @@ from pathlib import Path +import subprocess import warnings -try: - from pymwm_diff import make_diff -except ImportError: - warnings.warn('No pymwm_diff module found', ImportWarning) - - class Status: NO_NEW_VERSION = "Failed: new version doesn't exist: {new}" INTERNAL_ERROR = "Failed: internal error (C++ module) while calculating" @@ -37,8 +32,8 @@ def calculate_diff(params): if out.exists(): status = Status.NOTHING_TO_DO else: - res = make_diff(old.as_posix(), new.as_posix(), out.as_posix()) - if not res: + res = subprocess.run("mwm_diff_tool " + old.as_posix() + " " + new.as_posix() + " " + out.as_posix()) + if res.returncode != 0: return Status.INTERNAL_ERROR, params diff_size = out.stat().st_size