From e9b11611ea2c2c2c892938deee37797a5d10d296 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Wed, 5 Jun 2019 14:18:10 +0800 Subject: [PATCH 01/23] install script --- tests/modules/devel/git/test.lua | 21 ++++ xmake/actions/update/get_version.lua | 83 ++++++++++++++ xmake/actions/update/main.lua | 165 +++++++++++++++++---------- xmake/actions/update/xmake.lua | 16 ++- xmake/modules/devel/git/asgiturl.lua | 66 +++++++++++ xmake/scripts/run.vbs | 67 +++++++++++ xmake/scripts/sudo.vbs | 15 --- xmake/scripts/update-script.bat | 7 ++ xmake/scripts/update-script.sh | 5 + 9 files changed, 366 insertions(+), 79 deletions(-) create mode 100644 tests/modules/devel/git/test.lua create mode 100644 xmake/actions/update/get_version.lua create mode 100644 xmake/modules/devel/git/asgiturl.lua create mode 100644 xmake/scripts/run.vbs delete mode 100644 xmake/scripts/sudo.vbs create mode 100644 xmake/scripts/update-script.bat create mode 100644 xmake/scripts/update-script.sh diff --git a/tests/modules/devel/git/test.lua b/tests/modules/devel/git/test.lua new file mode 100644 index 00000000000..ddcfc94b248 --- /dev/null +++ b/tests/modules/devel/git/test.lua @@ -0,0 +1,21 @@ +import("devel.git") + + +function test_asgiturl() + assert(git.asgiturl("http://github.com/a/b") == "https://github.com/a/b.git") + assert(git.asgiturl("http://github.com/a/b/") == "https://github.com/a/b.git") + assert(git.asgiturl("HTTP://github.com//a/b/") == "https://github.com/a/b.git") + assert(git.asgiturl("http://github.com//a/b/s") == nil) + assert(git.asgiturl("https://github.com/a/b") == "https://github.com/a/b.git") + assert(git.asgiturl("https://github.com/a/b.git") == "https://github.com/a/b.git") + assert(git.asgiturl("HTTPS://GITHUB.com/a/b.git.git") == "https://github.com/a/b.git.git") + + assert(git.asgiturl("github:a/b") == "https://github.com/a/b.git") + assert(git.asgiturl("github:a/b.git") == "https://github.com/a/b.git.git") + assert(git.asgiturl("GitHub://a/b/") == "https://github.com/a/b.git") + assert(git.asgiturl("github:a/b/c") == nil) +end + +function main() + test_asgiturl() +end \ No newline at end of file diff --git a/xmake/actions/update/get_version.lua b/xmake/actions/update/get_version.lua new file mode 100644 index 00000000000..2c45b6ae157 --- /dev/null +++ b/xmake/actions/update/get_version.lua @@ -0,0 +1,83 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file get_version.lua +-- + +-- imports +import("core.base.semver") +import("core.base.option") +import("core.base.task") +import("net.http") +import("devel.git") +import("net.fasturl") + +local official_sources = { + "https://github.com/xmake-io/xmake.git", + "https://gitlab.com/tboox/xmake.git", + "https://gitee.com/tboox/xmake.git" +} + +-- get version and url of provided xmakever +function main(xmakever) + xmakever = xmakever or "lastest" + + local commitish = nil + local custom_url = nil + local seg = xmakever:split('#', { plain = true, limit = 2, strict = true }) + if #seg == 2 then + if #seg[1] ~= 0 then + custom_url = seg[1] + end + commitish = seg[2] + else + if xmakever:find(':', 1, true) then + custom_url = xmakever + else + commitish = xmakever + end + end + + local urls = nil + if custom_url then + urls = { git.asgiturl(custom_url) or custom_url } + vprint("using custom source: %s ..", urls[1] ) + else + urls = official_sources + end + commitish = (commitish and #commitish > 0) and commitish or "lastest" + + -- sort urls + if #urls > 1 then + fasturl.add(urls) + urls = fasturl.sort(urls) + end + + -- get version + local version = nil + local tags, branches + for _, url in ipairs(urls) do + tags, branches = git.refs(url) + if tags or branches then + version = semver.select(commitish, tags or {}, tags or {}, branches or {}) + break + end + end + + return (urls == official_sources), urls, (version or "master"), tags, branches +end + diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 108468a2194..701c56b5c06 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -28,15 +28,16 @@ import("net.fasturl") import("core.base.privilege") import("privilege.sudo") import("actions.require.impl.environment", {rootdir = os.programdir()}) +import("get_version") --- run cmd with privilege -function _sudo(cmd) +-- run program with privilege +function _sudo_v(program, params) -- attempt to install directly - try + return try { function () - os.vrun(cmd) + os.vrunv(program, params) return true end, @@ -53,7 +54,7 @@ function _sudo(cmd) local ok = try { function () - os.vrun(cmd) + os.vrunv(program, params) return true end } @@ -62,13 +63,14 @@ function _sudo(cmd) privilege.store() -- ok? - if ok then - return true + if ok then + return true end end -- show tips - cprint("\r${bright color.error}error: ${clear}run `%s` failed, may permission denied!", cmd) + local command = program .. " " ..os.args(params) + cprint("\r${bright color.error}error: ${clear}run `%s` failed, may permission denied!", command) -- continue to install with administrator permission? if sudo.has() then @@ -76,7 +78,7 @@ function _sudo(cmd) -- confirm to install? local confirm = utils.confirm({default = true, description = "try continue to run `%s` with administrator permission again"}) if confirm then - sudo.vrun(cmd) + sudo.vrunv(program, params) return true end end @@ -85,34 +87,40 @@ function _sudo(cmd) } end +-- run program witn admin user +function _run_win_v(program, commands, admin) + local sudo_vbs = path.join(os.programdir(), "scripts", "run.vbs") + local temp_vbs = os.tmpfile() .. ".vbs" + os.cp(sudo_vbs, temp_vbs) + local params = table.join("/Nologo", temp_vbs, "W" .. (admin and "A" or "N") , program, commands) + local proc = process.openv("cscript", params) + if proc then process.close(proc) end + return proc ~= nil +end + -- do uninstall function _uninstall() if is_host("windows") then local uninstaller = path.join(os.programdir(), "uninstall.exe") if os.isfile(uninstaller) then -- UAC on win7 + local params = option.get("quiet") and { "/S" } or {} if winos:version():gt("winxp") then - local proc = process.openv("cscript", {path.join(os.programdir(), "scripts", "sudo.vbs"), uninstaller}) - if proc ~= nil then - process.close(proc) - end + _run_win_v(uninstaller, params, true) else - local proc = process.open(uninstaller) - if proc ~= nil then - process.close(proc) - end + _run_win_v(uninstaller, params, false) end else raise("the uninstaller(%s) not found!", uninstaller) end else if os.programdir():startswith("/usr/") then - _sudo("rm -rf " .. os.programdir()) + _sudo_v("xmake", {"lua", "rm", os.programdir() }) if os.isfile("/usr/local/bin/xmake") then - _sudo("rm -f /usr/local/bin/xmake") + _sudo_v("xmake", {"lua", "rm", "/usr/local/bin/xmake" }) end if os.isfile("/usr/bin/xmake") then - _sudo("rm -f /usr/bin/xmake") + _sudo_v("xmake", {"lua", "rm", "/usr/bin/xmake" }) end else os.rm(os.programdir()) @@ -133,26 +141,23 @@ function _install(sourcedir, version) -- trace cprintf("\r${yellow} => ${clear}installing to %s .. ", installdir) - local ok = try + local ok = try { function () - -- install it + -- install it os.cd(sourcedir) if is_host("windows") then local installer = "xmake-" .. version .. ".exe" if os.isfile(installer) then + -- /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the last parameter used in the command line and must not contain any quotes, even if the path contains spaces. Only absolute paths are supported. + local params = ("/D=" .. os.programdir()):split("%s", { strict = true }) + if option.get("quiet") then table.insert(params, 1, "/S") end -- need UAC? if winos:version():gt("winxp") then - local proc = process.openv("cscript", {path.join(os.programdir(), "scripts", "sudo.vbs"), installer}) - if proc ~= nil then - process.close(proc) - end + _run_win_v(installer, params, true) else - local proc = process.open(installer) - if proc ~= nil then - process.close(proc) - end + _run_win_v(installer, params, false) end else raise("the installer(%s) not found!", installer) @@ -169,7 +174,7 @@ function _install(sourcedir, version) end } } - + -- trace if ok then cprint("\r${yellow} => ${clear}install to %s .. ${green}ok ", installdir) @@ -191,6 +196,49 @@ function _install(sourcedir, version) end end +-- do install script +function _install_script(sourcedir) + cprintf("\r${yellow} => ${clear}install script to %s .. ", os.programdir()) + + local source = path.join(sourcedir, "xmake") + local dirname = path.filename(os.programdir()) + if dirname ~= "xmake" then + local target = path.join(sourcedir, dirname) + os.mv(source, target) + source = target + end + + local ok = try + { + function () + if is_host("windows") then + local script_original = path.join(os.programdir(), "scripts", "update-script.bat") + local script = os.tmpfile() .. ".bat" + os.cp(script_original, script) + local params = { "/c", script, os.programdir(), source } + os.tryrm(script_original .. ".bak") + local access = os.trymv(script_original, script_original .. ".bak") + return _run_win_v("cmd", params, not access) + else + local script = path.join(os.programdir(), "scripts", "update-script.sh") + return _sudo_v("sh", { script, os.programdir(), source }) + end + end, + catch + { + function (errors) + vprint(errors) + end + } + } + -- trace + if ok then + cprint("${color.success}${text.success}") + else + cprint("${color.failure}${text.failure}") + end +end + -- main function main() @@ -202,42 +250,28 @@ function main() -- trace cprint("${bright}uninstall ok!") - return + return end - -- enter environment + -- enter environment environment.enter() - -- sort main urls - local mainurls = {"https://github.com/xmake-io/xmake.git", - "https://gitlab.com/tboox/xmake.git", - "https://gitee.com/tboox/xmake.git"} - fasturl.add(mainurls) - mainurls = fasturl.sort(mainurls) - - -- get version - local tags = nil - local branches = nil - local version = nil - for _, url in ipairs(mainurls) do - tags, branches = git.refs(url) - if tags or branches then - version = semver.select(option.get("xmakever") or "lastest", tags or {}, tags or {}, branches or {}) - break - end - end - if not version then - version = "master" - end + local is_official, mainurls, version, tags, branches = get_version(option.get("xmakever")) -- has been installed? - if os.xmakever():eq(version) then + if is_official and xmake.version():eq(version) then cprint("${bright}xmake %s has been installed!", version) return end + local script_only = option.get("scriptonly") + -- get urls on windows - if is_host("windows") then + if is_host("windows") and not script_only then + if not is_official then + raise("not support to update from unofficial source on windows, missing '--scriptonly' flag?") + end + if version:find('.', 1, true) then mainurls = {format("https://github.com/xmake-io/xmake/releases/download/%s/xmake-%s.exe", version, version), format("https://qcloud.coding.net/u/waruqi/p/xmake-releases/git/raw/master/xmake-%s.exe", version), @@ -259,10 +293,16 @@ function main() end -- trace - print("update version: %s ..", version) + if is_official then + cprint("update version ${green}%s${clear} from official source ..", version) + else + cprint("update version ${green}%s${clear} from ${underline}%s${clear} ..", version, mainurls[1]) + end -- the download task local sourcedir = path.join(os.tmpdir(), "xmakesrc", version) + vprint("prepared to downlaod to temp dir %s ..", sourcedir) + local download_task = function () for idx, url in ipairs(mainurls) do cprintf("\r${yellow} => ${clear}downloading %s .. ", url) @@ -270,7 +310,8 @@ function main() { function () os.tryrm(sourcedir) - if not git.checkurl(url) then + -- all user provided urls are considered as git url since check has been performed in get_version + if is_official and not git.checkurl(url) then os.mkdir(sourcedir) http.download(url, path.join(sourcedir, path.filename(url))) else @@ -309,10 +350,14 @@ function main() process.asyncrun(download_task) end - -- leave environment + -- leave environment environment.leave() -- do install - _install(sourcedir, version) + if script_only then + _install_script(sourcedir) + else + _install(sourcedir, version) + end end diff --git a/xmake/actions/update/xmake.lua b/xmake/actions/update/xmake.lua index 5e42a943678..ae7f1a58f73 100644 --- a/xmake/actions/update/xmake.lua +++ b/xmake/actions/update/xmake.lua @@ -30,7 +30,7 @@ task("update") -- set menu set_menu { -- usage - usage = "xmake update [options] [version]" + usage = "xmake update [options] [xmakever]" -- description , description = "Update and uninstall the xmake program." @@ -38,9 +38,17 @@ task("update") -- options , options = { - {nil, "uninstall", "k", nil, "Uninstall the current xmake program." } - , { } - , {nil, "xmakever", "v", nil, "The given xmake version. (e.g. ~2.2.3, dev, master)" } + {nil, "uninstall", "k", nil, "Uninstall the current xmake program." } + , { } + , {'s', "scriptonly", "k", nil, "Update script only" } + , {nil, "xmakever", "v", nil, "The given xmake version, or a git source (and branch). ", + "e.g.", + " from official source: ", + " lastest, ~2.2.3, dev, master", + " from custom source:", + " https://github.com/xmake-io/xmake", + " github:xmake-io/xmake#~2.2.3", + " git://github.com/xmake-io/xmake.git#master" } } } diff --git a/xmake/modules/devel/git/asgiturl.lua b/xmake/modules/devel/git/asgiturl.lua new file mode 100644 index 00000000000..2b8f5ea7ed2 --- /dev/null +++ b/xmake/modules/devel/git/asgiturl.lua @@ -0,0 +1,66 @@ +--!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 - 2019, TBOOX Open Source Group. +-- +-- @author OpportunityLiu +-- @file asgiturl.lua +-- + +-- imports +import("checkurl") + +local custom_protocol = { + ["github:"] = "https://github.com" +, ["gitlab:"] = "https://gitlab.com" +, ["gitee:"] = "https://gitee.com" +, ["bitbucket:"] = "https://bitbucket.org" +} + +-- try to parse given url as a git url +-- +-- @param url url can be transformed to a git url +-- +-- @return a git url or nil, if failed +-- + +function main(url) + url = url:trim() + assert(#url > 0) + + -- safe because all custom_protocol supports https + local lower = url:lower() + local n_url = url + if lower:startswith("http://") then + n_url = "https" .. url:sub(#"http" + 1) + lower = n_url:lower() + end + + for k, v in pairs(custom_protocol) do + if lower:startswith(k) then + local data = n_url:sub(#k + 1):split("/") + if #data ~= 2 then return nil end + return v .. "/" .. data[1] .. "/" .. data[2] .. ".git" + elseif lower:startswith(v) then + local data = n_url:sub(#v + 1):split("/") + if #data ~= 2 then return nil end + return v .. "/" .. data[1] .. "/" .. (data[2]:endswith(".git") and data[2] or (data[2] .. ".git")) + end + end + + if checkurl(url) then + return url + end +end + diff --git a/xmake/scripts/run.vbs b/xmake/scripts/run.vbs new file mode 100644 index 00000000000..24fa86c4aa0 --- /dev/null +++ b/xmake/scripts/run.vbs @@ -0,0 +1,67 @@ +Set UAC = CreateObject("Shell.Application") + +Const PROCESS = "xmake.exe" + +If WScript.Arguments.count < 2 Then + WScript.echo "Help: run [args]" + WScript.echo " flags:" + WScript.echo " N - normal" + WScript.echo " A - run as admin" + WScript.echo " W - wait xmake to exit" + WScript.echo " You should use 'N' if no speical flags needed" + WScript.echo " e.g.: run WA xmake-install.exe /Q" +Else + Dim flags + Dim program + flags = UCase(WScript.arguments(0)) + program = WScript.arguments(1) + + Dim verb + Dim wait + If InStr(flags, "A") <> 0 Then + verb = "runas" + Else + verb = "open" + End If + + If InStr(flags, "W") <> 0 Then + Dim counter + counter = 0 + Dim sQuery + sQuery = "select * from win32_process where name='" & PROCESS & "'" + Do + Set SVC = getobject("winmgmts:root\cimv2") + Set cproc = SVC.execquery(sQuery) + iniproc = cproc.count + counter = counter + 1 + If counter >= 20 Then + WScript.echo "xmake still hasn't exited after 10 seconds, aborting..." + WScript.quit 1 + End If + If iniproc <> 0 Then + WScript.echo "Waiting for xmake to exit..." + wscript.sleep 500 + End If + Loop Until iniproc = 0 + + Set cproc = Nothing + Set SVC = Nothing + End If + + Dim ucCount + Dim args + args = "" + For ucCount = 2 To (WScript.Arguments.count - 1) Step 1 + Dim carg + if InStr(WScript.Arguments(ucCount), " ") <> 0 Then + carg = """" & Replace(WScript.Arguments(ucCount), """", """""") & """" + ElseIf Len(WScript.Arguments(ucCount)) = 0 Then + carg = """""" + Else + carg = WScript.Arguments(ucCount) + End If + args = args & " " & carg + Next + + UAC.ShellExecute program, args, "", verb, 1 +End If diff --git a/xmake/scripts/sudo.vbs b/xmake/scripts/sudo.vbs deleted file mode 100644 index 9bc71637c4e..00000000000 --- a/xmake/scripts/sudo.vbs +++ /dev/null @@ -1,15 +0,0 @@ -Set UAC = CreateObject("Shell.Application") -Set Shell = CreateObject("WScript.Shell") -If WScript.Arguments.count < 1 Then - WScript.echo "Help: sudo [args]" -ElseIf WScript.Arguments.count = 1 Then - UAC.ShellExecute WScript.arguments(0), "", "", "runas", 1 -Else - Dim ucCount - Dim args - args = NULL - For ucCount = 1 To (WScript.Arguments.count - 1) Step 1 - args = args & " " & WScript.Arguments(ucCount) - Next - UAC.ShellExecute WScript.arguments(0), args, "", "runas", 5 -End If diff --git a/xmake/scripts/update-script.bat b/xmake/scripts/update-script.bat new file mode 100644 index 00000000000..f0df7c1bdf3 --- /dev/null +++ b/xmake/scripts/update-script.bat @@ -0,0 +1,7 @@ +@echo off + +echo Removing old files +cd "%~1" +del actions core includes languages modules platforms plugins repository rules scripts templates themes /S /Q /F >nul +echo Copying from temp directory to "%~1" +xcopy "%~2" "%~1" /S /Y /Q >nul \ No newline at end of file diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh new file mode 100644 index 00000000000..9e79ec71a07 --- /dev/null +++ b/xmake/scripts/update-script.sh @@ -0,0 +1,5 @@ + + +cd "$1" +rm actions core includes languages modules platforms plugins repository rules scripts templates themes -rf +cp "$2" "$1/.." -rf \ No newline at end of file From 50b021eced621efc6c2971d032e1592272ca045b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 10:38:40 +0800 Subject: [PATCH 02/23] use get.sh --- xmake/actions/update/main.lua | 17 +++++------------ xmake/scripts/update-script.sh | 5 ----- 2 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 xmake/scripts/update-script.sh diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 701c56b5c06..6d3e6ce0d2a 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -200,14 +200,6 @@ end function _install_script(sourcedir) cprintf("\r${yellow} => ${clear}install script to %s .. ", os.programdir()) - local source = path.join(sourcedir, "xmake") - local dirname = path.filename(os.programdir()) - if dirname ~= "xmake" then - local target = path.join(sourcedir, dirname) - os.mv(source, target) - source = target - end - local ok = try { function () @@ -215,13 +207,14 @@ function _install_script(sourcedir) local script_original = path.join(os.programdir(), "scripts", "update-script.bat") local script = os.tmpfile() .. ".bat" os.cp(script_original, script) - local params = { "/c", script, os.programdir(), source } + local params = { "/c", script, os.programdir(), path.join(sourcedir, "xmake") } os.tryrm(script_original .. ".bak") - local access = os.trymv(script_original, script_original .. ".bak") + local access = os.trycp(script_original, script_original .. ".bak") return _run_win_v("cmd", params, not access) else - local script = path.join(os.programdir(), "scripts", "update-script.sh") - return _sudo_v("sh", { script, os.programdir(), source }) + os.cd(sourcedir) + os.vrun("./scripts/get.sh __local__ __install_only__") + return true end end, catch diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh deleted file mode 100644 index 9e79ec71a07..00000000000 --- a/xmake/scripts/update-script.sh +++ /dev/null @@ -1,5 +0,0 @@ - - -cd "$1" -rm actions core includes languages modules platforms plugins repository rules scripts templates themes -rf -cp "$2" "$1/.." -rf \ No newline at end of file From 0c66e743e1b5b1b9d7e377015f1acefdaf2602d0 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 11:18:30 +0800 Subject: [PATCH 03/23] revert --- xmake/actions/update/main.lua | 17 ++++++++++++----- xmake/scripts/update-script.sh | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 xmake/scripts/update-script.sh diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 6d3e6ce0d2a..701c56b5c06 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -200,6 +200,14 @@ end function _install_script(sourcedir) cprintf("\r${yellow} => ${clear}install script to %s .. ", os.programdir()) + local source = path.join(sourcedir, "xmake") + local dirname = path.filename(os.programdir()) + if dirname ~= "xmake" then + local target = path.join(sourcedir, dirname) + os.mv(source, target) + source = target + end + local ok = try { function () @@ -207,14 +215,13 @@ function _install_script(sourcedir) local script_original = path.join(os.programdir(), "scripts", "update-script.bat") local script = os.tmpfile() .. ".bat" os.cp(script_original, script) - local params = { "/c", script, os.programdir(), path.join(sourcedir, "xmake") } + local params = { "/c", script, os.programdir(), source } os.tryrm(script_original .. ".bak") - local access = os.trycp(script_original, script_original .. ".bak") + local access = os.trymv(script_original, script_original .. ".bak") return _run_win_v("cmd", params, not access) else - os.cd(sourcedir) - os.vrun("./scripts/get.sh __local__ __install_only__") - return true + local script = path.join(os.programdir(), "scripts", "update-script.sh") + return _sudo_v("sh", { script, os.programdir(), source }) end end, catch diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh new file mode 100644 index 00000000000..9e79ec71a07 --- /dev/null +++ b/xmake/scripts/update-script.sh @@ -0,0 +1,5 @@ + + +cd "$1" +rm actions core includes languages modules platforms plugins repository rules scripts templates themes -rf +cp "$2" "$1/.." -rf \ No newline at end of file From b8d8a153ad39596df5580caf635f4363ccdfda45 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 10:38:40 +0800 Subject: [PATCH 04/23] use get.sh --- xmake/actions/update/main.lua | 17 +++++------------ xmake/scripts/update-script.sh | 5 ----- 2 files changed, 5 insertions(+), 17 deletions(-) delete mode 100644 xmake/scripts/update-script.sh diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 701c56b5c06..6d3e6ce0d2a 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -200,14 +200,6 @@ end function _install_script(sourcedir) cprintf("\r${yellow} => ${clear}install script to %s .. ", os.programdir()) - local source = path.join(sourcedir, "xmake") - local dirname = path.filename(os.programdir()) - if dirname ~= "xmake" then - local target = path.join(sourcedir, dirname) - os.mv(source, target) - source = target - end - local ok = try { function () @@ -215,13 +207,14 @@ function _install_script(sourcedir) local script_original = path.join(os.programdir(), "scripts", "update-script.bat") local script = os.tmpfile() .. ".bat" os.cp(script_original, script) - local params = { "/c", script, os.programdir(), source } + local params = { "/c", script, os.programdir(), path.join(sourcedir, "xmake") } os.tryrm(script_original .. ".bak") - local access = os.trymv(script_original, script_original .. ".bak") + local access = os.trycp(script_original, script_original .. ".bak") return _run_win_v("cmd", params, not access) else - local script = path.join(os.programdir(), "scripts", "update-script.sh") - return _sudo_v("sh", { script, os.programdir(), source }) + os.cd(sourcedir) + os.vrun("./scripts/get.sh __local__ __install_only__") + return true end end, catch diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh deleted file mode 100644 index 9e79ec71a07..00000000000 --- a/xmake/scripts/update-script.sh +++ /dev/null @@ -1,5 +0,0 @@ - - -cd "$1" -rm actions core includes languages modules platforms plugins repository rules scripts templates themes -rf -cp "$2" "$1/.." -rf \ No newline at end of file From f243d16eddf71ad45d3b0c662408517d081edd7d Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 11:18:30 +0800 Subject: [PATCH 05/23] revert --- xmake/actions/update/main.lua | 17 ++++++++++++----- xmake/scripts/update-script.sh | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 xmake/scripts/update-script.sh diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 6d3e6ce0d2a..701c56b5c06 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -200,6 +200,14 @@ end function _install_script(sourcedir) cprintf("\r${yellow} => ${clear}install script to %s .. ", os.programdir()) + local source = path.join(sourcedir, "xmake") + local dirname = path.filename(os.programdir()) + if dirname ~= "xmake" then + local target = path.join(sourcedir, dirname) + os.mv(source, target) + source = target + end + local ok = try { function () @@ -207,14 +215,13 @@ function _install_script(sourcedir) local script_original = path.join(os.programdir(), "scripts", "update-script.bat") local script = os.tmpfile() .. ".bat" os.cp(script_original, script) - local params = { "/c", script, os.programdir(), path.join(sourcedir, "xmake") } + local params = { "/c", script, os.programdir(), source } os.tryrm(script_original .. ".bak") - local access = os.trycp(script_original, script_original .. ".bak") + local access = os.trymv(script_original, script_original .. ".bak") return _run_win_v("cmd", params, not access) else - os.cd(sourcedir) - os.vrun("./scripts/get.sh __local__ __install_only__") - return true + local script = path.join(os.programdir(), "scripts", "update-script.sh") + return _sudo_v("sh", { script, os.programdir(), source }) end end, catch diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh new file mode 100644 index 00000000000..9e79ec71a07 --- /dev/null +++ b/xmake/scripts/update-script.sh @@ -0,0 +1,5 @@ + + +cd "$1" +rm actions core includes languages modules platforms plugins repository rules scripts templates themes -rf +cp "$2" "$1/.." -rf \ No newline at end of file From 0a0c2d0cea84f08c6b5ceddb0e89f4f59004f1f5 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 13:14:41 +0800 Subject: [PATCH 06/23] fix --- xmake/actions/update/main.lua | 2 +- xmake/scripts/update-script.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 701c56b5c06..1b25bd6bc31 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -76,7 +76,7 @@ function _sudo_v(program, params) if sudo.has() then -- confirm to install? - local confirm = utils.confirm({default = true, description = "try continue to run `%s` with administrator permission again"}) + local confirm = utils.confirm({ default = true, description = format("try continue to run `%s` with administrator permission again", command) }) if confirm then sudo.vrunv(program, params) return true diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh index 9e79ec71a07..4d7d9f25ecd 100644 --- a/xmake/scripts/update-script.sh +++ b/xmake/scripts/update-script.sh @@ -1,5 +1,5 @@ cd "$1" -rm actions core includes languages modules platforms plugins repository rules scripts templates themes -rf -cp "$2" "$1/.." -rf \ No newline at end of file +rm -rf actions core includes languages modules platforms plugins repository rules scripts templates themes +cp -rf "$2" "$1/.." \ No newline at end of file From b18f31fa02fd2061eb49b9780cab058c8f53551a Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 14:32:05 +0800 Subject: [PATCH 07/23] add #!/bin/sh --- xmake/scripts/update-script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/scripts/update-script.sh b/xmake/scripts/update-script.sh index 4d7d9f25ecd..e135a31b35f 100644 --- a/xmake/scripts/update-script.sh +++ b/xmake/scripts/update-script.sh @@ -1,4 +1,4 @@ - +#!/bin/sh cd "$1" rm -rf actions core includes languages modules platforms plugins repository rules scripts templates themes From 5c291b96a9dc2e42dddb05e4e26b365c4547bfa3 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 16:33:09 +0800 Subject: [PATCH 08/23] fix ignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9dd2d123e46..cd7ecbe72af 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,4 @@ core/.config.mak winenv xmake-ppa !xmake/actions/build -.vscode/* \ No newline at end of file +.vscode/ \ No newline at end of file From f9f50db9fffbd4dde056c238677d3aeaad226fe7 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 17:13:57 +0800 Subject: [PATCH 09/23] test new appveyor --- .appveyor.yml | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4b17152927e..9973033067b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,23 +9,25 @@ platform: - Win64 install: - - cmd: echo %CI% + - ps: | + Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-Webrequest "https://raw.githubusercontent.com/xmake-io/xmake/dev/scripts/get.ps1" -UseBasicParsing).Content)) -ArgumentList "dev" build_script: - - ps: Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-Webrequest "https://raw.githubusercontent.com/xmake-io/xmake/dev/scripts/get.ps1" -UseBasicParsing).Content)) -ArgumentList "dev" - - cmd: xmake --version - - cmd: xmake -P core - - cmd: set XMAKE_PROGRAM_DIR=%cd%\xmake - - cmd: core\build\xmake --version - - ps: Copy-Item -Force core\build\xmake.exe $HOME\xmake - - cmd: xmake lua -D tests\test.lua - -#on_success: -# - ps: $env:XMAKE_PROGRAM_DIR=$null -# - ps: Invoke-Expression (Get-Content scripts\getpb.ps1 | Out-String) + - ps: | + xmake --version + xmake -P core + $env:XMAKE_PROGRAM_DIR = Join-Path $(Get-Location) "xmake" + .\core\build\xmake.exe --version + Copy-Item -Force core\build\xmake.exe $HOME\xmake after_build: - - ps: Copy-Item core\build\xmake.exe . + - ps: | + Copy-Item .\core\build\xmake.exe .\xmake + Push-AppveyorArtifact .\xmake -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" + +test_script: + - ps: | + Get-Command xmake + xmake --version + xmake lua -v -D tests\test.lua -artifacts: - - path: xmake.exe From 78fbcdf0ebd350643da2ac8f42589adae9b2a4e0 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 17:32:24 +0800 Subject: [PATCH 10/23] not for ci --- .appveyor.yml | 7 ++++--- scripts/get.ps1 | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 9973033067b..0971f95167e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -14,10 +14,11 @@ install: build_script: - ps: | + Get-Command xmake xmake --version - xmake -P core - $env:XMAKE_PROGRAM_DIR = Join-Path $(Get-Location) "xmake" + xmake run --project=core .\core\build\xmake.exe --version + Set-AppveyorBuildVariable -Name XMAKE_PROGRAM_DIR -Value $(Join-Path $(Get-Location) "xmake") Copy-Item -Force core\build\xmake.exe $HOME\xmake after_build: @@ -29,5 +30,5 @@ test_script: - ps: | Get-Command xmake xmake --version - xmake lua -v -D tests\test.lua + xmake lua --verbose --diagnosis tests\test.lua diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 4b186c23ffe..5e8463bc22b 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -169,6 +169,7 @@ param ( Remove-Item "$repodir" -Recurse -Force -ErrorAction SilentlyContinue } - registerTabCompletion - + if (-not $env:CI) { + registerTabCompletion + } } From 7cac3d417c9eb0218669bc3c3b5ef390ff492c64 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:06:31 +0800 Subject: [PATCH 11/23] skip self build for ci --- scripts/get.ps1 | 225 +++++++++++++++++++++++++----------------------- 1 file changed, 118 insertions(+), 107 deletions(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 5e8463bc22b..968b2e7d449 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -7,126 +7,71 @@ param ( [string]$version = "v2.2.6" ) -& { - - function myExit($code) { - if ($code -is [int] -and $code -ne 0) { - throw $Error[0] - } else { - break - } +function myExit($code) { + if ($code -is [int] -and $code -ne 0) { + throw $Error[0] + } else { + break } +} - function writeErrorTip($msg) { - Write-Host $msg -BackgroundColor Red -ForegroundColor White - } +function writeErrorTip($msg) { + Write-Host $msg -BackgroundColor Red -ForegroundColor White +} - function writeLogoLine($msg) { - Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue - } +function writeLogoLine($msg) { + Write-Host $msg -BackgroundColor White -ForegroundColor DarkBlue +} - function registerTabCompletion { - - function writeDataToFile($file) { - $encoding = [text.encoding]::UTF8 - if (Test-Path $file -PathType Leaf) { - #Create a stream reader to get the file's encoding and contents. - $sr = New-Object System.IO.StreamReader($file, $true) - [char[]] $buffer = new-object char[] 3 - $sr.Read($buffer, 0, 3) | Out-Null - $encoding = $sr.CurrentEncoding - $sr.Close() | Out-Null - - if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") { - Write-Host "Seems the tab completion of xmake has installed here..." - return - } - } +writeLogoLine ' _ ' +writeLogoLine ' __ ___ __ __ __ _| | ______ ' +writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ ' +writeLogoLine ' > < | \__/ | /_| | < ___/ ' +writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' +writeLogoLine ' ' +writeLogoLine ' ' - try { - [IO.File]::AppendAllText($file, "`n", $encoding) - } catch { - writeErrorTip "Failed to append to profile!" - writeErrorTip "Please try again as administrator" - return - } - try { - $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content - } catch { - writeErrorTip 'Download failed!' - writeErrorTip 'Check your network or... the news of S3 break' - return - } - [IO.File]::AppendAllText($file, $content, $encoding) - [IO.File]::AppendAllText($file, "`n", $encoding) - } - $message = 'Tab completion service' - $question = 'Would you like to install tab completion service of xmake to your profile?' - - $choices = @( - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'For &all users', - "Install for all users, writes to $($PROFILE.AllUsersAllHosts), admin privilege is needed.")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'Just for &me', - "Install for current user, writes to $($PROFILE.CurrentUserAllHosts).")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - 'Just for this &host', - "Install for current user current host, writes to $($PROFILE.CurrentUserCurrentHost).")), - (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( - '&No', - "Do not install xmake's tab completion service.")) - ) - switch ($Host.UI.PromptForChoice($message, $question, $choices, 1)) { - 0 { writeDataToFile($PROFILE.AllUsersAllHosts) } - 1 { writeDataToFile($PROFILE.CurrentUserAllHosts) } - 2 { writeDataToFile($PROFILE.CurrentUserCurrentHost) } - } - } +if ($PSVersionTable.PSVersion.Major -lt 5) { + writeErrorTip 'Sorry but PowerShell v5+ is required' + throw 'PowerShell''s version too low' +} +$temppath = ($null -ne $env:TMP, $env:TEMP, '.')[0] +[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - writeLogoLine ' _ ' - writeLogoLine ' __ ___ __ __ __ _| | ______ ' - writeLogoLine ' \ \/ / | \/ |/ _ | |/ / __ \ ' - writeLogoLine ' > < | \__/ | /_| | < ___/ ' - writeLogoLine ' /_/\_\_|_| |_|\__ \|_|\_\____| getter ' - writeLogoLine ' ' - writeLogoLine ' ' - - if ($PSVersionTable.PSVersion.Major -lt 5) { - writeErrorTip 'Sorry but PowerShell v5+ is required' - throw 'PowerShell''s version too low' - } - $temppath = ($env:TMP, $env:TEMP, '.' -ne $null)[0] - $outfile = $temppath + "\$pid-xmake-installer.exe" +function checkTempAccess { + $outfile = Join-Path $temppath "$pid.tmp" try { - Write-Output "$pid" | Out-File -FilePath "$outfile" - Remove-Item "$outfile" + Write-Output $pid | Out-File -FilePath $outfile + Remove-Item $outfile } catch { writeErrorTip 'Cannot write to temp path' writeErrorTip 'Please set environment var "TMP" to another path' myExit 1 } +} + +function xmakeInstall { + $outfile = Join-Path $temppath "$pid-xmake-installer.exe" Write-Host "Start downloading https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe .." try { - [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" - Invoke-Webrequest "https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe" -OutFile "$outfile" + Invoke-Webrequest "https://github.com/xmake-io/xmake/releases/download/$version/xmake-$branch.exe" -OutFile $outfile } catch { writeErrorTip 'Download failed!' writeErrorTip 'Check your network or... the news of S3 break' myExit 1 } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' - $installdir = $HOME + '\xmake' + $installdir = Join-Path $env:HOME 'xmake' Write-Host "Install to $installdir" try { - Start-Process -FilePath "$outfile" -ArgumentList "/S /D=$installdir" -Wait + Start-Process -FilePath $outfile -ArgumentList "/S /D=$installdir" -Wait } catch { - Remove-Item "$outfile" writeErrorTip 'Install failed!' writeErrorTip 'Close your antivirus then try again' myExit 1 + } finally { + Remove-Item $outfile -ErrorAction SilentlyContinue } - Remove-Item "$outfile" Write-Host 'Adding to PATH... almost done' $env:Path += ";$installdir" [Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", [System.EnvironmentVariableTarget]::User) + ";$installdir", [System.EnvironmentVariableTarget]::User) # this step is optional because installer writes path to regedit @@ -137,39 +82,105 @@ param ( writeErrorTip 'But xmake could not run... Why?' myExit 1 } +} + +function xmakeSelfBuild { Write-Host "Pulling xmake from branch $branch" - $outfile = $temppath + "\$pid-xmake-repo.zip" + $outfile = Join-Path $temppath "$pid-xmake-repo.zip" try { - Invoke-Webrequest "https://github.com/xmake-io/xmake/archive/$branch.zip" -OutFile "$outfile" + Invoke-Webrequest "https://github.com/xmake-io/xmake/archive/$branch.zip" -OutFile $outfile } catch { writeErrorTip 'Pull Failed!' writeErrorTip 'xmake is now available but may not be newest' myExit } Write-Host 'Expanding archive...' - New-Item -Path "$temppath" -Name "$pid-xmake-repo" -ItemType "directory" -Force - $oldpwd = $pwd - $repodir = $temppath + "\$pid-xmake-repo" + $oldpwd = Get-Location + $repodir = New-Item -Path $temppath -Name "$pid-xmake-repo" -ItemType Directory -Force try { - Expand-Archive "$outfile" "$repodir" -Force + Expand-Archive -Path $outfile -DestinationPath $repodir -Force Write-Host 'Self-building...' - Set-Location ($repodir + "\xmake-$branch\core") + Set-Location $(Join-Path $repodir "\xmake-$branch\core") xmake Write-Host 'Copying new files...' - Copy-Item 'build\xmake.exe' "$installdir" -Force + Copy-Item -Path '.\build\xmake.exe' -Destination $installdir -Force Set-Location '..\xmake' - Copy-Item * "$installdir" -Recurse -Force + Copy-Item -Path * -Destination $installdir -Recurse -Force xmake --version } catch { writeErrorTip 'Update Failed!' writeErrorTip 'xmake is now available but may not be newest' } finally { - Set-Location "$oldpwd" -ErrorAction SilentlyContinue - Remove-Item "$outfile" -ErrorAction SilentlyContinue - Remove-Item "$repodir" -Recurse -Force -ErrorAction SilentlyContinue + Set-Location $oldpwd -ErrorAction SilentlyContinue + Remove-Item $outfile -ErrorAction SilentlyContinue + Remove-Item $repodir -Recurse -Force -ErrorAction SilentlyContinue } +} + +function registerTabCompletion { + + function writeDataToFile($file) { + $encoding = [text.encoding]::UTF8 + if (Test-Path $file -PathType Leaf) { + #Create a stream reader to get the file's encoding and contents. + $sr = New-Object System.IO.StreamReader($file, $true) + [char[]] $buffer = new-object char[] 3 + $sr.Read($buffer, 0, 3) | Out-Null + $encoding = $sr.CurrentEncoding + $sr.Close() | Out-Null + + if ($(Get-Content $file) -imatch "Register-ArgumentCompleter -Native -CommandName xmake -ScriptBlock") { + Write-Host "Seems the tab completion of xmake has installed here..." + return + } + } - if (-not $env:CI) { - registerTabCompletion + try { + [IO.File]::AppendAllText($file, "`n", $encoding) + } catch { + writeErrorTip "Failed to append to profile!" + writeErrorTip "Please try again as administrator" + return + } + try { + $content = (Invoke-Webrequest 'https://raw.githubusercontent.com/xmake-io/xmake/master/scripts/register-completions.ps1' -UseBasicParsing).Content + } catch { + writeErrorTip 'Download failed!' + writeErrorTip 'Check your network or... the news of S3 break' + return + } + [IO.File]::AppendAllText($file, $content, $encoding) + [IO.File]::AppendAllText($file, "`n", $encoding) + } + $message = 'Tab completion service' + $question = 'Would you like to install tab completion service of xmake to your profile?' + + $choices = @( + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'For &all users', + "Install for all users, writes to $($PROFILE.AllUsersAllHosts), admin privilege is needed.")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'Just for &me', + "Install for current user, writes to $($PROFILE.CurrentUserAllHosts).")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + 'Just for this &host', + "Install for current user current host, writes to $($PROFILE.CurrentUserCurrentHost).")), + (New-Object Management.Automation.Host.ChoiceDescription -ArgumentList @( + '&No', + "Do not install xmake's tab completion service.")) + ) + switch ($Host.UI.PromptForChoice($message, $question, $choices, 1)) { + 0 { writeDataToFile($PROFILE.AllUsersAllHosts) } + 1 { writeDataToFile($PROFILE.CurrentUserAllHosts) } + 2 { writeDataToFile($PROFILE.CurrentUserCurrentHost) } } } + +checkTempAccess +xmakeInstall + +if (-not $env:CI) { + xmakeSelfBuild + registerTabCompletion +} + From f626059565d8a99d963b64927800d4d2e0020c73 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:11:02 +0800 Subject: [PATCH 12/23] fix --- scripts/get.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 968b2e7d449..3b31701dc40 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -35,7 +35,7 @@ if ($PSVersionTable.PSVersion.Major -lt 5) { writeErrorTip 'Sorry but PowerShell v5+ is required' throw 'PowerShell''s version too low' } -$temppath = ($null -ne $env:TMP, $env:TEMP, '.')[0] +$temppath = ($env:TMP, $env:TEMP, '.' -ne $null)[0] [Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls" function checkTempAccess { From 3983a4c766b127cc50c36bb36ad7a779e3ce9432 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:18:08 +0800 Subject: [PATCH 13/23] improve script --- scripts/get.ps1 | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 3b31701dc40..5dc333c6c2d 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -46,7 +46,7 @@ function checkTempAccess { } catch { writeErrorTip 'Cannot write to temp path' writeErrorTip 'Please set environment var "TMP" to another path' - myExit 1 + throw } } @@ -58,7 +58,7 @@ function xmakeInstall { } catch { writeErrorTip 'Download failed!' writeErrorTip 'Check your network or... the news of S3 break' - myExit 1 + throw } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' $installdir = Join-Path $env:HOME 'xmake' @@ -68,7 +68,7 @@ function xmakeInstall { } catch { writeErrorTip 'Install failed!' writeErrorTip 'Close your antivirus then try again' - myExit 1 + throw } finally { Remove-Item $outfile -ErrorAction SilentlyContinue } @@ -80,7 +80,7 @@ function xmakeInstall { } catch { writeErrorTip 'Everything is showing installation has finished' writeErrorTip 'But xmake could not run... Why?' - myExit 1 + throw } } @@ -92,7 +92,7 @@ function xmakeSelfBuild { } catch { writeErrorTip 'Pull Failed!' writeErrorTip 'xmake is now available but may not be newest' - myExit + throw } Write-Host 'Expanding archive...' $oldpwd = Get-Location @@ -110,6 +110,7 @@ function xmakeSelfBuild { } catch { writeErrorTip 'Update Failed!' writeErrorTip 'xmake is now available but may not be newest' + throw } finally { Set-Location $oldpwd -ErrorAction SilentlyContinue Remove-Item $outfile -ErrorAction SilentlyContinue @@ -176,11 +177,18 @@ function registerTabCompletion { } } -checkTempAccess -xmakeInstall +try { + checkTempAccess + xmakeInstall +} catch { + myExit 1 +} + if (-not $env:CI) { - xmakeSelfBuild + try { + xmakeSelfBuild + } catch { } # continue registerTabCompletion } From 9aa7e776e2bd429962f78632e043bba2c728c46c Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:19:53 +0800 Subject: [PATCH 14/23] fix --- scripts/get.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 5dc333c6c2d..bd706b4d48e 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -4,7 +4,8 @@ param ( [string]$branch = "master", - [string]$version = "v2.2.6" + [string]$version = "v2.2.6", + [string]$installdir = $(Join-Path $env:HOME 'xmake') ) function myExit($code) { @@ -61,7 +62,6 @@ function xmakeInstall { throw } Write-Host 'Start installation... Hope your antivirus doesn''t trouble' - $installdir = Join-Path $env:HOME 'xmake' Write-Host "Install to $installdir" try { Start-Process -FilePath $outfile -ArgumentList "/S /D=$installdir" -Wait From a1b6a1e11a7b0dacbe718b78e80c92107e43203b Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:36:21 +0800 Subject: [PATCH 15/23] fix script --- .appveyor.yml | 4 ++-- scripts/get.ps1 | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0971f95167e..c410b84c8d0 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,13 +10,13 @@ platform: install: - ps: | - Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-Webrequest "https://raw.githubusercontent.com/xmake-io/xmake/dev/scripts/get.ps1" -UseBasicParsing).Content)) -ArgumentList "dev" + ./scripts/get.ps1 "dev" build_script: - ps: | Get-Command xmake xmake --version - xmake run --project=core + xmake build --project=core .\core\build\xmake.exe --version Set-AppveyorBuildVariable -Name XMAKE_PROGRAM_DIR -Value $(Join-Path $(Get-Location) "xmake") Copy-Item -Force core\build\xmake.exe $HOME\xmake diff --git a/scripts/get.ps1 b/scripts/get.ps1 index bd706b4d48e..9b500d44ce3 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -190,5 +190,7 @@ if (-not $env:CI) { xmakeSelfBuild } catch { } # continue registerTabCompletion +} else { + Write-Host "Self bulid and tab completion registration has been skipped" } From f564e7dbd980ece14d7e2e15f4499d8c1b7db858 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 18:51:11 +0800 Subject: [PATCH 16/23] fix --- .appveyor.yml | 6 ++++-- scripts/get.ps1 | 8 ++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index c410b84c8d0..fdcf4db9403 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -10,7 +10,7 @@ platform: install: - ps: | - ./scripts/get.ps1 "dev" + ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH build_script: - ps: | @@ -24,7 +24,9 @@ build_script: after_build: - ps: | Copy-Item .\core\build\xmake.exe .\xmake - Push-AppveyorArtifact .\xmake -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" + Copy-Item .\*.md .\xmake + Compress-Archive -Path .\xmake -DestinationPath .\archive.zip + Push-AppveyorArtifact .\archive.zip -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" test_script: - ps: | diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 9b500d44ce3..769585ebd0e 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -5,9 +5,13 @@ param ( [string]$branch = "master", [string]$version = "v2.2.6", - [string]$installdir = $(Join-Path $env:HOME 'xmake') + [string]$installdir = $(Join-Path $(if($env:HOME) { $env:HOME } else { "C:\" }) 'xmake') ) +echo $branch +echo $version +echo $installdir + function myExit($code) { if ($code -is [int] -and $code -ne 0) { throw $Error[0] @@ -191,6 +195,6 @@ if (-not $env:CI) { } catch { } # continue registerTabCompletion } else { - Write-Host "Self bulid and tab completion registration has been skipped" + Write-Host "Self bulid and tab completion registration has been skipped for CI" } From d67139ef9cb3743e3146dd965586b3110e64b002 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 19:18:49 +0800 Subject: [PATCH 17/23] add test --- .appveyor.yml | 13 ++++++++----- xmake/actions/update/main.lua | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index fdcf4db9403..63cf3831ba5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -17,20 +17,23 @@ build_script: Get-Command xmake xmake --version xmake build --project=core - .\core\build\xmake.exe --version Set-AppveyorBuildVariable -Name XMAKE_PROGRAM_DIR -Value $(Join-Path $(Get-Location) "xmake") - Copy-Item -Force core\build\xmake.exe $HOME\xmake + .\core\build\xmake.exe --version + Copy-Item -Force core\build\xmake.exe $(Get-Command xmake).Source after_build: - ps: | Copy-Item .\core\build\xmake.exe .\xmake Copy-Item .\*.md .\xmake - Compress-Archive -Path .\xmake -DestinationPath .\archive.zip + Compress-Archive -Path .\xmake -DestinationPath .\archive.zip -CompressionLevel Optimal Push-AppveyorArtifact .\archive.zip -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" test_script: - ps: | - Get-Command xmake xmake --version - xmake lua --verbose --diagnosis tests\test.lua + Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running + $time = Measure-Command { + $stdout = Invoke-Expression "xmake lua --verbose --diagnosis tests\test.lua" -ErrorVariable stderr + } + Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Passed -Duration $time.Milliseconds -StdOut $stdout -StdErr $stderr diff --git a/xmake/actions/update/main.lua b/xmake/actions/update/main.lua index 1b25bd6bc31..cab44adf335 100644 --- a/xmake/actions/update/main.lua +++ b/xmake/actions/update/main.lua @@ -301,7 +301,7 @@ function main() -- the download task local sourcedir = path.join(os.tmpdir(), "xmakesrc", version) - vprint("prepared to downlaod to temp dir %s ..", sourcedir) + vprint("prepared to download to temp dir %s ..", sourcedir) local download_task = function () for idx, url in ipairs(mainurls) do From 625ee243f954265baf280c4130ac96e331bd3e96 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 19:20:56 +0800 Subject: [PATCH 18/23] fix --- scripts/get.ps1 | 4 ---- xmake/scripts/update-script.bat | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/get.ps1 b/scripts/get.ps1 index 769585ebd0e..8bce6286142 100644 --- a/scripts/get.ps1 +++ b/scripts/get.ps1 @@ -8,10 +8,6 @@ param ( [string]$installdir = $(Join-Path $(if($env:HOME) { $env:HOME } else { "C:\" }) 'xmake') ) -echo $branch -echo $version -echo $installdir - function myExit($code) { if ($code -is [int] -and $code -ne 0) { throw $Error[0] diff --git a/xmake/scripts/update-script.bat b/xmake/scripts/update-script.bat index f0df7c1bdf3..760db081715 100644 --- a/xmake/scripts/update-script.bat +++ b/xmake/scripts/update-script.bat @@ -1,7 +1,7 @@ @echo off echo Removing old files -cd "%~1" +cd /d "%~1" del actions core includes languages modules platforms plugins repository rules scripts templates themes /S /Q /F >nul echo Copying from temp directory to "%~1" xcopy "%~2" "%~1" /S /Y /Q >nul \ No newline at end of file From eb7d9a02a1a848a576f2f87943f252d3f7027c39 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 19:34:14 +0800 Subject: [PATCH 19/23] fix test outcome --- .appveyor.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 63cf3831ba5..8ccc2666065 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -33,7 +33,8 @@ test_script: xmake --version Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running $time = Measure-Command { - $stdout = Invoke-Expression "xmake lua --verbose --diagnosis tests\test.lua" -ErrorVariable stderr + $stdout = xmake lua --verbose --diagnosis tests\test.lua 2>&1 + $outcome = if ($?) { "Passed" } else { "Failed" } } - Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Passed -Duration $time.Milliseconds -StdOut $stdout -StdErr $stderr + Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome $outcome -Duration $time.Milliseconds -StdOut $stdout From 066367227227591183296ee131a8fb532005d166 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 19:48:56 +0800 Subject: [PATCH 20/23] fix test time --- .appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 8ccc2666065..30668b25507 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -34,7 +34,8 @@ test_script: Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running $time = Measure-Command { $stdout = xmake lua --verbose --diagnosis tests\test.lua 2>&1 + Write-Host $stdout $outcome = if ($?) { "Passed" } else { "Failed" } } - Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome $outcome -Duration $time.Milliseconds -StdOut $stdout + Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome $outcome -Duration $time.TotalMilliseconds -StdOut $stdout From 9411dfe71fcbb8048e93d954f5004850beec8b30 Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 19:55:15 +0800 Subject: [PATCH 21/23] fix stdout --- .appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 30668b25507..03752747f4a 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -33,8 +33,8 @@ test_script: xmake --version Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running $time = Measure-Command { - $stdout = xmake lua --verbose --diagnosis tests\test.lua 2>&1 - Write-Host $stdout + $results = xmake lua --verbose --diagnosis tests\test.lua 2>&1 + $stdout = [string]::Join("`n", $results) $outcome = if ($?) { "Passed" } else { "Failed" } } Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome $outcome -Duration $time.TotalMilliseconds -StdOut $stdout From b175f88ac1c2557be21e186be4f23dae5fc7c03c Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 20:10:29 +0800 Subject: [PATCH 22/23] add some Artifact --- .appveyor.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 03752747f4a..fe31e67fad4 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,28 +9,28 @@ platform: - Win64 install: - - ps: | - ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH + - ps: ./scripts/get.ps1 -branch $env:APPVEYOR_REPO_BRANCH build_script: - - ps: | - Get-Command xmake - xmake --version - xmake build --project=core + - ps: Get-Command xmake + - ps: xmake --version + - ps: xmake build --project=core + - ps: |- Set-AppveyorBuildVariable -Name XMAKE_PROGRAM_DIR -Value $(Join-Path $(Get-Location) "xmake") .\core\build\xmake.exe --version Copy-Item -Force core\build\xmake.exe $(Get-Command xmake).Source after_build: - - ps: | + - ps: |- Copy-Item .\core\build\xmake.exe .\xmake Copy-Item .\*.md .\xmake Compress-Archive -Path .\xmake -DestinationPath .\archive.zip -CompressionLevel Optimal - Push-AppveyorArtifact .\archive.zip -FileName xmake.zip -DeploymentName "xmake-$($env:PLATFORM)" + Push-AppveyorArtifact .\xmake\xmake.exe -FileName xmake.exe -DeploymentName "xmake-executable" + Push-AppveyorArtifact .\archive.zip -FileName xmake.zip -DeploymentName "xmake-archive" test_script: - - ps: | - xmake --version + - ps: xmake --version + - ps: |- Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running $time = Measure-Command { $results = xmake lua --verbose --diagnosis tests\test.lua 2>&1 From b4c94415e8c7ee24cb3f8c0ba6e0536282121adf Mon Sep 17 00:00:00 2001 From: OpportunityLiu Date: Thu, 6 Jun 2019 20:15:34 +0800 Subject: [PATCH 23/23] fix --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index fe31e67fad4..48a726de39e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -34,8 +34,8 @@ test_script: Add-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome Running $time = Measure-Command { $results = xmake lua --verbose --diagnosis tests\test.lua 2>&1 - $stdout = [string]::Join("`n", $results) $outcome = if ($?) { "Passed" } else { "Failed" } + $stdout = [string]::Join("`n", $results) } Update-AppveyorTest -Name "tests" -Framework "xmake-test" -FileName ./tests/test.lua -Outcome $outcome -Duration $time.TotalMilliseconds -StdOut $stdout