mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-28 23:50:40 +00:00
Merge meson scripts (#9132)
This commit is contained in:
parent
e16e02be97
commit
7bfea1be93
75
sys/meson.py
75
sys/meson.py
@ -4,11 +4,16 @@ import argparse
|
|||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
ROOT = None
|
ROOT = None
|
||||||
BUILDDIR = 'build'
|
BUILDDIR = 'build'
|
||||||
|
SDB_BUILDDIR = 'build_sdb'
|
||||||
|
SDB = os.path.join(SDB_BUILDDIR, 'sdb')
|
||||||
|
BLACKLIST = ['Makefile', 'makefile']
|
||||||
|
EXTENSIONS = ['sdb.txt']
|
||||||
MESON = None
|
MESON = None
|
||||||
PYTHON = None
|
PYTHON = None
|
||||||
BACKENDS = ['ninja', 'vs2015', 'vs2017']
|
BACKENDS = ['ninja', 'vs2015', 'vs2017']
|
||||||
@ -72,12 +77,72 @@ def ninja(folder):
|
|||||||
log.error('Ninja error. Exiting.')
|
log.error('Ninja error. Exiting.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def convert_sdb(folder, f):
|
||||||
|
""" Convert f to sdb format """
|
||||||
|
base, _ = get_base_extension(f)
|
||||||
|
inf = os.path.join(folder, f)
|
||||||
|
sdb = os.path.join(folder, base) + '.sdb'
|
||||||
|
log.debug('Converting {} to {}'.format(inf, sdb))
|
||||||
|
os.system('{sdb} {outf} = <{inf}'.format(sdb=SDB, outf=sdb, inf=inf))
|
||||||
|
|
||||||
|
def get_base_extension(f):
|
||||||
|
""" file.sdb.txt => file, .txt """
|
||||||
|
n = f.split('.')
|
||||||
|
if len(n) == 1: return n[0], ''
|
||||||
|
return n[0], '.'.join(n[1:])
|
||||||
|
|
||||||
|
def handle_folder(folder):
|
||||||
|
""" Convert each suitable file inside specified folder to sdb file """
|
||||||
|
log.debug('Handling {} directory...'.format(folder))
|
||||||
|
for f in os.listdir(folder):
|
||||||
|
if f in BLACKLIST:
|
||||||
|
continue
|
||||||
|
base, ext = get_base_extension(f)
|
||||||
|
absf = os.path.join(folder, f)
|
||||||
|
if os.path.isdir(absf) and not os.path.islink(absf):
|
||||||
|
handle_folder(absf)
|
||||||
|
continue
|
||||||
|
if ext not in EXTENSIONS:
|
||||||
|
continue
|
||||||
|
convert_sdb(folder, f)
|
||||||
|
|
||||||
|
def xp_compat(builddir):
|
||||||
|
with open(os.path.join(builddir, 'REGEN.vcxproj'), 'r') as f:
|
||||||
|
version = re.search('<PlatformToolset>(.*)</PlatformToolset>', f.read()).group(1)
|
||||||
|
|
||||||
|
log.debug('Translating from %s to %s_xp' % (version, version))
|
||||||
|
newversion=version+'_xp'
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(builddir):
|
||||||
|
for f in files:
|
||||||
|
if f.endswith('.vcxproj'):
|
||||||
|
with open(os.path.join(root, f), 'r') as proj:
|
||||||
|
c = proj.read()
|
||||||
|
c = c.replace(version, newversion)
|
||||||
|
with open(os.path.join(root, f), 'w') as proj:
|
||||||
|
proj.write(c)
|
||||||
|
log.debug("%s .. OK" % f)
|
||||||
|
|
||||||
def build_sdb(args):
|
def build_sdb(args):
|
||||||
""" Build and generate sdb files """
|
""" Build and generate sdb files """
|
||||||
log.info('Building SDB')
|
log.info('Building SDB')
|
||||||
log.debug('TODO Merge scripts')
|
cmd = 'ECHO %CD%' if os.name == 'nt' else 'pwd'
|
||||||
return os.system('{python} {path}'.format(python=PYTHON,
|
cd = os.popen(cmd).read().rstrip()
|
||||||
path=os.path.join(ROOT, 'sys', 'meson_sdb.py')))
|
meson(os.path.join(ROOT, 'shlr', 'sdb'), SDB_BUILDDIR, prefix=cd)
|
||||||
|
ninja(SDB_BUILDDIR)
|
||||||
|
|
||||||
|
# Create .sdb files
|
||||||
|
log.info('Generating sdb files.')
|
||||||
|
with open('Makefile', 'r') as f:
|
||||||
|
line = ''
|
||||||
|
while 'DATADIRS' not in line:
|
||||||
|
line = f.readline()
|
||||||
|
datadirs = line.split('=')[1].split()
|
||||||
|
datadirs = [os.path.abspath(p) for p in datadirs]
|
||||||
|
log.debug('Looking up {}'.format(', '.join(datadirs)))
|
||||||
|
for folder in datadirs:
|
||||||
|
handle_folder(folder)
|
||||||
|
log.debug('Done')
|
||||||
|
|
||||||
def build_r2(args):
|
def build_r2(args):
|
||||||
""" Build radare2 """
|
""" Build radare2 """
|
||||||
@ -88,9 +153,7 @@ def build_r2(args):
|
|||||||
args.shared)
|
args.shared)
|
||||||
if args.xp:
|
if args.xp:
|
||||||
log.info('Running XP compat script')
|
log.info('Running XP compat script')
|
||||||
log.debug('TODO Merge this script')
|
xp_compat(BUILDDIR)
|
||||||
meson_extra = os.path.join(ROOT, 'sys', 'meson_extra.py')
|
|
||||||
os.system('python {meson_extra}'.format(meson_extra=meson_extra))
|
|
||||||
if not args.project:
|
if not args.project:
|
||||||
log.info('Starting msbuild')
|
log.info('Starting msbuild')
|
||||||
project = os.path.join(ROOT, args.dir, 'radare2.sln')
|
project = os.path.join(ROOT, args.dir, 'radare2.sln')
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
# meson sucks a bit for now and they are slow on taking pull requests so
|
|
||||||
# this is a hack to do what I want
|
|
||||||
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
|
|
||||||
builddir = os.getenv('BUILDDIR', None)
|
|
||||||
builddir = 'build' if builddir == None else builddir
|
|
||||||
|
|
||||||
with open(os.path.join(builddir, 'REGEN.vcxproj'), 'r') as f:
|
|
||||||
version = re.search('<PlatformToolset>(.*)</PlatformToolset>', f.read()).group(1)
|
|
||||||
|
|
||||||
print('Translating from %s to %s_xp' % (version, version))
|
|
||||||
newversion=version+'_xp'
|
|
||||||
|
|
||||||
for root, dirs, files in os.walk(builddir):
|
|
||||||
for f in files:
|
|
||||||
if f.endswith('.vcxproj'):
|
|
||||||
with open(os.path.join(root, f), 'r') as proj:
|
|
||||||
c = proj.read()
|
|
||||||
c = c.replace(version, newversion)
|
|
||||||
with open(os.path.join(root, f), 'w') as proj:
|
|
||||||
proj.write(c)
|
|
||||||
print("%s .. OK" % f)
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
|||||||
# This scripts aims to compile sdb and generate .sdb files for the meson build
|
|
||||||
# Assumes you are in radare2 root directory
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
BUILDDIR = 'build_sdb'
|
|
||||||
SDBDIR = os.path.join('shlr', 'sdb')
|
|
||||||
SDB = os.path.join(BUILDDIR, 'sdb')
|
|
||||||
with open('Makefile', 'r') as f:
|
|
||||||
line = ''
|
|
||||||
while 'DATADIRS' not in line:
|
|
||||||
line = f.readline()
|
|
||||||
DATADIRS = line.split('=')[1].split()
|
|
||||||
DATADIRS = [os.path.abspath(p) for p in DATADIRS]
|
|
||||||
BLACKLIST = ['Makefile', 'makefile']
|
|
||||||
EXTENSIONS = ['sdb.txt']
|
|
||||||
|
|
||||||
MESON = 'python meson.py' if os.path.isfile('meson.py') else 'meson'
|
|
||||||
NINJA = 'ninja'
|
|
||||||
|
|
||||||
def convert_sdb(folder, f):
|
|
||||||
""" Convert f to sdb format """
|
|
||||||
base, _ = get_base_extension(f)
|
|
||||||
inf = os.path.join(folder, f)
|
|
||||||
sdb = os.path.join(folder, base) + '.sdb'
|
|
||||||
print('Converting {} to {}'.format(inf, sdb))
|
|
||||||
os.system('{sdb} {outf} = <{inf}'.format(sdb=SDB, outf=sdb, inf=inf))
|
|
||||||
|
|
||||||
def get_base_extension(f):
|
|
||||||
""" file.sdb.txt => file, .txt """
|
|
||||||
n = f.split('.')
|
|
||||||
if len(n) == 1: return n[0], ''
|
|
||||||
return n[0], '.'.join(n[1:])
|
|
||||||
|
|
||||||
def handle_folder(folder):
|
|
||||||
""" Convert each suitable file inside specified folder to sdb file """
|
|
||||||
print('Handling {} directory...'.format(folder))
|
|
||||||
for f in os.listdir(folder):
|
|
||||||
if f in BLACKLIST:
|
|
||||||
continue
|
|
||||||
base, ext = get_base_extension(f)
|
|
||||||
absf = os.path.join(folder, f)
|
|
||||||
if os.path.isdir(absf) and not os.path.islink(absf):
|
|
||||||
handle_folder(absf)
|
|
||||||
continue
|
|
||||||
if ext not in EXTENSIONS:
|
|
||||||
continue
|
|
||||||
convert_sdb(folder, f)
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Create sdb binary
|
|
||||||
cd = '$(pwd)'
|
|
||||||
if os.name == 'nt':
|
|
||||||
cd = '%CD%'
|
|
||||||
r = os.system('{meson} --prefix={CD} {sdbdir} {builddir}'.format(meson=MESON, CD=cd, sdbdir=SDBDIR, builddir=BUILDDIR))
|
|
||||||
if r: exit(r)
|
|
||||||
r = os.system('{ninja} -C {builddir}'.format(ninja=NINJA, builddir=BUILDDIR))
|
|
||||||
if r: exit(r)
|
|
||||||
|
|
||||||
# Create .sdb files
|
|
||||||
print('Generating sdb files.')
|
|
||||||
print('Looking up {}'.format(', '.join(DATADIRS)))
|
|
||||||
for folder in DATADIRS:
|
|
||||||
handle_folder(folder)
|
|
||||||
print('Done')
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
main()
|
|
Loading…
Reference in New Issue
Block a user