10 Commits

Author SHA1 Message Date
  ruki d3acb6ca0d
Merge pull request #7136 from xmake-io/clangcl 1 day ago
  ruki ba89fa5f31 improve check clang /mmd 1 day ago
  ruki bbea1373c5 improve depfiles 1 day ago
  ruki 757ad89002 improve clang-cl depfiles #7070 1 day ago
  ruki e58fd4cd91 improve ./configure 1 day ago
  ruki cb0e3915da fix link tips 1 day ago
  ruki bab1a618ff
Merge pull request #7135 from xmake-io/session 1 day ago
  ruki 5ddfccee21 improve session id 1 day ago
  ruki f185da7553 improve xrepo env 1 day ago
  ruki b9116ea123 add tty.session_id 1 day ago
7 changed files with 137 additions and 6 deletions
Split View
  1. +5
    -1
      configure
  2. +2
    -0
      core/src/xmake/engine.c
  3. +65
    -0
      core/src/xmake/tty/session_id.c
  4. +20
    -0
      xmake/core/base/tty.lua
  5. +38
    -3
      xmake/modules/core/tools/clang_cl.lua
  6. +5
    -1
      xmake/modules/private/action/build/link_objects.lua
  7. +2
    -1
      xmake/modules/private/xrepo/action/env.lua

+ 5
- 1
configure View File

@@ -4295,7 +4295,11 @@ _gmake_add_build_target() {
# link target
echo "${target}: ${targetfile}" >> "${xmake_sh_makefile}"
echo "${targetfile}: ${depfiles}${objectfiles}" >> "${xmake_sh_makefile}"
print "\t@echo linking.${_target_mode} ${targetfile}" >> "${xmake_sh_makefile}"
if test_eq "${targetkind}" "static"; then
print "\t@echo archiving.${_target_mode} ${targetfile}" >> "${xmake_sh_makefile}"
else
print "\t@echo linking.${_target_mode} ${targetfile}" >> "${xmake_sh_makefile}"
fi
case "${toolname}" in
gcc) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;
gxx) _gmake_add_build_target_for_gcc_clang "${toolkind}" "${targetfile}" "${objectfiles}" "${flagname}";;


+ 2
- 0
core/src/xmake/engine.c View File

@@ -330,6 +330,7 @@ tb_int_t xm_libc_setbyte(lua_State *lua);

// the tty functions
tb_int_t xm_tty_term_mode(lua_State *lua);
tb_int_t xm_tty_session_id(lua_State *lua);

// the package functions
tb_int_t xm_package_loadxmi(lua_State *lua);
@@ -649,6 +650,7 @@ static luaL_Reg const g_libc_functions[] = {
// the tty functions
static luaL_Reg const g_tty_functions[] = {
{ "term_mode", xm_tty_term_mode },
{ "session_id", xm_tty_session_id },
{ tb_null, tb_null },
};



+ 65
- 0
core/src/xmake/tty/session_id.c View File

@@ -0,0 +1,65 @@
/*!A cross-platform build utility based on Lua
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright (C) 2015-present, Xmake Open Source Community.
*
* @author ruki
* @file session_id.c
*
*/

/* //////////////////////////////////////////////////////////////////////////////////////
* trace
*/
#define TB_TRACE_MODULE_NAME "session_id"
#define TB_TRACE_MODULE_DEBUG (0)

/* //////////////////////////////////////////////////////////////////////////////////////
* includes
*/
#include "prefix.h"
#ifdef TB_CONFIG_OS_WINDOWS
#include <windows.h>
#else
#include <unistd.h>
#endif

/* //////////////////////////////////////////////////////////////////////////////////////
* implementation
*/

// tty.session_id()
tb_int_t xm_tty_session_id(lua_State *lua) {
tb_assert_and_check_return_val(lua, 0);

#ifdef TB_CONFIG_OS_WINDOWS
HWND hwnd = GetConsoleWindow();
if (hwnd) {
// use hex string of hwnd as session id
lua_pushfstring(lua, "%p", hwnd);
return 1;
}
#else
// we use the tty name as session id
tb_char_t const* name = ttyname(STDIN_FILENO);
if (name) {
lua_pushstring(lua, name);
return 1;
}
#endif

// failed
lua_pushnil(lua);
return 1;
}

+ 20
- 0
xmake/core/base/tty.lua View File

@@ -26,6 +26,7 @@ local io = require("base/io")

-- save metatable and builtin functions
tty._term_mode = tty._term_mode or tty.term_mode
tty._session_id = tty._session_id or tty.session_id

-- @see https://www2.ccs.neu.edu/research/gpc/VonaUtils/vona/terminal/vtansi.htm
-- http://www.termsys.demon.co.uk/vtansi.htm
@@ -538,6 +539,25 @@ function tty.term_mode(stdtype, newmode)
return oldmode
end

-- get session id
function tty.session_id()
local session_id = tty._SESSION_ID
if session_id == nil then
if tty._session_id then
local sid = tty._session_id()
if sid then
local hash = require("base/hash")
session_id = hash.strhash32(sid)
end
end
if not session_id then
session_id = "00000000"
end
tty._SESSION_ID = session_id
end
return session_id
end

-- return module
return tty


+ 38
- 3
xmake/modules/core/tools/clang_cl.lua View File

@@ -143,6 +143,21 @@ function nf_pcxxheader(self, pcheaderfile, opt)
end
end

-- has /clang:-MMD -MF depfile?
function _has_clang_mmd(self)
local has_clang_mmd = _g._HAS_CLANG_MMD
if has_clang_mmd == nil then
local depfile = os.tmpfile()
if self:has_flags({"/clang:-MMD", "/clang:-MF", "/clang:" .. depfile}, "cxflags", {flagskey = "clang_mmd"}) then
has_clang_mmd = true
end
has_clang_mmd = has_clang_mmd or false
_g._HAS_CLANG_MMD = has_clang_mmd
os.tryrm(depfile)
end
return has_clang_mmd
end

-- compile the source file
function compile(self, sourcefile, objectfile, dependinfo, flags, opt)

@@ -150,6 +165,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
os.mkdir(path.directory(objectfile))

-- compile it
local depfile
local depfile_format
local outdata = try
{
function ()
@@ -157,7 +174,14 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)
-- generate includes file
local compflags = flags
if dependinfo then
compflags = table.join(flags, "-showIncludes")
if _has_clang_mmd(self) then
depfile = os.tmpfile()
compflags = table.join(flags, "/clang:-MMD", "/clang:-MF", "/clang:" .. depfile)
depfile_format = "gcc"
else
compflags = table.join(flags, "-showIncludes")
depfile_format = "cl"
end
end

-- has color diagnostics? enable it
@@ -176,6 +200,9 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)

-- try removing the old object file for forcing to rebuild this source file
os.tryrm(objectfile)
if depfile then
os.tryrm(depfile)
end

-- parse and strip errors
local lines = errors and tostring(errors):split('\n', {plain = true}) or {}
@@ -217,7 +244,15 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt)

-- generate the dependent includes
if dependinfo and outdata then
dependinfo.depfiles_format = "cl"
dependinfo.depfiles = outdata
if depfile then
if os.isfile(depfile) then
dependinfo.depfiles_format = depfile_format
dependinfo.depfiles = io.readfile(depfile)
os.tryrm(depfile)
end
elseif depfile_format == "cl" then
dependinfo.depfiles_format = "cl"
dependinfo.depfiles = outdata
end
end
end

+ 5
- 1
xmake/modules/private/action/build/link_objects.lua View File

@@ -41,7 +41,11 @@ function _do_link_target(target, opt)
if target:namespace() then
filename = target:namespace() .. "::" .. filename
end
progress.show(opt.progress, "${color.build.target}linking.$(mode) %s", filename)
if target:is_static() then
progress.show(opt.progress, "${color.build.target}archiving.$(mode) %s", filename)
else
progress.show(opt.progress, "${color.build.target}linking.$(mode) %s", filename)
end

local targetfile = target:targetfile()
local objectfiles = target:objectfiles()


+ 2
- 1
xmake/modules/private/xrepo/action/env.lua View File

@@ -19,6 +19,7 @@
--

-- imports
import("core.base.tty")
import("core.base.option")
import("core.base.task")
import("core.base.hashset")
@@ -98,7 +99,7 @@ end

-- enter the working project
function _enter_project()
local workdir = path.join(os.tmpdir(), "xrepo", "working")
local workdir = path.join(os.tmpdir(), "xrepo", "working-" .. tty.session_id())
if not os.isdir(workdir) then
os.mkdir(workdir)
os.cd(workdir)


Loading…
Cancel
Save
Baidu
map