summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-09-14 22:45:12 +0800
committerruki <[email protected]>2017-09-14 10:31:14 +0800
commit9b5dfae7e222ad3cdd293cbc962b6b9dc96590a6 (patch)
treea46c647f933c36bfee392dbbad5e707a2e97fcc1
parentb27b6447c072d357db96d17500c73bf9013b8c5c (diff)
add github traffic statistics
-rw-r--r--core/src/tbox/src/tbox/platform/posix/process.c13
-rw-r--r--core/src/tbox/src/tbox/platform/windows/process.c13
-rw-r--r--xmake/actions/build/main.lua4
-rw-r--r--xmake/actions/build/statistics.lua85
-rw-r--r--xmake/core/sandbox/modules/process.lua9
5 files changed, 95 insertions, 29 deletions
diff --git a/core/src/tbox/src/tbox/platform/posix/process.c b/core/src/tbox/src/tbox/platform/posix/process.c
index e59613777..34d606a27 100644
--- a/core/src/tbox/src/tbox/platform/posix/process.c
+++ b/core/src/tbox/src/tbox/platform/posix/process.c
@@ -480,19 +480,6 @@ tb_void_t tb_process_exit(tb_process_ref_t self)
tb_process_t* process = (tb_process_t*)self;
tb_assert_and_check_return(process);
- // the process has not exited?
- if (process->pid > 0)
- {
- // trace
- tb_trace_e("kill: %ld ..", process->pid);
-
- // kill it first
- tb_process_kill(self);
-
- // wait it again
- tb_process_wait(self, tb_null, -1);
- }
-
#ifdef TB_CONFIG_POSIX_HAVE_POSIX_SPAWNP
// close the stdout
diff --git a/core/src/tbox/src/tbox/platform/windows/process.c b/core/src/tbox/src/tbox/platform/windows/process.c
index c8768c47f..47afed967 100644
--- a/core/src/tbox/src/tbox/platform/windows/process.c
+++ b/core/src/tbox/src/tbox/platform/windows/process.c
@@ -311,19 +311,6 @@ tb_void_t tb_process_exit(tb_process_ref_t self)
tb_process_t* process = (tb_process_t*)self;
tb_assert_and_check_return(process);
- // the process has not exited?
- if (process->pi.hProcess != INVALID_HANDLE_VALUE)
- {
- // trace
- tb_trace_e("kill: %u ..", process->pi.dwProcessId);
-
- // kill it first
- tb_process_kill(self);
-
- // wait it again
- tb_process_wait(self, tb_null, -1);
- }
-
// close thread handle
if (process->pi.hThread != INVALID_HANDLE_VALUE)
tb_kernel32()->CloseHandle(process->pi.hThread);
diff --git a/xmake/actions/build/main.lua b/xmake/actions/build/main.lua
index 6206e5e4e..875d77009 100644
--- a/xmake/actions/build/main.lua
+++ b/xmake/actions/build/main.lua
@@ -29,6 +29,7 @@ import("core.project.config")
import("core.project.project")
import("core.platform.platform")
import("builder")
+import("statistics")
-- main
function main()
@@ -42,6 +43,9 @@ function main()
-- enter project directory
local oldir = os.cd(project.directory())
+ -- post statistics
+ statistics.post()
+
-- build it
try
{
diff --git a/xmake/actions/build/statistics.lua b/xmake/actions/build/statistics.lua
new file mode 100644
index 000000000..1d82c80e7
--- /dev/null
+++ b/xmake/actions/build/statistics.lua
@@ -0,0 +1,85 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file statistics.lua
+--
+
+-- imports
+import("core.base.option")
+
+-- post statistics info and only post once everyday when building each project
+--
+-- clone the xmake-stats repo to update the traffic(git clones) info in github
+--
+-- the traffic info in github (just be approximate numbers):
+--
+-- Clones: the number of projects which build using xmake everyday
+-- Unique cloners: the number of users everyday
+--
+function post()
+
+ -- get the project directory name
+ local projectname = path.basename(os.projectdir())
+
+ -- has been posted today or statistics is disable?
+ local outputdir = path.join(os.tmpdir(), "stats", os.date("%y%m%d"), projectname)
+ if os.isdir(outputdir) or os.getenv("XMAKE_STATS") == "disable" then
+ return
+ end
+
+ -- init argument list
+ local argv = {"lua", path.join(os.scriptdir(), "statistics.lua")}
+ for _, name in ipairs({"root", "file", "project", "backtrace", "verbose", "quiet"}) do
+ local value = option.get(name)
+ if type(value) == "string" then
+ table.insert(argv, "--" .. name .. "=" .. value)
+ elseif value then
+ table.insert(argv, "--" .. name)
+ end
+ end
+
+ -- post it in background
+ local proc = process.openv("xmake", argv, os.tmpfile() .. ".stats.log")
+ if proc ~= nil then
+ process.close(proc)
+ end
+end
+
+-- the main function
+function main()
+
+ -- in project?
+ if not os.isfile(os.projectfile()) then
+ return
+ end
+
+ -- get the project directory name
+ local projectname = path.basename(os.projectdir())
+
+ -- TODO git on windows
+ -- clone the xmake-stats repo to update the traffic(git clones) info in github
+ local outputdir = path.join(os.tmpdir(), "stats", os.date("%y%m%d"), projectname)
+ if not os.isdir(outputdir) then
+ import("devel.git.clone")
+ clone("https://github.com/tboox/xmake-stats.git", {depth = 1, branch = "master", outputdir = outputdir})
+ print("post ok!")
+ end
+end
diff --git a/xmake/core/sandbox/modules/process.lua b/xmake/core/sandbox/modules/process.lua
index cc4282702..6c71bb522 100644
--- a/xmake/core/sandbox/modules/process.lua
+++ b/xmake/core/sandbox/modules/process.lua
@@ -61,11 +61,14 @@ function sandbox_process.open(command, outfile, errfile)
end
-- open process with arguments
-function sandbox_process.openv(argv, outfile, errfile)
+function sandbox_process.openv(filename, argv, outfile, errfile)
-- check
assert(argv)
+ -- format filename first
+ filename = vformat(filename)
+
-- format output file if exists
if outfile then
outfile = vformat(outfile)
@@ -77,9 +80,9 @@ function sandbox_process.openv(argv, outfile, errfile)
end
-- open process
- local proc = process.openv(argv, outfile, errfile)
+ local proc = process.openv(filename, argv, outfile, errfile)
if not proc then
- raise("openv process(%s) failed!", table.concat(argv, " "))
+ raise("openv process(%s, %s) failed!", filename, table.concat(argv, " "))
end
-- ok