diff options
| author | ruki <[email protected]> | 2020-10-24 00:50:22 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-10-24 00:50:22 +0800 |
| commit | 1d192142d27973332edae50e0b1c4a37080ea65f (patch) | |
| tree | 6a7e434741cc85aec6ff9c2d23bd7f1485fb305c | |
| parent | d0ae5c6e46a2a90974b6dd478464e77453fe3352 (diff) | |
fetch cflags and ldflags
| -rw-r--r-- | xmake/actions/require/fetch.lua | 57 | ||||
| -rw-r--r-- | xmake/actions/require/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/fetch.lua | 17 |
3 files changed, 70 insertions, 7 deletions
diff --git a/xmake/actions/require/fetch.lua b/xmake/actions/require/fetch.lua index eb125eb53..da4157226 100644 --- a/xmake/actions/require/fetch.lua +++ b/xmake/actions/require/fetch.lua @@ -19,17 +19,12 @@ -- -- imports -import("core.base.task") import("core.base.option") import("core.base.hashset") import("core.project.project") import("core.package.package", {alias = "core_package"}) -import("devel.git") -import("utils.archive") -import("impl.utils.filter") import("impl.package") import("impl.repository") -import("impl.environment") import("impl.utils.get_requires") -- fetch the given package info @@ -42,10 +37,21 @@ function main(requires_raw) return end + -- get the fetching modes + local fetchmodes = option.get("fetch_modes") + if fetchmodes then + fetchmodes = hashset.from(fetchmodes:split(',', {plain = true})) + end + -- fetch all packages local fetchinfos = {} for _, instance in ipairs(package.load_packages(requires, {requires_extra = requires_extra})) do - local fetchinfo = instance:fetch() + local fetchinfo + if fetchmodes and fetchmodes:has("deps") then + fetchinfo = instance:fetchdeps() + else + fetchinfo = instance:fetch() + end if fetchinfo then table.insert(fetchinfos, fetchinfo) end @@ -53,7 +59,44 @@ function main(requires_raw) -- show results if #fetchinfos > 0 then - print(fetchinfos) + local flags = {} + if fetchmodes:has("cflags") then + for _, fetchinfo in ipairs(fetchinfos) do + for _, includedir in ipairs(fetchinfo.includedirs) do + table.insert(flags, "-I" .. os.args(includedir)) + end + for _, define in ipairs(fetchinfo.defines) do + table.insert(flags, "-D" .. define) + end + for _, cflag in ipairs(fetchinfo.cflags) do + table.insert(flags, cflag) + end + for _, cxflag in ipairs(fetchinfo.cxflags) do + table.insert(flags, cxflag) + end + for _, cxxflag in ipairs(fetchinfo.cxxflags) do + table.insert(flags, cxxflag) + end + end + end + if fetchmodes:has("ldflags") then + for _, fetchinfo in ipairs(fetchinfos) do + for _, linkdir in ipairs(fetchinfo.linkdirs) do + table.insert(flags, "-L" .. os.args(linkdir)) + end + for _, link in ipairs(fetchinfo.links) do + table.insert(flags, "-l" .. link) + end + for _, ldflag in ipairs(fetchinfo.ldflags) do + table.insert(flags, ldflags) + end + end + end + if #flags > 0 then + print(table.concat(flags, " ")) + else + print(fetchinfos) + end end end diff --git a/xmake/actions/require/xmake.lua b/xmake/actions/require/xmake.lua index e72fa5c6c..f8ac94595 100644 --- a/xmake/actions/require/xmake.lua +++ b/xmake/actions/require/xmake.lua @@ -61,6 +61,9 @@ task("require") , {nil, "fetch", "k", nil, "Fetch the library info of given package.", "e.g.", " $ xmake require --fetch tbox" } + , {nil, "fetch_modes","kv", nil, "Set the modes of fetching packages.", + "e.g.", + " $ xmake require --fetch --fetch_modes=deps,cflags,ldflags tbox" } , {'s', "search", "k", nil, "Search for the given packages from repositories.", "e.g.", " $ xmake require --search tbox" } diff --git a/xmake/modules/private/xrepo/action/fetch.lua b/xmake/modules/private/xrepo/action/fetch.lua index 55f918df3..464dfcb24 100644 --- a/xmake/modules/private/xrepo/action/fetch.lua +++ b/xmake/modules/private/xrepo/action/fetch.lua @@ -41,6 +41,10 @@ function menu_options() " - xrepo fetch --configs=\"vs_runtime=MD\" zlib", " - xrepo fetch --configs=\"regex=true,thread=true\" boost"}, {}, + {nil, "deps", "k", nil, "Fetch packages with dependencies." }, + {nil, "cflags", "k", nil, "Fetch cflags of the given packages." }, + {nil, "ldflags", "k", nil, "Fetch ldflags of the given packages."}, + {}, {nil, "packages", "vs", nil, "The packages list.", "e.g.", " - xrepo fetch zlib boost", @@ -118,6 +122,19 @@ function _fetch_packages(packages) if option.get("diagnosis") then table.insert(require_argv, "-D") end + local fetchmodes = {} + if option.get("deps") then + table.insert(fetchmodes, "deps") + end + if option.get("cflags") then + table.insert(fetchmodes, "cflags") + end + if option.get("ldflags") then + table.insert(fetchmodes, "ldflags") + end + if #fetchmodes > 0 then + table.insert(require_argv, "--fetch_modes=" .. table.concat(fetchmodes, ',')) + end local extra = nil if mode == "debug" then extra = extra or {} |
