From 12a6cdaa8d2f91e7e48eb031d5744ea43df95118 Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 15:05:22 +0900 Subject: [PATCH 1/7] Ninja: do not link when there is nothing to link This adds a check and early exit before writing the link command --- src/actions/ninja/ninja_cpp.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/actions/ninja/ninja_cpp.lua b/src/actions/ninja/ninja_cpp.lua index ded2fa2c..cb9dcbd6 100644 --- a/src/actions/ninja/ninja_cpp.lua +++ b/src/actions/ninja/ninja_cpp.lua @@ -356,6 +356,10 @@ end libs = ninja.list(libs) .. " " .. ninja.list(tool.getlinkflags(cfg)) walibs = ninja.list(walibs) + if #objfiles + #lddeps == 0 then + return + end + local function writevars() _p(1, "all_ldflags = " .. all_ldflags) _p(1, "libs = " .. libs) From 55282dd8307c61b93a821faaf284f94303169090 Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 15:05:43 +0900 Subject: [PATCH 2/7] GMake: do not link when there is nothing to link This adds a check and early exit before writing the link command --- src/actions/make/make_cpp.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/actions/make/make_cpp.lua b/src/actions/make/make_cpp.lua index 880d9d35..cb8889c6 100644 --- a/src/actions/make/make_cpp.lua +++ b/src/actions/make/make_cpp.lua @@ -463,6 +463,10 @@ lddeps = libdeps end + if #libdeps == 0 and not table.icontains(table.translate(cfg.files, path.issourcefile), true) then + return + end + _p(' ALL_LDFLAGS += $(LDFLAGS)%s', make.list(table.join(cc.getlibdirflags(cfg), cc.getldflags(cfg), cfg.linkoptions))) _p(' LIBDEPS +=%s', libdeps) _p(' LDDEPS +=%s', lddeps) From 156dd249b3c08aa14092f2d34b0ac09fa62f7a7c Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 15:12:54 +0900 Subject: [PATCH 3/7] Ninja/Swift: do not link when there is nothing to link This adds a check and early exit before writing the link command --- src/actions/ninja/ninja_swift.lua | 4 ++++ src/actions/ninja/ninja_swift_incremental.lua | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/actions/ninja/ninja_swift.lua b/src/actions/ninja/ninja_swift.lua index 3e5a93de..221ec96c 100644 --- a/src/actions/ninja/ninja_swift.lua +++ b/src/actions/ninja/ninja_swift.lua @@ -110,6 +110,10 @@ local p = premake function swift.linker(prj, cfg, objfiles, tool) local lddeps = ninja.list(premake.getlinks(cfg, "siblings", "fullpath")) + + if #objfiles + #lddeps == 0 then + return + end if cfg.kind == "StaticLib" then _p("build $target: ar %s | %s ", ninja.list(objfiles), lddeps) diff --git a/src/actions/ninja/ninja_swift_incremental.lua b/src/actions/ninja/ninja_swift_incremental.lua index 2168d18b..609436f9 100644 --- a/src/actions/ninja/ninja_swift_incremental.lua +++ b/src/actions/ninja/ninja_swift_incremental.lua @@ -159,9 +159,13 @@ function swift.linker(prj, cfg, depfiles, tool) _p("build $out_dir/$module_name.swiftmodule | $out_dir/$module_name.swiftdoc: swiftm %s | %s", table.concat(modfiles, " "), table.concat(docfiles, " ")) _p("") - + local output = cfg:getoutputfilename() + if #objfiles + #modfiles + #docfiles == 0 then + return + end + if cfg.kind == "StaticLib" then local ar_flags = ninja.list(tool.getarchiveflags(cfg, cfg, false)) _p("build %s: ar %s | %s $out_dir/$module_name.swiftmodule $out_dir/$module_name.swiftdoc", output, table.concat(objfiles, " "), lddeps) From 5b2d3b4f4125261be44149dcc247fa30dd6f9e10 Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 15:15:26 +0900 Subject: [PATCH 4/7] GMake/Swift: do not link when there is nothing to link This adds a check and early exit before writing the link command --- src/actions/make/make_swift.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/actions/make/make_swift.lua b/src/actions/make/make_swift.lua index 3302c623..3ee680e3 100644 --- a/src/actions/make/make_swift.lua +++ b/src/actions/make/make_swift.lua @@ -120,7 +120,11 @@ function swift.file_rules(prj, objfiles) end function swift.linker(prj, tool) - local lddeps = make.list(premake.getlinks(prj, "siblings", "fullpath")) + local lddeps = make.list(premake.getlinks(prj, "siblings", "fullpath")) + + if #lddeps == 0 and not table.icontains(table.translate(prj.files, path.isswiftfile), true) then + return + end if prj.kind == "StaticLib" then _p("$(TARGET): $(OBJECTS) %s ", lddeps) From 2732a3bc8941287375823e84b850162611fcbefd Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 17:21:36 +0900 Subject: [PATCH 5/7] Ninja/Solution: do not add libs to 'all' if when they don't require linking --- src/actions/ninja/ninja_solution.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/actions/ninja/ninja_solution.lua b/src/actions/ninja/ninja_solution.lua index 3d1e400e..8b87f348 100644 --- a/src/actions/ninja/ninja_solution.lua +++ b/src/actions/ninja/ninja_solution.lua @@ -140,17 +140,22 @@ end cfgs[key] = cfg:getoutputfilename() .. " " if not cfgs["all"] then cfgs["all"] = "" end - cfgs["all"] = cfgs["all"] .. cfg:getoutputfilename() .. " " - -- set first configuration name + -- set first configuration name and 'all' configs to build if (cfg_start == nil) and (cfg.solution.startproject == key) then cfg_start = key end if (cfg_first == nil) and (cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp") then cfg_first = key + cfgs["all"] = cfgs["all"] .. cfg:getoutputfilename() .. " " end if (cfg_first_lib == nil) and (cfg.kind == "StaticLib" or cfg.kind == "SharedLib") then cfg_first_lib = key + + -- only set if there's actually something to build + if table.icontains(table.translate(cfg.files, path.issourcefile), true) then + cfgs["all"] = cfgs["all"] .. cfg:getoutputfilename() .. " " + end end -- include other ninja file From 27fc2cf23b72fd17124b6c0bf7c7d187a2ec8c67 Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 18:10:23 +0900 Subject: [PATCH 6/7] Add premake.projectdoeslink() to check if a project actually has something to link --- src/base/project.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/base/project.lua b/src/base/project.lua index 9e027ff2..18dd1d85 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -393,6 +393,23 @@ end +-- +-- Checks if the project has something to link +-- + + function premake.projectdoeslink(prj, cfgname, platform) + local prjcfg = premake.getconfig(prj, cfgname, platform) + local lnkobj = table.icontains(table.translate(prjcfg.files, path.issourcefile), true) + local lnkdep = false + if prj.kind ~= 'StaticLib' then + lnkdep = table.icontains(table.translate(prjcfg.links, function(lnk) + local link = premake.findproject(lnk) + return premake.projectdoeslink(link, cfgname, platform) + end), true) + end + return lnkobj or lnkdep + end + -- -- Gets the name style for a configuration, indicating what kind of prefix, From 8c3d805b42b035e45f62bc92275886ab9900df8d Mon Sep 17 00:00:00 2001 From: KageKirin Date: Tue, 10 Dec 2019 18:15:58 +0900 Subject: [PATCH 7/7] Add check of whether given project dependencies link when returning list --- src/base/project.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base/project.lua b/src/base/project.lua index 18dd1d85..6fc312a1 100644 --- a/src/base/project.lua +++ b/src/base/project.lua @@ -340,7 +340,7 @@ if prj and kind ~= "system" then local prjcfg = premake.getconfig(prj, cfgname, cfg.platform) - if kind == "dependencies" or canlink(cfg, prjcfg) then + if kind == "dependencies" or canlink(cfg, prjcfg) and premake.projectdoeslink(prj, cfgname, cfg.platform) then if (part == "directory") then item = path.rebase(prjcfg.linktarget.directory, prjcfg.location, cfg.location) elseif (part == "basename") then