summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-05-23 00:53:13 +0800
committerruki <[email protected]>2018-05-22 23:19:23 +0800
commit6f36d0d4e5ce896424c51df8e544506f54660a44 (patch)
treef4d7adea03580e5cbc2443a808de5deea047819c
parent05d6bbc8e13e92fccc514dccca2fdbb9dd1be4c6 (diff)
add wdk.sign.test
-rw-r--r--tests/projects/wdk/wdm/msdsm/xmake.lua2
-rw-r--r--xmake/actions/build/builder.lua34
-rw-r--r--xmake/rules/wdk/inf.lua89
-rw-r--r--xmake/rules/wdk/man/xmake.lua4
-rw-r--r--xmake/rules/wdk/mof/xmake.lua4
-rw-r--r--xmake/rules/wdk/sign/test/xmake.lua78
-rw-r--r--xmake/rules/wdk/tracewpp.lua124
7 files changed, 323 insertions, 12 deletions
diff --git a/tests/projects/wdk/wdm/msdsm/xmake.lua b/tests/projects/wdk/wdm/msdsm/xmake.lua
index 7611b0f27..a30ddb29b 100644
--- a/tests/projects/wdk/wdm/msdsm/xmake.lua
+++ b/tests/projects/wdk/wdm/msdsm/xmake.lua
@@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release")
target("msdsm")
-- add rules
- add_rules("wdk.wdm.driver")
+ add_rules("wdk.wdm.driver", "wdk.sign.test")
-- add flags for rule: wdk.tracewpp
add_values("wdk.tracewpp.flags", "-func:TracePrint((LEVEL,FLAGS,MSG,...))")
diff --git a/xmake/actions/build/builder.lua b/xmake/actions/build/builder.lua
index d69322da1..d179ec256 100644
--- a/xmake/actions/build/builder.lua
+++ b/xmake/actions/build/builder.lua
@@ -62,34 +62,54 @@ function _build_target(target)
-- the target scripts
local scripts =
{
- target:script("build_before")
- , function (target)
+ function (target)
+
+ -- get progress
+ local progress = _g.targetindex * 100 / _g.targetcount
+
+ -- do before build for target
+ local before_build = target:script("build_before")
+ if before_build then
+ before_build(target, {progress = progress})
+ end
+
+ -- do before build for rules
for _, r in ipairs(target:orderules()) do
local before_build = r:script("build_before")
if before_build then
- before_build(target)
+ before_build(target, {progress = progress})
end
end
end
, target:script("build", _on_build_target)
, function (target)
+
+ -- get progress
+ local progress = (_g.targetindex + 1) * 100 / _g.targetcount
+
+ -- do after build for target
+ local after_build = target:script("build_after")
+ if after_build then
+ after_build(target, {progress = progress})
+ end
+
+ -- do after build for rules
for _, r in ipairs(target:orderules()) do
local after_build = r:script("build_after")
if after_build then
- after_build(target)
+ after_build(target, {progress = progress})
end
end
end
- , target:script("build_after")
}
-- clean target if rebuild
if option.get("rebuild") then
_clean_target(target)
end
-
+
-- run the target scripts
- for i = 1, 5 do
+ for i = 1, 3 do
local script = scripts[i]
if script ~= nil then
script(target)
diff --git a/xmake/rules/wdk/inf.lua b/xmake/rules/wdk/inf.lua
new file mode 100644
index 000000000..72b8581c3
--- /dev/null
+++ b/xmake/rules/wdk/inf.lua
@@ -0,0 +1,89 @@
+--!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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file inf.lua
+--
+
+-- define rule: *.inf
+rule("wdk.inf")
+
+ -- add rule: wdk environment
+ add_deps("wdk.env")
+
+ -- set extensions
+ set_extensions(".inf", ".inx")
+
+ -- on load
+ on_load(function (target)
+
+ -- imports
+ import("core.project.config")
+
+ -- get arch
+ local arch = assert(config.arch(), "arch not found!")
+
+ -- get stampinf
+ local stampinf = path.join(target:data("wdk").bindir, arch, "stampinf.exe")
+ assert(stampinf and os.isexec(stampinf), "stampinf not found!")
+
+ -- save uic
+ target:data_set("wdk.stampinf", stampinf)
+ end)
+
+ -- on build file
+ on_build_file(function (target, sourcefile, opt)
+
+ -- imports
+ import("core.base.option")
+ import("core.project.depend")
+
+ -- the target file
+ local targetfile = path.join(target:targetdir(), path.basename(sourcefile) .. ".inf")
+
+ -- add clean files
+ target:data_add("wdk.cleanfiles", targetfile)
+
+ -- need build this object?
+ local dependfile = target:dependfile(targetfile)
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile)}) then
+ return
+ end
+
+ -- trace progress info
+ if option.get("verbose") then
+ cprint("${green}[%02d%%]:${dim} compiling.wdk.inf %s", opt.progress, sourcefile)
+ else
+ cprint("${green}[%02d%%]:${clear} compiling.wdk.inf %s", opt.progress, sourcefile)
+ end
+
+ -- get stampinf
+ local stampinf = target:data("wdk.stampinf")
+
+ -- update the timestamp
+ os.cp(sourcefile, targetfile)
+ os.vrunv(stampinf, {"-d", "*", "-a", is_arch("x64") and "arm64" or "x86", "-v", "*", "-f", targetfile}, {wildcards = false})
+
+ -- update files and values to the dependent file
+ dependinfo.files = {sourcefile}
+ depend.save(dependinfo, dependfile)
+ end)
+
diff --git a/xmake/rules/wdk/man/xmake.lua b/xmake/rules/wdk/man/xmake.lua
index 3e40b983b..4bda72992 100644
--- a/xmake/rules/wdk/man/xmake.lua
+++ b/xmake/rules/wdk/man/xmake.lua
@@ -44,9 +44,9 @@ rule("wdk.man")
local wdk = target:data("wdk")
-- get ctrpp
- local ctrpp = path.join(wdk.bindir, arch, is_host("windows") and "ctrpp.exe" or "ctrpp")
+ local ctrpp = path.join(wdk.bindir, arch, "ctrpp.exe")
if not os.isexec(ctrpp) then
- ctrpp = path.join(wdk.bindir, wdk.sdkver, arch, is_host("windows") and "ctrpp.exe" or "ctrpp")
+ ctrpp = path.join(wdk.bindir, wdk.sdkver, arch, "ctrpp.exe")
end
assert(os.isexec(ctrpp), "ctrpp not found!")
diff --git a/xmake/rules/wdk/mof/xmake.lua b/xmake/rules/wdk/mof/xmake.lua
index af8459392..22ffe176c 100644
--- a/xmake/rules/wdk/mof/xmake.lua
+++ b/xmake/rules/wdk/mof/xmake.lua
@@ -56,9 +56,9 @@ rule("wdk.mof")
-- get wmimofck
local wmimofck = nil
if arch == "x64" then
- wmimofck = path.join(wdk.bindir, wdk.sdkver, "x86", "x64", is_host("windows") and "wmimofck.exe" or "wmimofck")
+ wmimofck = path.join(wdk.bindir, wdk.sdkver, "x86", "x64", "wmimofck.exe")
else
- wmimofck = path.join(wdk.bindir, wdk.sdkver, "x86", is_host("windows") and "wmimofck.exe" or "wmimofck")
+ wmimofck = path.join(wdk.bindir, wdk.sdkver, "x86", "wmimofck.exe")
end
assert(wmimofck and os.isexec(wmimofck), "wmimofck not found!")
diff --git a/xmake/rules/wdk/sign/test/xmake.lua b/xmake/rules/wdk/sign/test/xmake.lua
new file mode 100644
index 000000000..dc8a7b12b
--- /dev/null
+++ b/xmake/rules/wdk/sign/test/xmake.lua
@@ -0,0 +1,78 @@
+--!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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file xmake.lua
+--
+
+-- define rule: sign.test
+rule("wdk.sign.test")
+
+ -- add rule: wdk environment
+ add_deps("wdk.env")
+
+ -- after build
+ after_build(function (target, opt)
+
+ -- imports
+ import("core.base.option")
+ import("core.project.config")
+
+ -- trace progress info
+ cprintf("${green}[%02d%%]:${clear} ", opt.progress)
+ if option.get("verbose") then
+ cprint("${dim magenta}signing.test %s", path.filename(target:targetfile()))
+ else
+ cprint("${magenta}signing.test %s", path.filename(target:targetfile()))
+ end
+
+ -- get wdk
+ local wdk = target:data("wdk")
+
+ -- get arch
+ local arch = assert(config.arch(), "arch not found!")
+
+ -- get signtool
+ local signtool = path.join(wdk.bindir, arch, "signtool.exe")
+ if not os.isexec(signtool) then
+ signtool = path.join(wdk.bindir, wdk.sdkver, arch, "signtool.exe")
+ end
+ assert(os.isexec(signtool), "signtool not found!")
+
+ -- try to get certificate info
+ local certinfo = try
+ {
+ function ()
+ return os.iorun("certutil -store -user my")
+ end
+ }
+ assert(certinfo, "cannot get certificate info in local machine!")
+
+ -- trace certificate info
+ if option.get("verbose") then
+ print(certinfo)
+ end
+
+ -- get thumbprint from certificate info
+ local thumbprint = certinfo:match("sha1.-: (%w+)")
+ print(thumbprint)
+ end)
+
+
diff --git a/xmake/rules/wdk/tracewpp.lua b/xmake/rules/wdk/tracewpp.lua
new file mode 100644
index 000000000..c450a27e8
--- /dev/null
+++ b/xmake/rules/wdk/tracewpp.lua
@@ -0,0 +1,124 @@
+--!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 - 2018, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file tracewpp.lua
+--
+
+-- define rule: tracewpp
+rule("wdk.tracewpp")
+
+ -- add rule: wdk environment
+ add_deps("wdk.env")
+
+ -- on load
+ on_load(function (target)
+
+ -- imports
+ import("core.project.config")
+
+ -- get wdk
+ local wdk = target:data("wdk")
+
+ -- get arch
+ local arch = assert(config.arch(), "arch not found!")
+
+ -- get tracewpp
+ local tracewpp = path.join(wdk.bindir, arch, "tracewpp.exe")
+ assert(tracewpp and os.isexec(tracewpp), "tracewpp not found!")
+
+ -- save tracewpp
+ target:data_set("wdk.tracewpp", tracewpp)
+
+ -- save output directory
+ target:data_set("wdk.tracewpp.outputdir", path.join(config.buildir(), ".wpp", config.get("mode") or "generic", config.get("arch") or os.arch(), target:name()))
+
+ -- save config directory
+ target:data_set("wdk.tracewpp.configdir", path.join(wdk.bindir, wdk.sdkver, "WppConfig", "Rev1"))
+ end)
+
+ -- before build file
+ before_build_file(function (target, sourcefile, opt)
+
+ -- imports
+ import("core.base.option")
+ import("core.project.depend")
+
+ -- get tracewpp
+ local tracewpp = target:data("wdk.tracewpp")
+
+ -- get outputdir
+ local outputdir = target:data("wdk.tracewpp.outputdir")
+
+ -- get configdir
+ local configdir = target:data("wdk.tracewpp.configdir")
+
+ -- init args
+ local args = {}
+ if target:rule("wdk.kmdf.driver") then
+ table.insert(args, "-km")
+ table.insert(args, "-gen:{km-WdfDefault.tpl}*.tmh")
+ end
+ local flags = target:values("wdk.tracewpp.flags")
+ if flags then
+ table.join2(args, flags)
+ end
+ table.insert(args, "-cfgdir:" .. configdir)
+ table.insert(args, "-odir:" .. outputdir)
+ table.insert(args, sourcefile)
+
+ -- add includedirs
+ target:add("includedirs", outputdir)
+
+ -- add clean files
+ target:data_add("wdk.cleanfiles", outputdir)
+
+ -- need build this object?
+ local targetfile = path.join(outputdir, path.basename(sourcefile) .. ".tmh")
+ local dependfile = target:dependfile(targetfile)
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile), values = args}) then
+ return
+ end
+
+ -- trace progress info
+ if option.get("verbose") then
+ cprint("${green}[%02d%%]:${dim} compiling.wdk.tracewpp %s", opt.progress, sourcefile)
+ else
+ cprint("${green}[%02d%%]:${clear} compiling.wdk.tracewpp %s", opt.progress, sourcefile)
+ end
+
+ -- ensure the output directory
+ if not os.isdir(outputdir) then
+ os.mkdir(outputdir)
+ end
+
+ -- remove the previous target file first
+ os.tryrm(targetfile)
+
+ -- generate the *.tmh file
+ os.vrunv(tracewpp, args, {wildcards = false})
+
+ -- update files and values to the dependent file
+ dependinfo.files = {sourcefile}
+ dependinfo.values = args
+ depend.save(dependinfo, dependfile)
+ end)
+