Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Path Schema Ordered updates#230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,14 +26,14 @@ namespace buildcc {
class CustomGeneratorContext {
public:
CustomGeneratorContext(const env::Command &c,
const std::unordered_set<std::string> &i,
const std::unordered_set<std::string> &o,
const std::vector<std::string> &i,
const std::vector<std::string> &o,
const std::vector<uint8_t> &ub)
: command(c), inputs(i), outputs(o), userblob(ub) {}

const env::Command &command;
const std::unordered_set<std::string> &inputs;
const std::unordered_set<std::string> &outputs;
const std::vector<std::string> &inputs;
const std::vector<std::string> &outputs;
const std::vector<uint8_t> &userblob;
};

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -375,7 +375,7 @@ TEST(CustomGeneratorTestGroup, RealGenerate_Update_Success) {
CHECK_EQUAL(imap.at("id2").outputs.GetPaths().size(), 1);

STRCMP_EQUAL(std::to_string(last_write_timestamp).c_str(),
imap.at("id2").inputs.GetPathInfos().begin()->second.c_str());
imap.at("id2").inputs.GetPathInfos()[0].hash.c_str());

CHECK(buildcc::env::get_task_state() == buildcc::env::TaskState::SUCCESS);
}
Expand Down
8 changes: 8 additions & 0 deletionsbuildcc/schema/cmake/schema.cmake
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,6 +31,11 @@ if (${TESTING})
target_link_options(mock_schema PUBLIC ${TEST_LINK_FLAGS} ${BUILD_LINK_FLAGS})

# Tests
add_executable(test_path_schema
test/test_path_schema.cpp
)
target_link_libraries(test_path_schema PRIVATE mock_schema)

add_executable(test_custom_generator_serialization
test/test_custom_generator_serialization.cpp
)
Expand All@@ -41,6 +46,9 @@ if (${TESTING})
)
target_link_libraries(test_target_serialization PRIVATE mock_schema)

add_test(NAME test_path_schema COMMAND test_path_schema
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
add_test(NAME test_custom_generator_serialization COMMAND test_custom_generator_serialization
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test
)
Expand Down
78 changes: 48 additions & 30 deletionsbuildcc/schema/include/schema/path.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,8 +103,7 @@ struct Path {
*/
static std::string ToPathString(const std::string &str) {
auto path_str = str;
std::replace(path_str.begin(), path_str.end(), '\\', '/');
path_str = fs::path(path_str).lexically_normal().string();
path_str = fs::path(path_str).make_preferred().lexically_normal().string();
return path_str;
}

Expand DownExpand Up@@ -189,11 +188,11 @@ class PathList {

void Emplace(const std::string &pstr) {
auto path_str = Path::ToPathString(pstr);
paths_.emplace(std::move(path_str));
paths_.emplace_back(std::move(path_str));
}

bool IsEqual(const PathList &other) const { return paths_ == other.paths_; }
const std::unordered_set<std::string> &GetPaths() const { return paths_; }
const std::vector<std::string> &GetPaths() const { return paths_; }

friend void to_json(json &j, const PathList &plist) { j = plist.paths_; }

Expand All@@ -202,7 +201,7 @@ class PathList {
}

private:
std::unordered_set<std::string> paths_;
std::vector<std::string> paths_;
};

/**
Expand All@@ -211,10 +210,34 @@ class PathList {
*/
class PathInfoList {
private:
static constexpr const char *const kPath = "path";
static constexpr const char *const kHash = "hash";

public:
struct PathInfo {
private:
static constexpr const char *const kPath = "path";
static constexpr const char *const kHash = "hash";

public:
PathInfo() = default;
PathInfo(const std::string &p, const std::string &h) : path(p), hash(h) {}

bool operator==(const PathInfo &other) const {
return ((path == other.path) && (hash == other.hash));
}

friend void to_json(json &j, const PathInfo &info) {
j[kPath] = info.path;
j[kHash] = info.hash;
}

friend void from_json(const json &j, PathInfo &info) {
j.at(kPath).get_to(info.path);
j.at(kHash).get_to(info.hash);
}

std::string path;
std::string hash;
};

PathInfoList() = default;
explicit PathInfoList(
std::initializer_list<std::pair<const std::string, std::string>>
Expand All@@ -226,34 +249,31 @@ class PathInfoList {

void Emplace(const std::string &pstr, const std::string &hash) {
auto path_str = Path::ToPathString(pstr);
path_infos_.emplace(std::move(path_str), hash);
infos_.emplace_back(PathInfo(path_str, hash));
}

voidComputeHashForAll() {
for (auto &[path_str, hash] : path_infos_) {
hash = ComputeHash(path_str);
voidInsert(const PathInfoList &other) {
for (constauto &info : other.infos_) {
Emplace(info.path, info.hash);
}
}

const std::string &GetHash(const std::string &str) const {
auto path_str = Path::ToPathString(str);
const bool found = path_infos_.find(path_str) != path_infos_.end();
env::assert_fatal(found, "");
return path_infos_.at(path_str);
void ComputeHashForAll() {
for (auto &info : infos_) {
info.hash = ComputeHash(info.path);
}
}

bool IsEqual(const PathInfoList &other) const {
returnpath_infos_ == other.path_infos_;
returninfos_ == other.infos_;
}

const std::unordered_map<std::string, std::string> &GetPathInfos() const {
return path_infos_;
}
const std::vector<PathInfo> &GetPathInfos() const { return infos_; }

std::unordered_set<std::string> GetPaths() const {
std::unordered_set<std::string> paths;
for (const auto &[path_str, hash] : path_infos_) {
paths.emplace(path_str);
std::vector<std::string> GetPaths() const {
std::vector<std::string> paths;
for (const auto &info : infos_) {
paths.emplace_back(info.path);
}
return paths;
}
Expand All@@ -274,16 +294,14 @@ class PathInfoList {
return std::to_string(last_write_timestamp);
}

friend void to_json(json &j, const PathInfoList &plist) {
j = plist.path_infos_;
}
friend void to_json(json &j, const PathInfoList &plist) { j = plist.infos_; }

friend void from_json(const json &j, PathInfoList &plist) {
j.get_to(plist.path_infos_);
j.get_to(plist.infos_);
}

private:
std::unordered_map<std::string, std::string> path_infos_;
std::vector<PathInfo> infos_;
};

// TODO, Remove this
Expand Down
132 changes: 132 additions & 0 deletionsbuildcc/schema/test/test_path_schema.cpp
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
// Internal
#include "schema/path.h"

#include "env/host_os.h"

// NOTE, Make sure all these includes are AFTER the system and header includes
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTest/MemoryLeakDetectorNewMacros.h"
#include "CppUTest/TestHarness.h"
#include "CppUTest/Utest.h"

// clang-format off
TEST_GROUP(PathSchemaTestGroup)
{
};
// clang-format on

TEST(PathSchemaTestGroup, PathList) { buildcc::internal::PathList paths; }

TEST(PathSchemaTestGroup, Path_ToPathString) {
auto path_str = buildcc::internal::Path::ToPathString("hello/\\first.txt");

if constexpr (buildcc::env::is_win()) {
STRCMP_EQUAL("hello\\first.txt", path_str.c_str());
} else if constexpr (buildcc::env::is_linux() || buildcc::env::is_mac() ||
buildcc::env::is_unix()) {
STRCMP_EQUAL("hello/\\first.txt", path_str.c_str());
} else {
FAIL("Operating system not supported");
}
}

TEST(PathSchemaTestGroup, PathInfoList_OrderedEmplace) {
buildcc::internal::PathInfoList path_infos;

path_infos.Emplace("hello/world/first_file.txt", "");
path_infos.Emplace("hello/world/second_file.txt", "");
path_infos.Emplace("hello/world/third_file.txt", "");
path_infos.Emplace("hello/world/fourth_file.txt", "");

std::vector<std::string> paths;
if constexpr (buildcc::env::is_win()) {
paths = {
"hello\\world\\first_file.txt",
"hello\\world\\second_file.txt",
"hello\\world\\third_file.txt",
"hello\\world\\fourth_file.txt",
};
} else if constexpr (buildcc::env::is_linux() || buildcc::env::is_unix() ||
buildcc::env::is_mac()) {
paths = {
"hello/world/first_file.txt",
"hello/world/second_file.txt",
"hello/world/third_file.txt",
"hello/world/fourth_file.txt",
};
} else {
FAIL("Operating system not supported");
}

auto inserted_paths = path_infos.GetPaths();
for (std::size_t i = 0; i < inserted_paths.size(); i++) {
STRCMP_EQUAL(paths[i].c_str(), inserted_paths[i].c_str());
}

json j = path_infos;
UT_PRINT(j.dump().c_str());
}

TEST(PathSchemaTestGroup, PathInfoList_GetChanged) {
{
buildcc::internal::PathInfoList pinfolist1{
{"first.txt", "1"},
{"second.txt", "2"},
{"third.txt", "3"},
};
buildcc::internal::PathInfoList pinfolist2{
{"first.txt", "1"},
{"second.txt", "2"},
{"third.txt", "3"},
};
CHECK_TRUE(pinfolist1.IsEqual(pinfolist2));
}

// Missing path info
{
buildcc::internal::PathInfoList pinfolist1{
{"first.txt", "1"},
{"second.txt", "2"},
{"third.txt", "3"},
};
buildcc::internal::PathInfoList pinfolist2{
{"first.txt", "1"}, {"second.txt", "2"},
// {"third.txt", "3"},
};
CHECK_FALSE(pinfolist1.IsEqual(pinfolist2));
}

// Wrong hash
{
buildcc::internal::PathInfoList pinfolist1{
{"first.txt", "1"},
{"second.txt", "2"},
{"third.txt", "3"},
};
buildcc::internal::PathInfoList pinfolist2{
{"first.txt", "1"},
{"second.txt", "2"},
{"third.txt", "4"},
};
CHECK_FALSE(pinfolist1.IsEqual(pinfolist2));
}

// Wrong order
{
buildcc::internal::PathInfoList pinfolist1{
{"first.txt", "1"},
{"second.txt", "2"},
{"third.txt", "3"},
};
buildcc::internal::PathInfoList pinfolist2{
{"first.txt", "1"},
{"third.txt", "3"},
{"second.txt", "2"},
};
CHECK_FALSE(pinfolist1.IsEqual(pinfolist2));
}
}

int main(int ac, char **av) {
return CommandLineTestRunner::RunAllTests(ac, av);
}

[8]ページ先頭

©2009-2025 Movatter.jp