summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Builder.cpp2
-rw-r--r--file.cpp5
-rw-r--r--file.h1
-rw-r--r--test-ymake.cpp38
4 files changed, 45 insertions, 1 deletions
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<fs::path, std::vector<fs::path>> Builder::get_dependencies(co
fs::path target{get_target(list)};
std::vector<fs::path> deps{get_objects(list)};
std::vector<fs::path> 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"(
+<ymake>
+ <build>
+ <name>runmain</name>
+ <source>runmain.cpp</source>
+ <linklib>fmt</linklib>
+ </build>
+</ymake>
+)");
+
+ create_file("runmain.cpp", R"(
+int main(int argc, char* argv[])
+{
+ return 0;
+})");
+
+ std::vector<std::string> 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"(