From d9e360bb95d4fced4974bb716f993c81626417cb Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 11 Jun 2024 17:15:19 +0200 Subject: bugfix: external lib linking --- Builder.cpp | 2 +- file.cpp | 5 +++++ file.h | 1 + test-ymake.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/Builder.cpp b/Builder.cpp index 6fd4f3c..69ecf48 100644 --- a/Builder.cpp +++ b/Builder.cpp @@ -302,7 +302,7 @@ std::unordered_map> Builder::get_dependencies(co fs::path target{get_target(list)}; std::vector deps{get_objects(list)}; std::vector link_libs{link_libs_of(target)}; - std::copy(link_libs.begin(), link_libs.end(), std::back_inserter(deps)); + std::copy_if(link_libs.begin(), link_libs.end(), std::back_inserter(deps), [](const fs::path& p){ return !is_external_lib(p);}); dependencies.emplace(target, deps); // add dynamic lib links diff --git a/file.cpp b/file.cpp index d4c3f54..6211471 100644 --- a/file.cpp +++ b/file.cpp @@ -117,6 +117,11 @@ bool is_static_lib(const std::filesystem::path& p) return p.extension() == ".a"; } +bool is_external_lib(const std::filesystem::path& p) +{ + return !(is_static_lib(p) || is_dynamic_lib(p) || is_dynamic_lib_link(p)); +} + std::filesystem::path simplified_path(const std::filesystem::path& p) { if (p.string().substr(0, 2) == "./") { diff --git a/file.h b/file.h index 972b580..d9a117b 100644 --- a/file.h +++ b/file.h @@ -13,6 +13,7 @@ bool is_executable_target(const std::filesystem::path& p); bool is_dynamic_lib(const std::filesystem::path& p); bool is_dynamic_lib_link(const std::filesystem::path& p); bool is_static_lib(const std::filesystem::path& p); +bool is_external_lib(const std::filesystem::path& p); std::filesystem::path soname_shorter(const std::filesystem::path& p); std::filesystem::path soname_short(const std::filesystem::path& p); std::string dynamic_lib_name(const std::filesystem::path& p); diff --git a/test-ymake.cpp b/test-ymake.cpp index 886a43b..9d6cd43 100644 --- a/test-ymake.cpp +++ b/test-ymake.cpp @@ -937,6 +937,44 @@ extern int hello(); EXPECT_TRUE(!fs::exists("runmain")); } +TEST_F(ymakeTest, use_one_external_lib) +{ + create_file("YMakefile", R"( + + + runmain + runmain.cpp + fmt + + +)"); + + create_file("runmain.cpp", R"( +int main(int argc, char* argv[]) +{ + return 0; +})"); + + std::vector output; + int result = run_command("../ymake", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 2); // compile, link, compile, link + + EXPECT_TRUE(fs::exists("runmain.o")); + EXPECT_TRUE(fs::exists("runmain")); + + result = run_command("./runmain", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 0); + + result = run_command("../ymake clean", output); + EXPECT_EQ(result, 0); + ASSERT_EQ(output.size(), 3); // runmain.o, runmain.d, runmain + + EXPECT_TRUE(!fs::exists("runmain.o")); + EXPECT_TRUE(!fs::exists("runmain")); +} + TEST_F(ymakeTest, use_one_dynamic_lib) { create_file("YMakefile", R"( -- cgit v1.2.3