diff options
| author | ruki <[email protected]> | 2019-08-24 21:08:29 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-08-24 21:08:29 +0800 |
| commit | 5050520d20fb41fc61a0a7a294b34617e6737932 (patch) | |
| tree | f20f561c94dc02681416ebbec9648bab7ddb4eb5 | |
| parent | 3fd6fc731109c138f3eb2cfcc4700c9004921e2c (diff) | |
add display name to bitcode files
| -rw-r--r-- | .appveyor.yml | 2 | ||||
| -rw-r--r-- | .travis.yml | 2 | ||||
| -rwxr-xr-x | scripts/archive-all.sh | 2 | ||||
| -rwxr-xr-x | scripts/get.sh | 2 | ||||
| -rwxr-xr-x | scripts/makeself/build-runfile.sh | 2 | ||||
| -rw-r--r-- | xmake/core/_xmake_main.lua | 33 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/utils/bcsave.lua | 16 |
8 files changed, 38 insertions, 25 deletions
diff --git a/.appveyor.yml b/.appveyor.yml index d6001b892..5423db9df 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -50,7 +50,7 @@ build_script: - ps: Copy-Item -Force .\core\build\xmake.exe $(Get-Command xmake).Path - ps: (Get-Command xmake).FileVersionInfo.ProductVersion # use bitcodes - - ps: xmake l private.utils.bcsave -x 'scripts/**|templates/**' xmake + - ps: xmake l private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake - ps: (Get-Command xmake).FileVersionInfo.ProductVersion after_build: diff --git a/.travis.yml b/.travis.yml index 7d73bc777..25291faa0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,7 @@ script: - export XMAKE_PROGRAM_DIR=~/.local/share/xmake - cp core/build/xmake "$XMAKE_PROGRAM_DIR" || sudo cp core/build/xmake "$XMAKE_PROGRAM_DIR" - xmake --version - - xmake l private.utils.bcsave -x 'scripts/**|templates/**' xmake + - xmake l private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake - xmake --version - travis_wait 60 xmake lua -v -D tests/run.lua - scripts/archive-all.sh diff --git a/scripts/archive-all.sh b/scripts/archive-all.sh index 144c68f92..1cdb6c29c 100755 --- a/scripts/archive-all.sh +++ b/scripts/archive-all.sh @@ -18,7 +18,7 @@ git submodule foreach git clean -dfX # copy files to tmpdir/xmake mkdir -p $tmpdir/xmake/scripts cd $tmpdir/repo || exit -xmake l -v private.utils.bcsave -x 'scripts/**|templates/**' xmake || exit +xmake l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake || exit cp -r ./core $tmpdir/xmake cp -r ./xmake $tmpdir/xmake/xmake cp ./scripts/get.sh $tmpdir/xmake/scripts diff --git a/scripts/get.sh b/scripts/get.sh index 10ccf544a..5ae3f8513 100755 --- a/scripts/get.sh +++ b/scripts/get.sh @@ -143,7 +143,7 @@ fi # make bytecodes export XMAKE_PROGRAM_DIR=$projectdir/xmake -$projectdir/core/src/demo/demo.b l -v private.utils.bcsave -x 'scripts/**|templates/**' $projectdir/xmake || my_exit 'generate bytecode failed!' +$projectdir/core/src/demo/demo.b l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' $projectdir/xmake || my_exit 'generate bytecode failed!' export XMAKE_PROGRAM_DIR= # do install diff --git a/scripts/makeself/build-runfile.sh b/scripts/makeself/build-runfile.sh index 45fa2ccd2..4527da46a 100755 --- a/scripts/makeself/build-runfile.sh +++ b/scripts/makeself/build-runfile.sh @@ -20,7 +20,7 @@ git submodule foreach git clean -dfX # copy files to tmpdir/xmake mkdir -p $tmpdir/xmake/scripts cd $tmpdir/repo || exit -xmake l -v private.utils.bcsave -x 'scripts/**|templates/**' xmake || exit +xmake l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake || exit cp -r ./xmake $tmpdir/xmake/xmake cp -r ./core $tmpdir/xmake cp ./scripts/get.sh $tmpdir/xmake/scripts diff --git a/xmake/core/_xmake_main.lua b/xmake/core/_xmake_main.lua index 7f812089b..631549cc0 100644 --- a/xmake/core/_xmake_main.lua +++ b/xmake/core/_xmake_main.lua @@ -31,18 +31,24 @@ xmake._PROJECT_DIR = _PROJECT_DIR xmake._PROJECT_FILE = "xmake.lua" xmake._WORKING_DIR = os.curdir() -function _loadfile_impl(filepath, mode) +function _loadfile_impl(filepath, mode, opt) + + -- init options + opt = opt or {} -- init displaypath local binary = false - local displaypath = filepath - if filepath:startswith(xmake._WORKING_DIR) then - displaypath = path.translate("./" .. path.relative(filepath, xmake._WORKING_DIR)) - elseif filepath:startswith(xmake._PROGRAM_DIR) then - binary = true -- read file by binary mode, will be faster - displaypath = path.translate("$(programdir)/" .. path.relative(filepath, xmake._PROGRAM_DIR)) - elseif filepath:startswith(xmake._PROJECT_DIR) then - displaypath = path.translate("$(projectdir)/" .. path.relative(filepath, xmake._PROJECT_DIR)) + local displaypath = opt.displaypath + if displaypath == nil then + displaypath = filepath + if filepath:startswith(xmake._WORKING_DIR) then + displaypath = path.translate("./" .. path.relative(filepath, xmake._WORKING_DIR)) + elseif filepath:startswith(xmake._PROGRAM_DIR) then + binary = true -- read file by binary mode, will be faster + displaypath = path.translate("@programdir/" .. path.relative(filepath, xmake._PROGRAM_DIR)) + elseif filepath:startswith(xmake._PROJECT_DIR) then + displaypath = path.translate("@projectdir/" .. path.relative(filepath, xmake._PROJECT_DIR)) + end end -- load script data from file @@ -64,8 +70,13 @@ function _loadfile_impl(filepath, mode) end -- init loadfile +-- +-- @param filepath the lua file path +-- @param mode the load mode, e.g 't', 'b' or 'bt' (default) +-- @param opt the arguments option, e.g. {displaypath = ""} +-- local _loadcache = {} -function loadfile(filepath, mode) +function loadfile(filepath, mode, opt) -- get absolute path filepath = path.absolute(filepath) @@ -81,7 +92,7 @@ function loadfile(filepath, mode) end -- load file - local script, errors = _loadfile_impl(filepath, mode) + local script, errors = _loadfile_impl(filepath, mode, opt) if script then _loadcache[filepath] = {script = script, mtime = mtime or os.mtime(filepath)} end diff --git a/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua b/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua index da4baed6b..28ea0ced7 100644 --- a/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua +++ b/xmake/core/sandbox/modules/import/lib/luajit/bcsave.lua @@ -27,11 +27,11 @@ local raise = require("sandbox/modules/raise") -- -- @param luafile the lua file -- @param bcfile the bitcode file --- @param opt the arguments option, e.g. {strip = true} +-- @param opt the arguments option, e.g. {strip = true, displaypath = "/xxx/a.lua"} -- function main(luafile, bcfile, opt) opt = opt or {} - local result, errors = loadfile(luafile) + local result, errors = loadfile(luafile, "bt", {displaypath = opt.displaypath}) if not result then raise(errors) end diff --git a/xmake/modules/private/utils/bcsave.lua b/xmake/modules/private/utils/bcsave.lua index 2ae3ae430..9310180b4 100644 --- a/xmake/modules/private/utils/bcsave.lua +++ b/xmake/modules/private/utils/bcsave.lua @@ -26,6 +26,7 @@ import("lib.luajit.bcsave") local options = { {'s', "strip", "k", false, "Strip the debug info." } +, {nil, "rootname", "kv", nil, "Set the display root path name." } , {'o', "outputdir", "kv", nil, "Set the output directory of bitcode files." } , {'x', "excludedirs", "kv", nil, "Set the excluded directories." } , {nil, "sourcedir", "v", os.programdir(), "Set the directory of lua source files." } @@ -44,7 +45,6 @@ function save(sourcedir, outputdir, opt) print("generating bitcode files from %s ..", sourcedir) -- save all lua files to bitcode files - local oldir = os.cd(sourcedir) local total_lua = 0 local total_bc = 0 local pattern = path.join(sourcedir, "**.lua") @@ -54,28 +54,30 @@ function save(sourcedir, outputdir, opt) local override = (outputdir == sourcedir) for _, luafile in ipairs(os.files(pattern)) do - -- get relative lua file path to decrease bitcode file size (without strip) - luafile = path.relative(luafile, sourcedir) + -- get relative lua file path + local relativepath = path.relative(luafile, sourcedir) + + -- get display path + local displaypath = opt.rootname and path.join(opt.rootname, relativepath) or relativepath -- get bitcode file path - local bcfile = override and os.tmpfile() or path.join(outputdir, luafile) + local bcfile = override and os.tmpfile() or path.join(outputdir, relativepath) -- generate bitcode file - bcsave(luafile, bcfile, {strip = opt.strip}) + bcsave(luafile, bcfile, {strip = opt.strip, displaypath = displaypath}) -- trace local luasize = os.filesize(luafile) local bcsize = os.filesize(bcfile) total_lua = total_lua + luasize total_bc = total_bc + bcsize - vprint("generating %s (%d => %d)..", luafile, luasize, bcsize) + vprint("generating %s (%d => %d) ..", displaypath, luasize, bcsize) -- override? if override then os.cp(bcfile, luafile) end end - os.cd(oldir) -- trace cprint("${bright}bitcode files have been generated in %s, size: %d => %d", outputdir, total_lua, total_bc) |
