Fix the CI badge and fully rewrite all the workflows to make sense ##build
* Windows, Linux, Static, macOS, Android, iOS builds published for every commit
* Kept coverage, coverity, fuzzing tests, lgtm and -Werror jobs
* Kill the continuos, the over-engineered matrix and other empty or unnecessary tasks (250 vs 900LOC)
* Jobs TODO: fatmac, termux and rpm (centos) packages
2021-01-12 12:41:21 +00:00
|
|
|
#!/usr/bin/env python
|
2018-02-06 12:41:42 +00:00
|
|
|
"""Meson build for radare2"""
|
2017-12-13 14:07:01 +00:00
|
|
|
|
|
|
|
import argparse
|
2018-01-11 16:20:23 +00:00
|
|
|
import glob
|
2017-12-13 14:07:01 +00:00
|
|
|
import logging
|
|
|
|
import os
|
2018-01-05 09:20:17 +00:00
|
|
|
import re
|
2018-01-11 16:20:23 +00:00
|
|
|
import shutil
|
2017-12-13 14:07:01 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
BUILDDIR = 'build'
|
2019-09-30 04:31:40 +00:00
|
|
|
BACKENDS = ['ninja', 'vs2015', 'vs2017', 'vs2019']
|
2018-01-11 16:20:23 +00:00
|
|
|
|
|
|
|
PATH_FMT = {}
|
2018-04-29 14:03:04 +00:00
|
|
|
R2_PATH = {
|
|
|
|
'R2_LIBDIR': r'lib',
|
2018-04-30 10:38:25 +00:00
|
|
|
'R2_INCDIR': r'include',
|
2018-04-29 14:03:04 +00:00
|
|
|
'R2_DATDIR': r'share',
|
2018-04-30 10:38:25 +00:00
|
|
|
'R2_WWWROOT': r'{R2_DATDIR}\www',
|
|
|
|
'R2_SDB': r'{R2_DATDIR}',
|
|
|
|
'R2_ZIGNS': r'{R2_DATDIR}\zigns',
|
|
|
|
'R2_THEMES': r'{R2_DATDIR}\cons',
|
|
|
|
'R2_FORTUNES': r'{R2_DATDIR}\doc',
|
2018-05-26 16:12:13 +00:00
|
|
|
'R2_FLAGS': r'{R2_DATDIR}\flag',
|
2018-04-30 10:38:25 +00:00
|
|
|
'R2_HUD': r'{R2_DATDIR}\hud'
|
2018-04-29 14:03:04 +00:00
|
|
|
}
|
2018-01-11 16:20:23 +00:00
|
|
|
|
2018-02-09 08:16:15 +00:00
|
|
|
MESON = None
|
2018-01-11 16:20:23 +00:00
|
|
|
ROOT = None
|
2017-12-13 14:07:01 +00:00
|
|
|
log = None
|
|
|
|
|
2018-02-06 12:41:42 +00:00
|
|
|
def set_global_variables():
|
2018-02-20 08:33:19 +00:00
|
|
|
"""[R_API] Set global variables"""
|
2017-12-13 14:07:01 +00:00
|
|
|
global log
|
|
|
|
global ROOT
|
2018-02-09 08:16:15 +00:00
|
|
|
global MESON
|
2017-12-13 14:07:01 +00:00
|
|
|
|
2018-01-28 17:16:38 +00:00
|
|
|
ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
2017-12-13 14:07:01 +00:00
|
|
|
|
2018-02-06 12:41:42 +00:00
|
|
|
logging.basicConfig(format='[%(name)s][%(levelname)s]: %(message)s',
|
2018-02-09 08:16:15 +00:00
|
|
|
level=logging.DEBUG)
|
2017-12-13 14:07:01 +00:00
|
|
|
log = logging.getLogger('r2-meson')
|
2018-02-06 12:41:42 +00:00
|
|
|
|
|
|
|
with open(os.path.join(ROOT, 'configure.acr')) as f:
|
|
|
|
f.readline()
|
|
|
|
version = f.readline().split()[1].rstrip()
|
|
|
|
|
2018-02-09 08:16:15 +00:00
|
|
|
if os.name == 'nt':
|
2018-09-23 08:54:37 +00:00
|
|
|
meson = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'meson.exe')
|
|
|
|
if os.path.exists(meson):
|
|
|
|
MESON = [meson]
|
|
|
|
else:
|
|
|
|
meson = os.path.join(os.path.dirname(sys.executable), 'Scripts', 'meson.py')
|
|
|
|
MESON = [sys.executable, meson]
|
2018-02-09 08:16:15 +00:00
|
|
|
else:
|
|
|
|
MESON = ['meson']
|
|
|
|
|
2018-02-06 12:41:42 +00:00
|
|
|
PATH_FMT['ROOT'] = ROOT
|
|
|
|
PATH_FMT['R2_VERSION'] = version
|
|
|
|
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('Root: %s', ROOT)
|
2018-02-09 08:16:15 +00:00
|
|
|
log.debug('Meson: %s', MESON)
|
|
|
|
log.debug('Version: %s', version)
|
2017-12-13 14:07:01 +00:00
|
|
|
|
2020-08-11 04:33:15 +00:00
|
|
|
def meson(command, rootdir=None, builddir=None, prefix=None, backend=None,
|
|
|
|
release=False, shared=None, *, options=[]):
|
2018-02-20 08:33:19 +00:00
|
|
|
"""[R_API] Invoke meson"""
|
2020-08-11 04:33:15 +00:00
|
|
|
cmd = MESON + [command]
|
|
|
|
if rootdir:
|
|
|
|
cmd.append(rootdir)
|
|
|
|
if builddir:
|
|
|
|
cmd.append(builddir)
|
2017-12-13 14:07:01 +00:00
|
|
|
if prefix:
|
2020-08-11 04:33:15 +00:00
|
|
|
cmd.append('--prefix={}'.format(prefix))
|
2017-12-13 14:07:01 +00:00
|
|
|
if backend:
|
2020-08-11 04:33:15 +00:00
|
|
|
cmd.append('--backend={}'.format(backend))
|
2017-12-13 14:07:01 +00:00
|
|
|
if release:
|
2020-08-11 04:33:15 +00:00
|
|
|
cmd.append('--buildtype=release')
|
|
|
|
if shared != None:
|
|
|
|
cmd.append('--default-library={}'.format('shared' if shared else 'static'))
|
2018-02-06 12:41:42 +00:00
|
|
|
if options:
|
2020-08-11 04:33:15 +00:00
|
|
|
cmd.extend(options)
|
2017-12-13 14:07:01 +00:00
|
|
|
|
2020-08-11 04:33:15 +00:00
|
|
|
log.debug('Invoking meson: %s', cmd)
|
|
|
|
ret = subprocess.call(cmd)
|
2017-12-13 14:07:01 +00:00
|
|
|
if ret != 0:
|
|
|
|
log.error('Meson error. Exiting.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-01-28 17:16:38 +00:00
|
|
|
def ninja(folder, *targets):
|
2018-02-20 08:33:19 +00:00
|
|
|
"""[R_API] Invoke ninja"""
|
2018-02-06 12:41:42 +00:00
|
|
|
command = ['ninja', '-C', folder]
|
2018-01-28 17:16:38 +00:00
|
|
|
if targets:
|
|
|
|
command.extend(targets)
|
|
|
|
log.debug('Invoking ninja: %s', command)
|
2017-12-13 14:07:01 +00:00
|
|
|
ret = subprocess.call(command)
|
|
|
|
if ret != 0:
|
|
|
|
log.error('Ninja error. Exiting.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-01-28 17:16:38 +00:00
|
|
|
def msbuild(project, *params):
|
2018-02-20 08:33:19 +00:00
|
|
|
"""[R_API] Invoke MSbuild"""
|
2018-01-28 17:16:38 +00:00
|
|
|
command = ['msbuild', project]
|
|
|
|
if params:
|
|
|
|
command.extend(params)
|
|
|
|
log.info('Invoking MSbuild: %s', command)
|
|
|
|
ret = subprocess.call(command)
|
2018-01-11 16:20:23 +00:00
|
|
|
if ret != 0:
|
|
|
|
log.error('MSbuild error. Exiting.')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2018-03-04 23:10:28 +00:00
|
|
|
def copytree(src, dst, exclude=()):
|
2018-01-11 16:20:23 +00:00
|
|
|
src = src.format(**PATH_FMT)
|
2018-04-29 14:03:04 +00:00
|
|
|
dst = dst.format(**PATH_FMT).format(**PATH_FMT)
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('copytree "%s" -> "%s"', src, dst)
|
2018-03-04 23:10:28 +00:00
|
|
|
shutil.copytree(src, dst, ignore=shutil.ignore_patterns(*exclude) if exclude else None)
|
2018-01-11 16:20:23 +00:00
|
|
|
|
|
|
|
def move(src, dst):
|
|
|
|
src = src.format(**PATH_FMT)
|
2018-04-29 14:03:04 +00:00
|
|
|
dst = dst.format(**PATH_FMT).format(**PATH_FMT)
|
2018-01-11 16:20:23 +00:00
|
|
|
term = os.path.sep if os.path.isdir(dst) else ''
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('move "%s" -> "%s%s"', src, dst, term)
|
2018-01-11 16:20:23 +00:00
|
|
|
for file in glob.iglob(src):
|
|
|
|
shutil.move(file, dst)
|
|
|
|
|
|
|
|
def copy(src, dst):
|
|
|
|
src = src.format(**PATH_FMT)
|
2018-04-29 14:03:04 +00:00
|
|
|
dst = dst.format(**PATH_FMT).format(**PATH_FMT)
|
2018-01-11 16:20:23 +00:00
|
|
|
term = os.path.sep if os.path.isdir(dst) else ''
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('copy "%s" -> "%s%s"', src, dst, term)
|
|
|
|
for file in glob.iglob(src, recursive='**' in src):
|
2018-01-11 16:20:23 +00:00
|
|
|
shutil.copy2(file, dst)
|
|
|
|
|
|
|
|
def makedirs(path):
|
2018-04-29 14:03:04 +00:00
|
|
|
path = path.format(**PATH_FMT).format(**PATH_FMT)
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('makedirs "%s"', path)
|
2018-01-11 16:20:23 +00:00
|
|
|
os.makedirs(path)
|
|
|
|
|
2018-01-05 09:20:17 +00:00
|
|
|
def xp_compat(builddir):
|
2018-01-11 16:20:23 +00:00
|
|
|
log.info('Running XP compat script')
|
|
|
|
|
2018-01-05 09:20:17 +00:00
|
|
|
with open(os.path.join(builddir, 'REGEN.vcxproj'), 'r') as f:
|
|
|
|
version = re.search('<PlatformToolset>(.*)</PlatformToolset>', f.read()).group(1)
|
|
|
|
|
2018-01-11 16:20:23 +00:00
|
|
|
if version.endswith('_xp'):
|
2018-01-28 17:16:38 +00:00
|
|
|
log.info('Skipping %s', builddir)
|
2018-01-11 16:20:23 +00:00
|
|
|
return
|
|
|
|
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('Translating from %s to %s_xp', version, version)
|
2018-01-11 16:20:23 +00:00
|
|
|
newversion = version+'_xp'
|
2018-01-05 09:20:17 +00:00
|
|
|
|
2018-01-28 17:16:38 +00:00
|
|
|
for f in glob.iglob(os.path.join(builddir, '**', '*.vcxproj'), recursive=True):
|
|
|
|
with open(f, 'r') as proj:
|
|
|
|
c = proj.read()
|
|
|
|
c = c.replace(version, newversion)
|
|
|
|
with open(f, 'w') as proj:
|
|
|
|
proj.write(c)
|
|
|
|
log.debug("%s .. OK", f)
|
2018-01-05 09:20:17 +00:00
|
|
|
|
2018-03-04 23:10:28 +00:00
|
|
|
def build(args):
|
2017-12-13 14:07:01 +00:00
|
|
|
""" Build radare2 """
|
|
|
|
log.info('Building radare2')
|
2018-02-06 12:41:42 +00:00
|
|
|
r2_builddir = os.path.join(ROOT, args.dir)
|
2018-03-30 21:35:12 +00:00
|
|
|
options = ['-D%s' % x for x in args.options]
|
2019-09-14 21:02:52 +00:00
|
|
|
if args.webui:
|
|
|
|
options.append('-Duse_webui=true')
|
2019-09-22 08:49:54 +00:00
|
|
|
if args.local:
|
|
|
|
options.append('-Dlocal=true')
|
2022-08-21 08:30:58 +00:00
|
|
|
if args.fuzz:
|
|
|
|
options.append('-Denable_libfuzzer=true')
|
2018-02-06 12:41:42 +00:00
|
|
|
if not os.path.exists(r2_builddir):
|
2020-08-11 04:33:15 +00:00
|
|
|
meson('setup', builddir=r2_builddir, prefix=args.prefix, backend=args.backend,
|
2018-03-30 21:35:12 +00:00
|
|
|
release=args.release, shared=args.shared, options=options)
|
2017-12-13 14:07:01 +00:00
|
|
|
if args.backend != 'ninja':
|
2019-09-30 04:31:40 +00:00
|
|
|
# XP support was dropped in Visual Studio 2019 v142 platform
|
2019-12-17 14:31:47 +00:00
|
|
|
if args.backend == 'vs2017' and args.xp:
|
2018-02-06 12:41:42 +00:00
|
|
|
xp_compat(r2_builddir)
|
2017-12-13 14:07:01 +00:00
|
|
|
if not args.project:
|
2018-02-06 12:41:42 +00:00
|
|
|
project = os.path.join(r2_builddir, 'radare2.sln')
|
2020-04-08 18:32:46 +00:00
|
|
|
params = ['/m', '/clp:Summary;Verbosity=minimal']
|
2019-12-17 11:34:26 +00:00
|
|
|
if args.backend == 'vs2017' and args.xp:
|
|
|
|
params.append('/p:XPDeprecationWarning=false')
|
|
|
|
msbuild(project, *params)
|
2017-12-13 14:07:01 +00:00
|
|
|
else:
|
2018-02-06 12:41:42 +00:00
|
|
|
ninja(r2_builddir)
|
|
|
|
|
2017-12-13 14:07:01 +00:00
|
|
|
def install(args):
|
|
|
|
""" Install radare2 """
|
2020-08-11 04:33:15 +00:00
|
|
|
meson('install', options=['-C', '{}'.format(args.dir), '--no-rebuild'])
|
2017-12-13 14:07:01 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
# Create logger and get applications paths
|
2018-02-06 12:41:42 +00:00
|
|
|
set_global_variables()
|
2017-12-13 14:07:01 +00:00
|
|
|
|
|
|
|
# Create parser
|
|
|
|
parser = argparse.ArgumentParser(description='Mesonbuild scripts for radare2')
|
2019-11-04 23:33:35 +00:00
|
|
|
# --sanitize=address,signed-integer-overflow for faster build
|
|
|
|
parser.add_argument('--sanitize', nargs='?',
|
2019-11-04 06:38:20 +00:00
|
|
|
const='address,undefined,signed-integer-overflow', metavar='sanitizers',
|
2019-11-04 23:33:35 +00:00
|
|
|
help='Build radare2 with sanitizer support (default: %(const)s)')
|
2022-08-21 08:30:58 +00:00
|
|
|
parser.add_argument('--fuzz', action='store_true',
|
|
|
|
help='Build radare2 with libFuzzer support')
|
2017-12-13 14:07:01 +00:00
|
|
|
parser.add_argument('--project', action='store_true',
|
|
|
|
help='Create a visual studio project and do not build.')
|
|
|
|
parser.add_argument('--release', action='store_true',
|
|
|
|
help='Set the build as Release (remove debug info)')
|
2018-02-20 08:33:19 +00:00
|
|
|
parser.add_argument('--backend', choices=BACKENDS, default='ninja',
|
|
|
|
help='Choose build backend (default: %(default)s)')
|
2017-12-13 14:07:01 +00:00
|
|
|
parser.add_argument('--shared', action='store_true',
|
|
|
|
help='Link dynamically (shared library) rather than statically')
|
2019-09-22 08:49:54 +00:00
|
|
|
parser.add_argument('--local', action='store_true',
|
|
|
|
help='Adds support for local/side-by-side installation (sets rpath if needed)')
|
2018-02-20 08:33:19 +00:00
|
|
|
parser.add_argument('--prefix', default=None,
|
|
|
|
help='Set project installation prefix')
|
|
|
|
parser.add_argument('--dir', default=BUILDDIR, required=False,
|
|
|
|
help='Destination build directory (default: %(default)s)')
|
2018-08-01 12:51:41 +00:00
|
|
|
parser.add_argument('--alias', action='store_true',
|
|
|
|
help='Show the "m" alias shell command')
|
2017-12-13 14:07:01 +00:00
|
|
|
parser.add_argument('--xp', action='store_true',
|
|
|
|
help='Adds support for Windows XP')
|
2018-07-18 00:28:59 +00:00
|
|
|
parser.add_argument('--pull', action='store_true',
|
|
|
|
help='git pull before building')
|
2018-08-01 01:12:33 +00:00
|
|
|
parser.add_argument('--nosudo', action='store_true',
|
|
|
|
help='Do not use sudo for install/symstall/uninstall')
|
2018-07-18 00:30:59 +00:00
|
|
|
parser.add_argument('--uninstall', action='store_true',
|
|
|
|
help='Uninstall')
|
2018-07-18 00:06:19 +00:00
|
|
|
parser.add_argument('--symstall', action='store_true',
|
|
|
|
help='Install using symlinks')
|
2019-09-14 21:02:52 +00:00
|
|
|
parser.add_argument('--webui', action='store_true',
|
|
|
|
help='Install WebUIs')
|
2020-08-11 04:33:15 +00:00
|
|
|
parser.add_argument('--install', action='store_true',
|
2018-01-11 16:20:23 +00:00
|
|
|
help='Install radare2 after building')
|
2018-03-30 21:35:12 +00:00
|
|
|
parser.add_argument('--options', nargs='*', default=[])
|
2017-12-13 14:07:01 +00:00
|
|
|
args = parser.parse_args()
|
2018-08-01 12:51:41 +00:00
|
|
|
if args.alias:
|
|
|
|
print("alias m=\"" + os.path.abspath(__file__) + "\"")
|
|
|
|
sys.exit(0);
|
2019-11-04 23:33:35 +00:00
|
|
|
if args.sanitize:
|
2018-07-29 08:43:46 +00:00
|
|
|
if os.uname().sysname == 'OpenBSD':
|
2019-11-04 23:33:35 +00:00
|
|
|
log.error("Sanitizers unsupported under OpenBSD")
|
2018-07-29 08:43:46 +00:00
|
|
|
sys.exit(1)
|
2022-08-21 08:30:58 +00:00
|
|
|
sanitizers = args.sanitize
|
|
|
|
if args.fuzz and 'fuzzer' not in sanitizers:
|
|
|
|
sanitizers = "fuzzer," + sanitizers
|
2018-07-18 00:27:02 +00:00
|
|
|
cflags = os.environ.get('CFLAGS')
|
|
|
|
if not cflags:
|
|
|
|
cflags = ''
|
2022-08-21 08:30:58 +00:00
|
|
|
os.environ['CFLAGS'] = cflags + ' -fsanitize=' + sanitizers
|
2018-07-18 00:27:02 +00:00
|
|
|
if os.uname().sysname != 'Darwin':
|
|
|
|
ldflags = os.environ.get('LDFLAGS')
|
|
|
|
if not ldflags:
|
|
|
|
ldflags = ''
|
2022-08-21 08:30:58 +00:00
|
|
|
os.environ['LDFLAGS'] = ldflags + ' -fsanitize=' + sanitizers
|
2017-12-13 14:07:01 +00:00
|
|
|
|
|
|
|
# Check arguments
|
2018-07-18 00:28:59 +00:00
|
|
|
if args.pull:
|
2021-12-15 09:12:43 +00:00
|
|
|
# Attempt to update from an existing remote
|
|
|
|
upstream_remote = subprocess.check_output(["git", "remote", "-v"]).decode()
|
|
|
|
try:
|
|
|
|
remote = re.search(r'(.*?)\t.*radareorg/radare2 \(fetch\)', upstream_remote).group(1)
|
|
|
|
except AttributeError: # If search misses, None.group() throws this
|
|
|
|
remote = 'https://github.com/radareorg/radare2'
|
|
|
|
os.system(f'git pull {remote} master')
|
2017-12-13 14:07:01 +00:00
|
|
|
if args.project and args.backend == 'ninja':
|
|
|
|
log.error('--project is not compatible with --backend ninja')
|
|
|
|
sys.exit(1)
|
2019-09-30 04:31:40 +00:00
|
|
|
if args.xp and args.backend in 'ninja':
|
2017-12-13 14:07:01 +00:00
|
|
|
log.error('--xp is not compatible with --backend ninja')
|
|
|
|
sys.exit(1)
|
2019-09-30 04:31:40 +00:00
|
|
|
if args.xp and args.backend in 'vs2019':
|
|
|
|
log.error('--xp is not compatible with --backend vs2019')
|
|
|
|
sys.exit(1)
|
2020-08-11 04:33:15 +00:00
|
|
|
if not args.prefix:
|
2018-03-04 23:10:28 +00:00
|
|
|
args.prefix = os.path.join(ROOT, args.dir, 'priv_install_dir')
|
2020-08-11 04:33:15 +00:00
|
|
|
else:
|
|
|
|
args.prefix = os.path.abspath(args.prefix)
|
2018-04-29 14:03:04 +00:00
|
|
|
for option in args.options:
|
|
|
|
if '=' not in option:
|
|
|
|
log.error('Invalid option: %s', option)
|
2018-03-30 21:35:12 +00:00
|
|
|
sys.exit(1)
|
2018-04-29 14:03:04 +00:00
|
|
|
key, value = option.split('=', 1)
|
|
|
|
key = key.upper()
|
|
|
|
if key not in R2_PATH:
|
|
|
|
continue
|
|
|
|
if os.path.isabs(value):
|
|
|
|
log.error('Relative path is required: %s', option)
|
|
|
|
sys.exit(1)
|
|
|
|
R2_PATH[key] = os.path.normpath(value)
|
|
|
|
|
|
|
|
PATH_FMT.update(R2_PATH)
|
2017-12-13 14:07:01 +00:00
|
|
|
|
2018-08-01 01:12:33 +00:00
|
|
|
sudo = 'sudo '
|
|
|
|
if args.nosudo:
|
|
|
|
sudo = ''
|
2017-12-13 14:07:01 +00:00
|
|
|
# Build it!
|
2018-01-28 17:16:38 +00:00
|
|
|
log.debug('Arguments: %s', args)
|
2017-12-13 14:07:01 +00:00
|
|
|
build(args)
|
2018-07-18 00:30:59 +00:00
|
|
|
if args.uninstall:
|
2018-08-01 01:12:33 +00:00
|
|
|
os.system(sudo + 'make uninstall PWD="$PWD/build" BTOP="$PWD/build/binr"')
|
2017-12-13 14:07:01 +00:00
|
|
|
if args.install:
|
|
|
|
install(args)
|
2018-07-18 00:06:19 +00:00
|
|
|
if args.symstall:
|
2018-08-01 01:12:33 +00:00
|
|
|
os.system(sudo + 'make symstall PWD="$PWD/build" BTOP="$PWD/build/binr"')
|
2017-12-13 14:07:01 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|