Skip to content

Commit

Permalink
improve to check snippets in target #4491
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Dec 12, 2023
1 parent deabe00 commit 81feca7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
34 changes: 29 additions & 5 deletions xmake/core/project/target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,30 @@ function _instance:_get_from_source(name, source, result_values, result_sources,
end
end

-- get the checked target, it's only for target:check_xxx api.
--
-- we should not inherit links from deps/packages when checking snippets in on_config,
-- because the target deps has been not built.
--
-- @see https://github.com/xmake-io/xmake/issues/4491
--
function _instance:_checked_target()
local checked_target = self._CHECKED_TARGET
if checked_target == nil then
checked_target = self:clone()
-- we need update target:cachekey(), because target flags may be cached in builder
checked_target:_invalidate()
checked_target.get_from = function (target, name, sources, opt)
if (name == "links" or name == "linkdirs") and sources == "*" then
sources = "self"
end
return _instance.get_from(target, name, sources, opt)
end
self._CHECKED_TARGET = checked_target
end
return checked_target
end

-- clone target, @note we can just call it in after_load()
function _instance:clone()
if not self:_is_loaded() then
Expand Down Expand Up @@ -2606,7 +2630,7 @@ end
--
function _instance:has_features(features, opt)
opt = opt or {}
opt.target = self
opt.target = self:_checked_target()
return sandbox_module.import("core.tool.compiler", {anonymous = true}).has_features(features, opt)
end

Expand All @@ -2619,7 +2643,7 @@ end
--
function _instance:check_sizeof(typename, opt)
opt = opt or {}
opt.target = self
opt.target = self:_checked_target()
return sandbox_module.import("lib.detect.check_sizeof", {anonymous = true})(typename, opt)
end

Expand All @@ -2632,7 +2656,7 @@ end
--
function _instance:check_csnippets(snippets, opt)
opt = opt or {}
opt.target = self
opt.target = self:_checked_target()
return sandbox_module.import("lib.detect.check_csnippets", {anonymous = true})(snippets, opt)
end

Expand All @@ -2658,7 +2682,7 @@ end
--
function _instance:check_msnippets(snippets, opt)
opt = opt or {}
opt.target = self
opt.target = self:_checked_target()
return sandbox_module.import("lib.detect.check_msnippets", {anonymous = true})(snippets, opt)
end

Expand All @@ -2671,7 +2695,7 @@ end
--
function _instance:check_mxxsnippets(snippets, opt)
opt = opt or {}
opt.target = self
opt.target = self:_checked_target()
return sandbox_module.import("lib.detect.check_mxxsnippets", {anonymous = true})(snippets, opt)
end

Expand Down
3 changes: 0 additions & 3 deletions xmake/core/tool/linker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ end

-- add flags from the linker
function linker:_add_flags_from_linker(flags)

-- add flags
local toolkind = self:kind()
for _, flagkind in ipairs(self:_flagkinds()) do

-- attempt to add special lanugage flags first, e.g. gcldflags, dcarflags
table.join2(flags, self:get(toolkind .. 'flags') or self:get(flagkind))
end
Expand Down

0 comments on commit 81feca7

Please sign in to comment.