[generator] Stubs for incremental updates.

This commit is contained in:
Maxim Pimenov 2017-07-25 19:11:18 +03:00 committed by Yuri Gorshenin
parent 1bb30fc057
commit 1ff7d0bf38
8 changed files with 248 additions and 0 deletions

View file

@ -108,6 +108,8 @@ add_library(${PROJECT_NAME} ${SRC})
omim_add_test_subdirectory(generator_tests_support)
omim_add_test_subdirectory(generator_tests)
add_subdirectory(mwm_diff)
if (NOT SKIP_GTOOL)
add_subdirectory(generator_tool)
endif()

View file

@ -0,0 +1,12 @@
project(mwm_diff)
set(
SRC
diff.cpp
diff.hpp
)
add_library(${PROJECT_NAME} ${SRC})
omim_add_pybindings_subdirectory(pymwm_diff)
omim_add_test_subdirectory(mwm_diff_tests)

View file

@ -0,0 +1,56 @@
#include "generator/mwm_diff/diff.hpp"
#include "coding/file_reader.hpp"
#include "coding/file_writer.hpp"
#include "coding/read_write_utils.hpp"
#include "coding/reader.hpp"
#include "base/logging.hpp"
using namespace std;
namespace
{
// We could use my::CopyFileX but it fails if the file at |srcFile| is empty.
bool CopyFile(string const & srcFile, string const & dstFile)
{
size_t constexpr kBufferSize = 1024 * 1024;
try
{
FileReader reader(srcFile, true /* withExceptions */);
ReaderSource<FileReader> src(reader);
FileWriter writer(dstFile);
rw::ReadAndWrite(src, writer, kBufferSize);
}
catch (Reader::Exception const & e)
{
LOG(LERROR, ("Could not read from", srcFile, ":", e.Msg()));
return false;
}
catch (Writer::Exception const & e)
{
LOG(LERROR, ("Could not write to", dstFile, ":", e.Msg()));
return false;
}
return true;
}
} // namespace
namespace generator
{
namespace mwm_diff
{
bool MakeDiff(string const & /* oldMwmPath */, string const & newMwmPath, string const & diffPath)
{
return CopyFile(newMwmPath, diffPath);
}
bool ApplyDiff(string const & /* oldMwmPath */, string const & newMwmPath, string const & diffPath)
{
return CopyFile(diffPath, newMwmPath);
}
} // namespace mwm_diff
} // namespace generator

View file

@ -0,0 +1,24 @@
#pragma once
#include <string>
namespace generator
{
namespace mwm_diff
{
// Makes a diff that, when applied to the mwm at |oldMwmPath|, will
// result in the mwm at |newMwmPath|. The diff is stored at |diffPath|.
// It is assumed that the files at |oldMwmPath| and |newMwmPath| are valid mwms.
// Returns true on success and false on failure.
bool MakeDiff(std::string const & /* oldMwmPath */, std::string const & newMwmPath,
std::string const & diffPath);
// 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(std::string const & /* oldMwmPath */, std::string const & newMwmPath,
std::string const & diffPath);
} // namespace mwm_diff
} // namespace generator

View file

@ -0,0 +1,51 @@
project(mwm_diff_tests)
set(
SRC
diff_test.cpp
)
omim_add_test(${PROJECT_NAME} ${SRC})
omim_link_libraries(
${PROJECT_NAME}
generator_tests_support
platform_tests_support
mwm_diff
generator
drape_frontend
map
routing
search
storage
indexer
drape
traffic
routing_common
editor
platform
geometry
coding
base
freetype
expat
icu
jansson
protobuf
osrm
stats_client
minizip
succinct
pugixml
tess2
gflags
oauthcpp
opening_hours
stb_image
sdf_image
# TODO(syershov): Use FindPackage.
sqlite3
${LIBZ}
)
link_qt5_core(${PROJECT_NAME})

View file

@ -0,0 +1,45 @@
#include "testing/testing.hpp"
#include "generator/mwm_diff/diff.hpp"
#include "platform/platform.hpp"
#include "coding/file_name_utils.hpp"
#include "coding/file_writer.hpp"
#include "coding/internal/file_data.hpp"
#include "base/scope_guard.hpp"
using namespace std;
namespace generator
{
namespace mwm_diff
{
UNIT_TEST(IncrementalUpdates_Smoke)
{
string const oldMwmPath = my::JoinFoldersToPath(GetPlatform().WritableDir(), "minsk-pass.mwm");
string const newMwmPath1 =
my::JoinFoldersToPath(GetPlatform().WritableDir(), "minsk-pass-new1.mwm");
string const newMwmPath2 =
my::JoinFoldersToPath(GetPlatform().WritableDir(), "minsk-pass-new2.mwm");
string const diffPath = my::JoinFoldersToPath(GetPlatform().WritableDir(), "minsk-pass.mwmdiff");
MY_SCOPE_GUARD(cleanup, [&] {
FileWriter::DeleteFileX(newMwmPath1);
FileWriter::DeleteFileX(newMwmPath2);
FileWriter::DeleteFileX(diffPath);
});
{
// Create an empty file.
FileWriter writer(newMwmPath1);
}
TEST(MakeDiff(oldMwmPath, newMwmPath1, diffPath), ());
TEST(ApplyDiff(oldMwmPath, newMwmPath2, diffPath), ());
TEST(my::IsEqualFiles(newMwmPath1, newMwmPath2), ());
}
} // namespace mwm_diff
} // namespace generator

View file

@ -0,0 +1,45 @@
project(pymwm_diff)
set(
SRC
bindings.cpp
)
add_library(${PROJECT_NAME} MODULE ${SRC})
if (PLATFORM_MAC)
omim_link_libraries(
${PROJECT_NAME}
${Qt5Widgets_LIBRARIES}
)
endif()
if (PLATFORM_WIN OR PLATFORM_LINUX)
omim_link_libraries(
${PROJECT_NAME}
${Qt5Widgets_LIBRARIES}
)
endif()
omim_link_libraries(
${PROJECT_NAME}
mwm_diff
indexer
editor
platform
geometry
coding
base
stats_client
jansson
oauthcpp
protobuf
pugixml
opening_hours
icu
${PYTHON_LIBRARIES}
${Boost_LIBRARIES}
${LIBZ}
)
set_target_properties(${PROJECT_NAME} PROPERTIES PREFIX "")

View file

@ -0,0 +1,13 @@
#include "generator/mwm_diff/diff.hpp"
#include <boost/python.hpp>
using namespace std;
BOOST_PYTHON_MODULE(pymwm_diff)
{
using namespace boost::python;
def("make_diff", generator::mwm_diff::MakeDiff);
def("apply_diff", generator::mwm_diff::ApplyDiff);
}