diff options
| author | ruki <[email protected]> | 2020-06-20 16:18:51 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-20 16:18:51 +0800 |
| commit | 966b8dd7a01b09a93ba21ee4d2df0d471ab2282c (patch) | |
| tree | 144af8b8bebb12e441402dcc90325cbb9949b494 /xmake/modules/detect/tools/link/has_flags.lua | |
| parent | da2e3b83c53752c43b651effeb273cb72090d7b0 (diff) | |
bind runenvs to has_flags
Diffstat (limited to 'xmake/modules/detect/tools/link/has_flags.lua')
| -rw-r--r-- | xmake/modules/detect/tools/link/has_flags.lua | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/xmake/modules/detect/tools/link/has_flags.lua b/xmake/modules/detect/tools/link/has_flags.lua index db93ba195..188d22976 100644 --- a/xmake/modules/detect/tools/link/has_flags.lua +++ b/xmake/modules/detect/tools/link/has_flags.lua @@ -20,13 +20,12 @@ -- imports import("lib.detect.cache") +import("lib.detect.find_tool") -- try running -function _try_running(...) - - local argv = {...} +function _try_running(program, argv, opt) local errors = nil - return try { function () os.runv(unpack(argv)); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors + return try { function () os.runv(program, argv, opt); return true end, catch { function (errs) errors = (errs or ""):trim() end }}, errors end -- attempt to check it from the argument list @@ -55,7 +54,7 @@ function _check_from_arglist(flags, opt) local arglist = nil try { - function () os.runv(opt.program, {"-?"}) end, + function () os.runv(opt.program, {"-?"}, {envs = opt.envs}) end, catch { function (errors) arglist = errors end @@ -71,8 +70,6 @@ function _check_from_arglist(flags, opt) cacheinfo[flagskey] = allflags cache.save(key, cacheinfo) end - - -- ok? return allflags[flags[1]:gsub("/", "-"):lower()] end @@ -94,16 +91,15 @@ function _check_try_running(flags, opt) -- compile the source file local objectfile = os.tmpfile() .. ".obj" local binaryfile = os.tmpfile() .. ".exe" - os.runv("cl", {"-c", "-nologo", "-Fo" .. objectfile, sourcefile}) + local cl = find_tool("cl") + if cl then + os.runv(cl.program, {"-c", "-nologo", "-Fo" .. objectfile, sourcefile}, {envs = envs}) + end -- try link it - local ok, errors = _try_running(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile)) - - -- remove files + local ok, errors = _try_running(opt.program, table.join(flags, "-nologo", "-out:" .. binaryfile, objectfile), {envs = opt.envs}) os.tryrm(objectfile) os.tryrm(binaryfile) - - -- ok? return ok, errors end |
