Skip to content

Commit

Permalink
更早地计算path
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Feb 27, 2024
1 parent a03be66 commit 3849555
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 23 deletions.
63 changes: 53 additions & 10 deletions scripts/workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ local function push_strings(t, v)
end
end

local function push_path(v, root)
local function path2string(root, v)
local vt = type(v)
if vt == "string" then
return pathutil.tostring(root, v)
Expand Down Expand Up @@ -142,7 +142,7 @@ local function push_args(t, v, root)
end
end

local function push_table(t, a, root, NOLINK)
local function push_table(t, a, NOLINK)
for k, v in pairs(a) do
if type(k) ~= "string" then
goto continue
Expand All @@ -151,14 +151,56 @@ local function push_table(t, a, root, NOLINK)
goto continue
end
if ATTRIBUTE[k] == AttributePlatform then
elseif ATTRIBUTE[k] == AttributePaths or ATTRIBUTE[k] == AttributeArgs or ATTRIBUTE[k] == AttributeStrings then
t[k] = t[k] or {}
push_strings(t[k], v)
if #t[k] == 0 then
t[k] = nil
end
elseif ATTRIBUTE[k] == AttributeGlobs then
t[k] = t[k] or {}
push_globs(t[k], v)
if #t[k] == 0 then
t[k] = nil
end
else
t[k] = v
end
::continue::
end
return t
end

local function push_attributes(t, a, NOLINK)
push_table(t, a, NOLINK)
if a[globals.os] then
push_table(t, a[globals.os], NOLINK)
end
if a[globals.compiler] then
push_table(t, a[globals.compiler], NOLINK)
end
if a.mingw and globals.os == "windows" and globals.hostshell == "sh" then
push_table(t, a.mingw, NOLINK)
end
if a.clang_cl and globals.cc == "clang-cl" then
push_table(t, a.clang_cl, NOLINK)
end
end

local function resolve_table(t, a, root)
for k, v in pairs(a) do
if type(k) ~= "string" then
goto continue
end
if ATTRIBUTE[k] == AttributePlatform then
elseif ATTRIBUTE[k] == AttributePaths then
t[k] = t[k] or {}
push_paths(t[k], v, root)
if #t[k] == 0 then
t[k] = nil
end
elseif ATTRIBUTE[k] == AttributePath then
t[k] = push_path(v, root)
t[k] = path2string(root, v)
elseif ATTRIBUTE[k] == AttributeArgs then
t[k] = t[k] or {}
push_args(t[k], v, root)
Expand All @@ -185,19 +227,19 @@ local function push_table(t, a, root, NOLINK)
return t
end

local function push_attributes(t, a, root, NOLINK)
push_table(t, a, root, NOLINK)
local function resolve_attributes(t, a, root)
resolve_table(t, a, root)
if a[globals.os] then
push_table(t, a[globals.os], root, NOLINK)
resolve_table(t, a[globals.os], root)
end
if a[globals.compiler] then
push_table(t, a[globals.compiler], root, NOLINK)
resolve_table(t, a[globals.compiler], root)
end
if a.mingw and globals.os == "windows" and globals.hostshell == "sh" then
push_table(t, a.mingw, root, NOLINK)
resolve_table(t, a.mingw, root)
end
if a.clang_cl and globals.cc == "clang-cl" then
push_table(t, a.clang_cl, root, NOLINK)
resolve_table(t, a.clang_cl, root)
end
end

Expand All @@ -217,7 +259,7 @@ local function create(workdir, parent, attri)
end
if ATTRIBUTE[k] == AttributePaths then
local t = {}
push_paths(t, parent[k], parent.workdir)
push_strings(t, parent[k])
push_paths(t, v, workdir)
attri[k] = t
elseif ATTRIBUTE[k] == AttributeStrings then
Expand Down Expand Up @@ -268,5 +310,6 @@ end
return {
create = create,
push_attributes = push_attributes,
resolve_attributes = resolve_attributes,
push_strings = push_strings,
}
20 changes: 7 additions & 13 deletions scripts/writer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,21 @@ local function normalize_rootdir(workdir, rootdir)
return fsutil.normalize(workdir, rootdir or ".")
end

local function resolve_rootdir(g, l)
local g_rootdir = normalize_rootdir(g.workdir, g.rootdir)
local l_rootdir = normalize_rootdir(g.workdir, l.rootdir or g.rootdir)
return g_rootdir, l_rootdir
end

local function reslove_attributes(g, l)
local g_rootdir, l_rootdir = resolve_rootdir(g, l)
local l_rootdir = normalize_rootdir(g.workdir, l.rootdir or g.rootdir)
local t = {}
workspace.push_attributes(t, g, g_rootdir)
workspace.push_attributes(t, l, l_rootdir)
workspace.push_attributes(t, g)
workspace.resolve_attributes(t, l, l_rootdir)
t.workdir = g.workdir
t.rootdir = l_rootdir
return t
end

local function reslove_attributes_nolink(g, l)
local g_rootdir, l_rootdir = resolve_rootdir(g, l)
local l_rootdir = normalize_rootdir(g.workdir, l.rootdir or g.rootdir)
local t = {}
workspace.push_attributes(t, g, g_rootdir, true)
workspace.push_attributes(t, l, l_rootdir)
workspace.push_attributes(t, g, true)
workspace.resolve_attributes(t, l, l_rootdir)
t.workdir = g.workdir
t.rootdir = l_rootdir
return t
Expand Down Expand Up @@ -901,7 +895,7 @@ end

function api.conf(global_attribute, attribute)
local root = normalize_rootdir(global_attribute.workdir, attribute.rootdir or global_attribute.rootdir)
workspace.push_attributes(global_attribute, attribute, root)
workspace.resolve_attributes(global_attribute, attribute, root)
end

function api:has(name)
Expand Down

0 comments on commit 3849555

Please sign in to comment.