diff options
| author | ruki <[email protected]> | 2017-09-14 22:45:12 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-09-14 10:31:14 +0800 |
| commit | 9b5dfae7e222ad3cdd293cbc962b6b9dc96590a6 (patch) | |
| tree | a46c647f933c36bfee392dbbad5e707a2e97fcc1 /xmake | |
| parent | b27b6447c072d357db96d17500c73bf9013b8c5c (diff) | |
add github traffic statistics
Diffstat (limited to 'xmake')
| -rw-r--r-- | xmake/actions/build/main.lua | 4 | ||||
| -rw-r--r-- | xmake/actions/build/statistics.lua | 85 | ||||
| -rw-r--r-- | xmake/core/sandbox/modules/process.lua | 9 |
3 files changed, 95 insertions, 3 deletions
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 |
