From a54f9363e4eeb78e06074d88f3a4c4d4b9f606f4 Mon Sep 17 00:00:00 2001 From: yossizap Date: Tue, 11 Aug 2020 04:33:15 +0000 Subject: [PATCH] Use meson install instead of manual installation in meson.py (#17424) * Use meson install instead of manual installation in meson.py * Update AppVeyor and docs to use the new meson.py flag format * Meson.py should use --prefix for install paths and --install is a boolean for Windows and Unix now. * Removed windows specific restrictions from meson.py * Ensure that the prefix path is an absolute path * Fix install options syntax * Added an optional rootdir path for the meson setup command Co-authored-by: yossizap --- .appveyor.yml | 8 ++-- doc/windows.md | 2 +- sys/meson.py | 114 +++++++++---------------------------------------- 3 files changed, 26 insertions(+), 98 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index aaf6c86efa..4507078614 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -76,13 +76,13 @@ install: build_script: - appveyor AddMessage "Compiling radare2 %R2_VERSION% (%builder%)" - - cmd: if %builder% == vs2017_64 ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2017%" x64 && python sys\meson.py --backend vs2017 --release --xp --install="%DIST_FOLDER%" --webui --options static_runtime=true && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) + - cmd: if %builder% == vs2017_64 ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2017%" x64 && python sys\meson.py --backend vs2017 --release --xp --install --prefix="%DIST_FOLDER%" --webui --options static_runtime=true && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) - - cmd: if %builder% == vs2019_64 ( choco install mingw && refreshenv && set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2019%" x64 && python sys\meson.py --backend vs2019 --release --install="%DIST_FOLDER%" --webui --options static_runtime=true && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) + - cmd: if %builder% == vs2019_64 ( choco install mingw && refreshenv && set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2019%" x64 && python sys\meson.py --backend vs2019 --release --install --prefix="%DIST_FOLDER%" --webui --options static_runtime=true && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) - - cmd: if %builder% == vs2017_64_dyn ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2017%" x64 && python sys\meson.py --release --shared --install="%DIST_FOLDER%" --webui && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) + - cmd: if %builder% == vs2017_64_dyn ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2017%" x64 && python sys\meson.py --release --shared --install --prefix="%DIST_FOLDER%" --webui && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) - - cmd: if %builder% == clang_cl_64_dyn ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2019%" x64 && set CC=clang-cl && python sys\meson.py --release --shared --install="%DIST_FOLDER%" --webui && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) + - cmd: if %builder% == clang_cl_64_dyn ( set "PATH=C:\mingw\bin;C:\mingw\msys\1.0\bin;%PYTHON%;%PATH%" && call "%VSVARSALLPATH2019%" x64 && set CC=clang-cl && python sys\meson.py --release --shared --install --prefix="%DIST_FOLDER%" --webui && 7z a %ARTIFACT_ZIP% %DIST_FOLDER% ) # Run tests only conditionally for: diff --git a/doc/windows.md b/doc/windows.md index 718bec99e0..5da5a785f2 100644 --- a/doc/windows.md +++ b/doc/windows.md @@ -16,7 +16,7 @@ You will need: First, call `vcvarsall.bat` with your architecture (x86, x64, arm) to setup the compilation environment. cd radare2 - python3 sys\meson.py --release --backend vs2019 --shared --install="%cd%\radare2_dist" --webui + python3 sys\meson.py --release --backend vs2019 --shared --install --prefix="%cd%\radare2_dist" --webui You can change `--backend` to your VS version (`vs2015`, `vs2017`), `ninja` buildsystem is also supported. diff --git a/sys/meson.py b/sys/meson.py index 4e7030b986..5b4fd5d66f 100755 --- a/sys/meson.py +++ b/sys/meson.py @@ -64,25 +64,27 @@ def set_global_variables(): log.debug('Meson: %s', MESON) log.debug('Version: %s', version) -def meson(root, build, prefix=None, backend=None, - release=False, shared=False, *, options=[]): +def meson(command, rootdir=None, builddir=None, prefix=None, backend=None, + release=False, shared=None, *, options=[]): """[R_API] Invoke meson""" - command = MESON + [root, build] + cmd = MESON + [command] + if rootdir: + cmd.append(rootdir) + if builddir: + cmd.append(builddir) if prefix: - command.append('--prefix={}'.format(prefix)) + cmd.append('--prefix={}'.format(prefix)) if backend: - command.append('--backend={}'.format(backend)) + cmd.append('--backend={}'.format(backend)) if release: - command.append('--buildtype=release') - if shared: - command.append('--default-library=shared') - else: - command.append('--default-library=static') + cmd.append('--buildtype=release') + if shared != None: + cmd.append('--default-library={}'.format('shared' if shared else 'static')) if options: - command.extend(options) + cmd.extend(options) - log.debug('Invoking meson: %s', command) - ret = subprocess.call(command) + log.debug('Invoking meson: %s', cmd) + ret = subprocess.call(cmd) if ret != 0: log.error('Meson error. Exiting.') sys.exit(1) @@ -157,69 +159,6 @@ def xp_compat(builddir): proj.write(c) log.debug("%s .. OK", f) -def win_dist(args): - """Create r2 distribution for Windows""" - builddir = os.path.join(ROOT, args.dir) - PATH_FMT['DIST'] = args.install - PATH_FMT['BUILDDIR'] = builddir - - makedirs(r'{DIST}') - makedirs(r'{DIST}\bin') - copy(r'{BUILDDIR}\binr\*\*.exe', r'{DIST}\bin') - - r2_bat_fname = args.install + r'\bin\r2.bat' - log.debug('create "%s"', r2_bat_fname) - with open(r2_bat_fname, 'w') as r2_bat: - r2_bat.write('@"%~dp0\\radare2" %*\n') - - r2_sh_fname = args.install + r'\bin\r2' - log.debug('create "%s"', r2_sh_fname) - with open(r2_sh_fname, 'w') as r2_sh: - r2_sh.write('#!/bin/sh\n$(dirname "$0")/radare2 "$@"\n') - - copy(r'{BUILDDIR}\libr\*\*.dll', r'{DIST}\bin') - makedirs(r'{DIST}\{R2_LIBDIR}') - if args.shared: - copy(r'{BUILDDIR}\libr\*\*.lib', r'{DIST}\{R2_LIBDIR}') - else: - copy(r'{BUILDDIR}\libr\*\*.a', r'{DIST}\{R2_LIBDIR}') - win_dist_libr2(install_webui=args.webui) - -def win_dist_libr2(install_webui=False, **path_fmt): - """[R_API] Add libr2 data/www/include/doc to dist directory""" - PATH_FMT.update(path_fmt) - - if install_webui: - copytree(r'{ROOT}\shlr\www', r'{DIST}\{R2_WWWROOT}') - copytree(r'{ROOT}\libr\magic\d\default', r'{DIST}\{R2_SDB}\magic') - makedirs(r'{DIST}\{R2_SDB}\syscall') - copy(r'{BUILDDIR}\libr\syscall\d\*.sdb', r'{DIST}\{R2_SDB}\syscall') - makedirs(r'{DIST}\{R2_SDB}\fcnsign') - copy(r'{BUILDDIR}\libr\anal\d\*.sdb', r'{DIST}\{R2_SDB}\fcnsign') - makedirs(r'{DIST}\{R2_SDB}\opcodes') - copy(r'{BUILDDIR}\libr\asm\d\*.sdb', r'{DIST}\{R2_SDB}\opcodes') - makedirs(r'{DIST}\{R2_INCDIR}\sdb') - makedirs(r'{DIST}\{R2_INCDIR}\r_util') - makedirs(r'{DIST}\{R2_INCDIR}\r_crypto') - copy(r'{ROOT}\libr\include\*.h', r'{DIST}\{R2_INCDIR}') - copy(r'{BUILDDIR}\r_version.h', r'{DIST}\{R2_INCDIR}') - copy(r'{BUILDDIR}\r_userconf.h', r'{DIST}\{R2_INCDIR}') - copy(r'{ROOT}\libr\include\sdb\*.h', r'{DIST}\{R2_INCDIR}\sdb') - copy(r'{ROOT}\libr\include\r_util\*.h', r'{DIST}\{R2_INCDIR}\r_util') - copy(r'{ROOT}\libr\include\r_crypto\*.h', r'{DIST}\{R2_INCDIR}\r_crypto') - makedirs(r'{DIST}\{R2_FORTUNES}') - copy(r'{ROOT}\doc\fortunes.*', r'{DIST}\{R2_FORTUNES}') - copytree(r'{ROOT}\libr\bin\d', r'{DIST}\{R2_SDB}\format', - exclude=('Makefile', 'meson.build', 'dll')) - makedirs(r'{DIST}\{R2_SDB}\format\dll') - copy(r'{BUILDDIR}\libr\bin\d\*.sdb', r'{DIST}\{R2_SDB}\format\dll') - copytree(r'{ROOT}\libr\cons\d', r'{DIST}\{R2_THEMES}', - exclude=('Makefile', 'meson.build')) - makedirs(r'{DIST}\{R2_FLAGS}') - copy(r'{BUILDDIR}\libr\flag\d\*.r2', r'{DIST}\{R2_FLAGS}') - makedirs(r'{DIST}\{R2_HUD}') - copy(r'{ROOT}\doc\hud', r'{DIST}\{R2_HUD}\main') - def build(args): """ Build radare2 """ log.info('Building radare2') @@ -230,7 +169,7 @@ def build(args): if args.local: options.append('-Dlocal=true') if not os.path.exists(r2_builddir): - meson(ROOT, r2_builddir, prefix=args.prefix, backend=args.backend, + meson('setup', builddir=r2_builddir, prefix=args.prefix, backend=args.backend, release=args.release, shared=args.shared, options=options) if args.backend != 'ninja': # XP support was dropped in Visual Studio 2019 v142 platform @@ -247,14 +186,7 @@ def build(args): def install(args): """ Install radare2 """ - if os.name == 'nt': - win_dist(args) - return - log.warning('Install not implemented yet for this platform.') - # TODO - #if os.name == 'posix': - # os.system('DESTDIR="{destdir}" ninja -C {build} install' - # .format(destdir=destdir, build=args.dir)) + meson('install', options=['-C', '{}'.format(args.dir), '--no-rebuild']) def main(): # Create logger and get applications paths @@ -294,10 +226,7 @@ def main(): help='Install using symlinks') parser.add_argument('--webui', action='store_true', help='Install WebUIs') - if os.name == 'nt': - parser.add_argument('--install', help='Installation directory') - else: - parser.add_argument('--install', action='store_true', + parser.add_argument('--install', action='store_true', help='Install radare2 after building') parser.add_argument('--options', nargs='*', default=[]) args = parser.parse_args() @@ -330,11 +259,10 @@ def main(): if args.xp and args.backend in 'vs2019': log.error('--xp is not compatible with --backend vs2019') sys.exit(1) - if os.name == 'nt' and args.install and os.path.exists(args.install): - log.error('%s already exists', args.install) - sys.exit(1) - if os.name == 'nt' and not args.prefix: + if not args.prefix: args.prefix = os.path.join(ROOT, args.dir, 'priv_install_dir') + else: + args.prefix = os.path.abspath(args.prefix) for option in args.options: if '=' not in option: log.error('Invalid option: %s', option)