summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2018-05-24 23:23:33 +0800
committerruki <[email protected]>2018-05-24 14:21:22 +0800
commitca171c7042ddef339aa21a62065f96479125459b (patch)
tree93e202d179b4f6d8d48eefd8a2d2e31216e730c8
parentdbfe733eb8610343396590cebd037de19c1753cc (diff)
improve sign
-rw-r--r--tests/projects/wdk/kmdf/ioctl/xmake.lua2
-rw-r--r--tests/projects/wdk/kmdf/serial/xmake.lua2
-rw-r--r--tests/projects/wdk/umdf/echo/xmake.lua2
-rw-r--r--tests/projects/wdk/umdf/skeleton/xmake.lua2
-rw-r--r--tests/projects/wdk/wdm/msdsm/xmake.lua2
-rw-r--r--tests/projects/wdk/wdm/perfcounters/xmake.lua2
-rw-r--r--xmake/rules/wdk/sign/sign.lua99
-rw-r--r--xmake/rules/wdk/sign/xmake.lua (renamed from xmake/rules/wdk/sign/test/xmake.lua)110
-rw-r--r--xmake/rules/wdk/xmake.lua6
9 files changed, 176 insertions, 51 deletions
diff --git a/tests/projects/wdk/kmdf/ioctl/xmake.lua b/tests/projects/wdk/kmdf/ioctl/xmake.lua
index 0fe5dda38..6c7c6f7a7 100644
--- a/tests/projects/wdk/kmdf/ioctl/xmake.lua
+++ b/tests/projects/wdk/kmdf/ioctl/xmake.lua
@@ -9,7 +9,7 @@ add_includedirs(".")
target("nonpnp")
-- add rules
- add_rules("wdk.kmdf.driver", "wdk.sign.test")
+ add_rules("wdk.kmdf.driver")
-- add flags for rule: wdk.tracewpp
add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))")
diff --git a/tests/projects/wdk/kmdf/serial/xmake.lua b/tests/projects/wdk/kmdf/serial/xmake.lua
index 09c4dfd89..f3b55d5d9 100644
--- a/tests/projects/wdk/kmdf/serial/xmake.lua
+++ b/tests/projects/wdk/kmdf/serial/xmake.lua
@@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release")
target("wdfserial")
-- add rules
- add_rules("wdk.kmdf.driver", "wdk.sign.test")
+ add_rules("wdk.kmdf.driver")
-- add flags for rule: wdk.tracewpp
add_values("wdk.tracewpp.flags", "-func:SerialDbgPrintEx(LEVEL,FLAGS,MSG,...)")
diff --git a/tests/projects/wdk/umdf/echo/xmake.lua b/tests/projects/wdk/umdf/echo/xmake.lua
index 64a25a118..45ec8ec9d 100644
--- a/tests/projects/wdk/umdf/echo/xmake.lua
+++ b/tests/projects/wdk/umdf/echo/xmake.lua
@@ -9,7 +9,7 @@ add_defines("_UNICODE", "UNICODE")
target("echo")
-- add rules
- add_rules("wdk.umdf.driver", "wdk.sign.test")
+ add_rules("wdk.umdf.driver")
-- add files
add_files("driver/*.c")
diff --git a/tests/projects/wdk/umdf/skeleton/xmake.lua b/tests/projects/wdk/umdf/skeleton/xmake.lua
index 0f245bcbb..75e5ec7e1 100644
--- a/tests/projects/wdk/umdf/skeleton/xmake.lua
+++ b/tests/projects/wdk/umdf/skeleton/xmake.lua
@@ -9,7 +9,7 @@ add_defines("_UNICODE", "UNICODE")
target("UMDFSkeleton")
-- add rules
- add_rules("wdk.umdf.driver", "wdk.sign.test")
+ add_rules("wdk.umdf.driver")
-- add flags fro tracewpp
add_values("wdk.tracewpp.flags", "-scan:internal.h")
diff --git a/tests/projects/wdk/wdm/msdsm/xmake.lua b/tests/projects/wdk/wdm/msdsm/xmake.lua
index 36f29a4fd..ea8886d83 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("sampledsm")
-- add rules
- add_rules("wdk.wdm.driver", "wdk.sign.test")
+ add_rules("wdk.wdm.driver")
-- add flags for rule: wdk.tracewpp
add_values("wdk.tracewpp.flags", "-func:TracePrint((LEVEL,FLAGS,MSG,...))")
diff --git a/tests/projects/wdk/wdm/perfcounters/xmake.lua b/tests/projects/wdk/wdm/perfcounters/xmake.lua
index de86d9b53..fb0bc3d54 100644
--- a/tests/projects/wdk/wdm/perfcounters/xmake.lua
+++ b/tests/projects/wdk/wdm/perfcounters/xmake.lua
@@ -6,7 +6,7 @@ add_rules("mode.debug", "mode.release")
target("kcs")
-- add rules
- add_rules("wdk.wdm.driver", "wdk.sign.test")
+ add_rules("wdk.wdm.driver")
-- add flags for rule: wdk.man
add_values("wdk.man.prefix", "Kcs")
diff --git a/xmake/rules/wdk/sign/sign.lua b/xmake/rules/wdk/sign/sign.lua
new file mode 100644
index 000000000..2480c54c2
--- /dev/null
+++ b/xmake/rules/wdk/sign/sign.lua
@@ -0,0 +1,99 @@
+--!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 sign.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.project.config")
+
+-- get sign tool
+function _get_signtool(target)
+
+ -- get it from the cache
+ local signtool = _g.signtool
+ if not signtool then
+
+ -- get wdk
+ local wdk = target:data("wdk")
+
+ -- get arch
+ local arch = assert(config.arch(), "arch not found!")
+
+ -- get signtool
+ 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!")
+ _g.signtool = signtool
+ end
+ return signtool
+end
+
+-- get thumbprint
+function _get_thumbprint(target)
+
+ -- get it from the cache
+ local thumbprint = _g.thumbprint
+ if not thumbprint then
+
+ -- 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
+ thumbprint = (certinfo:match("sha1.-: (%w+)") or ""):trim()
+ assert(#thumbprint > 0, "cannot get thumbprint of certificate!")
+ _g.thumbprint = thumbprint
+ end
+ return thumbprint
+end
+
+-- do sign
+function main(target, filepath, mode)
+
+ -- sign is disabled?
+ local enabled = target:values("wdk.sign.enabled")
+ if enabled == false then
+ return
+ end
+
+ -- get signtool
+ local signtool = _get_signtool(target)
+
+ -- get thumbprint
+ local thumbprint = _get_thumbprint(target)
+
+ -- sign the target file
+ os.vrunv(signtool, {"sign", "/ph", "/sha1", thumbprint, filepath})
+end
diff --git a/xmake/rules/wdk/sign/test/xmake.lua b/xmake/rules/wdk/sign/xmake.lua
index ce08a644f..5ba60f785 100644
--- a/xmake/rules/wdk/sign/test/xmake.lua
+++ b/xmake/rules/wdk/sign/xmake.lua
@@ -22,16 +22,48 @@
-- @file xmake.lua
--
--- define rule: sign.test
-rule("wdk.sign.test")
+-- define rule: sign
+--
+-- values:
+-- - wdk.sign.enabled: true/false (default: true)
+-- - wdk.sign.mode: test/release (default: test)
+-- - wdk.sign.company: tboox.org
+-- - wdk.sign.timestamp: http://timestamp.verisign.com/scripts/timstamp.dll
+--
+rule("wdk.sign")
-- 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 inf2cat
+ local inf2cat = path.join(wdk.bindir, arch, "inf2cat.exe")
+ if not os.isexec(inf2cat) then
+ inf2cat = path.join(wdk.bindir, wdk.sdkver, arch, "inf2cat.exe")
+ end
+ if not os.isexec(inf2cat) then
+ inf2cat = path.join(wdk.bindir, wdk.sdkver, "x86", "inf2cat.exe")
+ end
+ assert(os.isexec(inf2cat), "inf2cat not found!")
+ target:data_set("wdk.sign.inf2cat", inf2cat)
+ end)
+
-- after build
after_build(function (target, opt)
-- imports
+ import("sign")
import("core.base.option")
import("core.project.config")
import("core.project.depend")
@@ -45,60 +77,28 @@ rule("wdk.sign.test")
return
end
+ -- get sign mode
+ local signmode = target:values("wdk.sign.mode") or "test"
+
-- add clean files
target:data_add("wdk.cleanfiles", {tempfile, dependfile})
-- trace progress info
cprintf("${green}[%02d%%]:${clear} ", opt.progress)
if option.get("verbose") then
- cprint("${dim magenta}signing.test %s", path.filename(target:targetfile()))
+ cprint("${dim magenta}signing.%s %s", signmode, path.filename(target:targetfile()))
else
- cprint("${magenta}signing.test %s", path.filename(target:targetfile()))
+ cprint("${magenta}signing.%s %s", signmode, 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!")
-
-- get inf2cat
- local inf2cat = path.join(wdk.bindir, arch, "inf2cat.exe")
- if not os.isexec(inf2cat) then
- inf2cat = path.join(wdk.bindir, wdk.sdkver, arch, "inf2cat.exe")
- end
- if not os.isexec(inf2cat) then
- inf2cat = path.join(wdk.bindir, wdk.sdkver, "x86", "inf2cat.exe")
- end
- assert(os.isexec(inf2cat), "inf2cat 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+)") or ""):trim()
- assert(#thumbprint > 0, "cannot get thumbprint of certificate!")
+ local inf2cat = target:data("wdk.sign.inf2cat")
-- sign the target file
- os.vrunv(signtool, {"sign", "/ph", "/sha1", thumbprint, target:targetfile()})
+ sign(target, target:targetfile(), signmode)
-- get inf file
local infile = target:data("wdk.sign.inf")
@@ -116,7 +116,7 @@ rule("wdk.sign.test")
assert(catfile, "*.cat not found!")
-- sign *.cat file
- os.vrunv(signtool, {"sign", "/ph", "/sha1", thumbprint, catfile})
+ sign(target, catfile, signmode)
else
-- trace
vprint("Inf2Cat task was skipped as there were no inf files to process")
@@ -128,4 +128,30 @@ rule("wdk.sign.test")
io.writefile(tempfile, "")
end)
+ -- after package
+ after_package(function (target)
+
+ -- imports
+ import("sign")
+ import("core.base.option")
+
+ -- get signtool
+ local signtool = target:data("wdk.sign.signtool")
+
+ -- get package file
+ local packagefile = target:data("wdk.sign.cab")
+ assert(packagefile and os.isfile(packagefile), "the driver package file(.cab) not found!")
+ -- get sign mode
+ local signmode = target:values("wdk.sign.mode") or "test"
+
+ -- trace progress info
+ if option.get("verbose") then
+ cprint("${dim magenta}signing.%s %s", signmode, path.filename(packagefile))
+ else
+ cprint("${magenta}signing.%s %s", signmode, path.filename(packagefile))
+ end
+
+ -- sign package file
+ sign(target, packagefile, signmode)
+ end)
diff --git a/xmake/rules/wdk/xmake.lua b/xmake/rules/wdk/xmake.lua
index 97a851052..4b39b9d47 100644
--- a/xmake/rules/wdk/xmake.lua
+++ b/xmake/rules/wdk/xmake.lua
@@ -26,7 +26,7 @@
rule("wdk.umdf.driver")
-- add rules
- add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.package.cab")
+ add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.sign", "wdk.package.cab")
-- on load
on_load(function (target)
@@ -48,7 +48,7 @@ rule("wdk.umdf.binary")
rule("wdk.kmdf.driver")
-- add rules
- add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.package.cab")
+ add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.sign", "wdk.package.cab")
-- on load
on_load(function (target)
@@ -86,7 +86,7 @@ rule("wdk.kmdf.binary")
rule("wdk.wdm.driver")
-- add rules
- add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.package.cab")
+ add_deps("wdk.inf", "wdk.man", "wdk.mc", "wdk.mof", "wdk.sign", "wdk.package.cab")
-- on load
on_load(function (target)