Move the signing stuff out of cmake

This commit is contained in:
Chris Marsh 2017-11-29 14:00:28 -08:00
parent 8cae35ea46
commit b01d0a8af3
3 changed files with 32 additions and 40 deletions

View file

@ -4,7 +4,6 @@ project (DiscordRPC)
include(GNUInstallDirs) include(GNUInstallDirs)
option(BUILD_EXAMPLES "Build example apps" ON) option(BUILD_EXAMPLES "Build example apps" ON)
option(SIGN_BUILD "Sign resulting dll with digital cert" OFF)
# format # format
file(GLOB_RECURSE ALL_SOURCE_FILES file(GLOB_RECURSE ALL_SOURCE_FILES
@ -55,15 +54,3 @@ add_subdirectory(src)
if (BUILD_EXAMPLES) if (BUILD_EXAMPLES)
add_subdirectory(examples/send-presence) add_subdirectory(examples/send-presence)
endif(BUILD_EXAMPLES) endif(BUILD_EXAMPLES)
# sign builds
if (SIGN_BUILD)
if(WIN32)
find_program(SIGNTOOL_EXECUTABLE signtool)
endif(WIN32)
if (APPLE)
find_program(SIGNTOOL_EXECUTABLE codesign)
endif(APPLE)
# todo linux? gpg sign a hash maybe? does anyone care/check these?
endif(SIGN_BUILD)

View file

@ -9,11 +9,6 @@ from contextlib import contextmanager
import click import click
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
# we use Buildkite which sets this env variable by default
IS_BUILD_MACHINE = os.environ.get('CI', '') == 'true'
def get_platform(): def get_platform():
""" a name for the platform """ """ a name for the platform """
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
@ -25,6 +20,22 @@ def get_platform():
raise Exception('Unsupported platform ' + sys.platform) raise Exception('Unsupported platform ' + sys.platform)
SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__))
# we use Buildkite which sets this env variable by default
IS_BUILD_MACHINE = os.environ.get('CI', '') == 'true'
PLATFORM = get_platform()
INSTALL_ROOT = os.path.join(SCRIPT_PATH, 'builds', 'install')
def get_signtool():
""" get path to code signing tool """
if PLATFORM == 'win':
sdk_dir = os.environ['WindowsSdkDir']
return os.path.join(sdk_dir, 'bin', 'x86', 'signtool.exe')
elif PLATFORM == 'osx':
return '/usr/bin/codesign'
@contextmanager @contextmanager
def cd(new_dir): def cd(new_dir):
""" Temporarily change current directory """ """ Temporarily change current directory """
@ -50,6 +61,8 @@ def cli(ctx, clean):
""" click wrapper for command line stuff """ """ click wrapper for command line stuff """
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
ctx.invoke(libs, clean=clean) ctx.invoke(libs, clean=clean)
if IS_BUILD_MACHINE:
ctx.invoke(sign)
ctx.invoke(archive) ctx.invoke(archive)
@ -68,7 +81,7 @@ def unreal():
def build_lib(build_name, generator, options): def build_lib(build_name, generator, options):
""" Create a dir under builds, run build and install in it """ """ Create a dir under builds, run build and install in it """
build_path = os.path.join(SCRIPT_PATH, 'builds', build_name) build_path = os.path.join(SCRIPT_PATH, 'builds', build_name)
install_path = os.path.join(SCRIPT_PATH, 'builds', 'install', build_name) install_path = os.path.join(INSTALL_ROOT, build_name)
mkdir_p(build_path) mkdir_p(build_path)
mkdir_p(install_path) mkdir_p(install_path)
with cd(build_path): with cd(build_path):
@ -98,7 +111,7 @@ def archive():
click.echo('--- Archiving') click.echo('--- Archiving')
archive_file_path = os.path.join(SCRIPT_PATH, 'builds', 'discord-rpc-%s.zip' % get_platform()) archive_file_path = os.path.join(SCRIPT_PATH, 'builds', 'discord-rpc-%s.zip' % get_platform())
archive_file = zipfile.ZipFile(archive_file_path, 'w', zipfile.ZIP_DEFLATED) archive_file = zipfile.ZipFile(archive_file_path, 'w', zipfile.ZIP_DEFLATED)
archive_src_base_path = os.path.join(SCRIPT_PATH, 'builds', 'install') archive_src_base_path = INSTALL_ROOT
archive_dst_base_path = 'discord-rpc' archive_dst_base_path = 'discord-rpc'
with cd(archive_src_base_path): with cd(archive_src_base_path):
for path, _, filenames in os.walk('.'): for path, _, filenames in os.walk('.'):
@ -110,13 +123,11 @@ def archive():
@cli.command() @cli.command()
@click.option('--tool', type=click.Path(exists=True, file_okay=True, dir_okay=False)) def sign():
@click.argument('install_paths', required=True, nargs=-1) """ Do code signing within install directory using our cert """
def sign(install_paths, tool): tool = get_signtool()
""" Do code signing or within specified directory using our cert """
platform = get_platform()
signable_extensions = set() signable_extensions = set()
if platform == 'win': if PLATFORM == 'win':
signable_extensions.add('.dll') signable_extensions.add('.dll')
sign_command_base = [ sign_command_base = [
tool, tool,
@ -128,7 +139,7 @@ def sign(install_paths, tool):
'/td', 'sha256', '/td', 'sha256',
'/fd', 'sha256', '/fd', 'sha256',
] ]
elif platform == 'osx': elif PLATFORM == 'osx':
signable_extensions.add('.dylib') signable_extensions.add('.dylib')
sign_command_base = [ sign_command_base = [
tool, tool,
@ -143,12 +154,12 @@ def sign(install_paths, tool):
return return
click.echo('--- Signing') click.echo('--- Signing')
for install_path in install_paths: for path, _, filenames in os.walk(INSTALL_ROOT):
for fname in os.listdir(install_path): for fname in filenames:
ext = os.path.splitext(fname)[1] ext = os.path.splitext(fname)[1]
if ext not in signable_extensions: if ext not in signable_extensions:
continue continue
fpath = os.path.join(install_path, fname) fpath = os.path.join(path, fname)
click.echo('Sign ' + fpath) click.echo('Sign ' + fpath)
sign_command = sign_command_base + [fpath] sign_command = sign_command_base + [fpath]
subprocess.check_call(sign_command) subprocess.check_call(sign_command)
@ -163,9 +174,7 @@ def libs(clean):
mkdir_p('builds') mkdir_p('builds')
platform = get_platform() if PLATFORM == 'win':
if platform == 'win':
generator32 = 'Visual Studio 14 2015' generator32 = 'Visual Studio 14 2015'
generator64 = 'Visual Studio 14 2015 Win64' generator64 = 'Visual Studio 14 2015 Win64'
static_options = {} static_options = {}
@ -178,10 +187,10 @@ def libs(clean):
build_lib('win32-dynamic', generator32, dynamic_options) build_lib('win32-dynamic', generator32, dynamic_options)
build_lib('win64-static', generator64, static_options) build_lib('win64-static', generator64, static_options)
build_lib('win64-dynamic', generator64, dynamic_options) build_lib('win64-dynamic', generator64, dynamic_options)
elif platform == 'osx': elif PLATFORM == 'osx':
build_lib('osx-static', None, {}) build_lib('osx-static', None, {})
build_lib('osx-dynamic', None, {'BUILD_SHARED_LIBS': True, 'SIGN_BUILD': IS_BUILD_MACHINE}) build_lib('osx-dynamic', None, {'BUILD_SHARED_LIBS': True, 'SIGN_BUILD': IS_BUILD_MACHINE})
elif platform == 'linux': elif PLATFORM == 'linux':
build_lib('linux-static', None, {}) build_lib('linux-static', None, {})
build_lib('linux-dynamic', None, {'BUILD_SHARED_LIBS': True}) build_lib('linux-dynamic', None, {'BUILD_SHARED_LIBS': True})

View file

@ -130,7 +130,3 @@ install(
"../include/discord-rpc.h" "../include/discord-rpc.h"
DESTINATION "include" DESTINATION "include"
) )
if (SIGNTOOL_EXECUTABLE)
install(CODE "execute_process(COMMAND python ${CMAKE_SOURCE_DIR}/build.py sign --tool \"${SIGNTOOL_EXECUTABLE}\" \"${CMAKE_INSTALL_PREFIX}/bin\")")
endif(SIGNTOOL_EXECUTABLE)