mirror of
https://github.com/holub/mame
synced 2025-07-01 16:19:38 +03:00
Updated scripts to support SOURCES= builds after the reorganisation happens.
This commit is contained in:
parent
c1f1ab2717
commit
d8854e4e55
@ -562,6 +562,7 @@ def parse_command_line():
|
|||||||
subparser.add_argument('sources', metavar='<srcfile>', nargs='+', help='source files to include')
|
subparser.add_argument('sources', metavar='<srcfile>', nargs='+', help='source files to include')
|
||||||
|
|
||||||
subparser = subparsers.add_parser('sourcesfilter', help='generate driver filter for source files')
|
subparser = subparsers.add_parser('sourcesfilter', help='generate driver filter for source files')
|
||||||
|
subparser.add_argument('-l', '--list', metavar='<lstfile>', required=True, help='master driver list file')
|
||||||
subparser.add_argument('sources', metavar='<srcfile>', nargs='+', help='source files to include')
|
subparser.add_argument('sources', metavar='<srcfile>', nargs='+', help='source files to include')
|
||||||
|
|
||||||
subparser = subparsers.add_parser('driverlist', help='generate driver list source')
|
subparser = subparsers.add_parser('driverlist', help='generate driver list source')
|
||||||
@ -662,9 +663,13 @@ def scan_source_dependencies(options):
|
|||||||
if ext.lower().startswith('.h'):
|
if ext.lower().startswith('.h'):
|
||||||
components = components[:-1]
|
components = components[:-1]
|
||||||
test_siblings(components, base, depth)
|
test_siblings(components, base, depth)
|
||||||
if components == ('src', 'mame', 'includes'):
|
if components[:2] == ('src', 'mame'):
|
||||||
for aspect in ('audio', 'drivers', 'video', 'machine'):
|
if components[2:] == ('includes', ):
|
||||||
test_siblings(('src', 'mame', aspect), base, depth)
|
for aspect in ('audio', 'drivers', 'video', 'machine'):
|
||||||
|
test_siblings(('src', 'mame', aspect), base, depth)
|
||||||
|
else:
|
||||||
|
for aspect in ('_a', '_v', '_m'):
|
||||||
|
test_siblings(components, base + aspect, depth)
|
||||||
|
|
||||||
handler = CppParser.Handler()
|
handler = CppParser.Handler()
|
||||||
handler.line = line_hook
|
handler.line = line_hook
|
||||||
@ -741,13 +746,60 @@ def write_project(options, projectfile, mappings, sources):
|
|||||||
|
|
||||||
|
|
||||||
def write_filter(options, filterfile):
|
def write_filter(options, filterfile):
|
||||||
|
def do_parse(p):
|
||||||
|
def line_hook(text):
|
||||||
|
text = text.strip()
|
||||||
|
if text.startswith('#'):
|
||||||
|
do_parse(os.path.join(os.path.dirname(n), text[1:].lstrip()))
|
||||||
|
elif text.startswith('@'):
|
||||||
|
parts = text[1:].lstrip().split(':', 1)
|
||||||
|
parts[0] = parts[0].strip()
|
||||||
|
if (parts[0] == 'source') and (len(parts) == 2):
|
||||||
|
parts[1] = parts[1].strip()
|
||||||
|
if not parts[1]:
|
||||||
|
sys.stderr.write('%s:%s: Empty source file name "%s"\n' % (p, parser.input_line, text))
|
||||||
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
sources.add(parts[1])
|
||||||
|
else:
|
||||||
|
sys.stderr.write('%s:%s: Unsupported directive "%s"\n' % (p, parser.input_line, text))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
n = os.path.normpath(p)
|
||||||
|
if n not in lists:
|
||||||
|
lists.add(n)
|
||||||
|
try:
|
||||||
|
listfile = io.open(n, 'r', encoding='utf-8')
|
||||||
|
except IOError:
|
||||||
|
sys.stderr.write('Unable to open list file "%s"\n' % (p, ))
|
||||||
|
sys.exit(1)
|
||||||
|
with listfile:
|
||||||
|
handler = CppParser.Handler()
|
||||||
|
handler.line = line_hook
|
||||||
|
parser = CppParser(handler)
|
||||||
|
try:
|
||||||
|
parser.parse(listfile)
|
||||||
|
except IOError:
|
||||||
|
sys.stderr.write('Error reading list file "%s"\n' % (p, ))
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
sys.stderr.write('Error parsing list file "%s": %s\n' % (p, e))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
lists = set()
|
||||||
|
sources = set()
|
||||||
|
do_parse(options.list)
|
||||||
|
|
||||||
drivers = set()
|
drivers = set()
|
||||||
for source in options.sources:
|
for source in options.sources:
|
||||||
components = tuple(x for x in split_path(source) if x)
|
components = tuple(x for x in split_path(source) if x)
|
||||||
if (len(components) > 3) and (components[:3] == ('src', 'mame', 'drivers')):
|
if (len(components) > 3) and (components[:2] == ('src', 'mame')):
|
||||||
ext = os.path.splitext(components[-1])[1].lower()
|
ext = os.path.splitext(components[-1])[1].lower()
|
||||||
if ext.startswith('.c'):
|
if ext.startswith('.c'):
|
||||||
drivers.add('/'.join(components[3:]))
|
if components[2] == 'drivers':
|
||||||
|
drivers.add('/'.join(components[3:]))
|
||||||
|
elif '/'.join(components[2:]) in sources:
|
||||||
|
drivers.add('/'.join(components[2:]))
|
||||||
for driver in sorted(drivers):
|
for driver in sorted(drivers):
|
||||||
filterfile.write(driver + '\n')
|
filterfile.write(driver + '\n')
|
||||||
|
|
||||||
|
@ -557,7 +557,7 @@ if (_OPTIONS["PROJECT"] ~= nil) then
|
|||||||
end
|
end
|
||||||
dofile (path.join(".." ,"projects", _OPTIONS["PROJECT"], "scripts", "target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))
|
dofile (path.join(".." ,"projects", _OPTIONS["PROJECT"], "scripts", "target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))
|
||||||
end
|
end
|
||||||
if (_OPTIONS["SOURCES"] == nil and _OPTIONS["PROJECT"] == nil) then
|
if (_OPTIONS["SOURCES"] == nil) and (_OPTIONS["PROJECT"] == nil) then
|
||||||
if (not os.isfile(path.join("target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))) then
|
if (not os.isfile(path.join("target", _OPTIONS["target"],_OPTIONS["subtarget"] .. ".lua"))) then
|
||||||
error("File definition for TARGET=" .. _OPTIONS["target"] .. " SUBTARGET=" .. _OPTIONS["subtarget"] .. " does not exist")
|
error("File definition for TARGET=" .. _OPTIONS["target"] .. " SUBTARGET=" .. _OPTIONS["subtarget"] .. " does not exist")
|
||||||
end
|
end
|
||||||
@ -1416,14 +1416,14 @@ if (_OPTIONS["SOURCES"] ~= nil) then
|
|||||||
local sourceargs = ""
|
local sourceargs = ""
|
||||||
for word in string.gmatch(str, '([^,]+)') do
|
for word in string.gmatch(str, '([^,]+)') do
|
||||||
if (not os.isfile(path.join(MAME_DIR, word))) then
|
if (not os.isfile(path.join(MAME_DIR, word))) then
|
||||||
print("File " .. word.. " does not exist")
|
print("File " .. word .. " does not exist")
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
sourceargs = sourceargs .. " " .. word
|
sourceargs = sourceargs .. " " .. word
|
||||||
end
|
end
|
||||||
OUT_STR = os.outputof( PYTHON .. " " .. MAME_DIR .. "scripts/build/makedep.py sourcesproject -r " .. MAME_DIR .. " -t " .. _OPTIONS["subtarget"] .. sourceargs )
|
OUT_STR = os.outputof( PYTHON .. " " .. MAME_DIR .. "scripts/build/makedep.py sourcesproject -r " .. MAME_DIR .. " -t " .. _OPTIONS["subtarget"] .. sourceargs )
|
||||||
load(OUT_STR)()
|
load(OUT_STR)()
|
||||||
os.outputof( PYTHON .. " " .. MAME_DIR .. "scripts/build/makedep.py sourcesfilter" .. sourceargs .. " > ".. GEN_DIR .. _OPTIONS["target"] .. "/" .. _OPTIONS["subtarget"] .. ".flt" )
|
os.outputof( PYTHON .. " " .. MAME_DIR .. "scripts/build/makedep.py sourcesfilter -l " .. MAME_DIR .. "src/" .. _OPTIONS["target"] .. "/" .. _OPTIONS["target"] .. ".lst" .. sourceargs .. " > ".. GEN_DIR .. _OPTIONS["target"] .. "/" .. _OPTIONS["subtarget"] .. ".flt" )
|
||||||
end
|
end
|
||||||
|
|
||||||
group "libs"
|
group "libs"
|
||||||
|
@ -285,45 +285,50 @@ if (STANDALONE~=true) then
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
elseif os.isfile(MAME_DIR .. "src/" .._target .. "/" .. _subtarget ..".lst") then
|
||||||
|
custombuildtask {
|
||||||
|
{
|
||||||
|
MAME_DIR .. "src/" .. _target .. "/" .. _subtarget .. ".lst",
|
||||||
|
GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.cpp",
|
||||||
|
{ MAME_DIR .. "scripts/build/makedep.py" },
|
||||||
|
{
|
||||||
|
"@echo Building driver list...",
|
||||||
|
PYTHON .. " $(1) driverlist $(<) > $(@)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
else
|
else
|
||||||
if os.isfile(MAME_DIR .. "src/" .._target .. "/" .. _subtarget ..".lst") then
|
dependency {
|
||||||
custombuildtask {
|
{ GEN_DIR .. _target .. "/" .. _target .."/drivlist.cpp", MAME_DIR .. "src/".._target .."/" .. _target ..".lst", true },
|
||||||
|
}
|
||||||
|
custombuildtask {
|
||||||
|
{
|
||||||
|
MAME_DIR .. "src/" .. _target .. "/" .. _target .. ".lst",
|
||||||
|
GEN_DIR .. _target .. "/" .. _target .. "/drivlist.cpp",
|
||||||
|
{ MAME_DIR .. "scripts/build/makedep.py" },
|
||||||
{
|
{
|
||||||
MAME_DIR .. "src/" .. _target .. "/" .. _subtarget .. ".lst",
|
"@echo Building driver list...",
|
||||||
GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.cpp",
|
PYTHON .. " $(1) driverlist $(<) > $(@)"
|
||||||
{ MAME_DIR .. "scripts/build/makedep.py" },
|
}
|
||||||
{
|
},
|
||||||
"@echo Building driver list...",
|
}
|
||||||
PYTHON .. " $(1) driverlist $(<) > $(@)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
else
|
|
||||||
dependency {
|
|
||||||
{ GEN_DIR .. _target .. "/" .. _target .."/drivlist.cpp", MAME_DIR .. "src/".._target .."/" .. _target ..".lst", true },
|
|
||||||
}
|
|
||||||
custombuildtask {
|
|
||||||
{
|
|
||||||
MAME_DIR .. "src/" .. _target .. "/" .. _target .. ".lst",
|
|
||||||
GEN_DIR .. _target .. "/" .. _target .. "/drivlist.cpp",
|
|
||||||
{ MAME_DIR .. "scripts/build/makedep.py" },
|
|
||||||
{
|
|
||||||
"@echo Building driver list...",
|
|
||||||
PYTHON .. " $(1) driverlist $(<) > $(@)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if (_OPTIONS["SOURCES"] ~= nil) then
|
if (_OPTIONS["SOURCES"] ~= nil) then
|
||||||
dependency {
|
dependency {
|
||||||
{
|
{ GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.cpp", MAME_DIR .. "src/".._target .."/" .. _target ..".lst", true },
|
||||||
GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.cpp", MAME_DIR .. "src/".._target .."/" .. _target ..".lst", true },
|
|
||||||
}
|
}
|
||||||
custombuildtask {
|
custombuildtask {
|
||||||
{ GEN_DIR .. _target .."/" .. _subtarget ..".flt" , GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.cpp", { MAME_DIR .. "scripts/build/makedep.py", MAME_DIR .. "src/".._target .."/" .. _target ..".lst" }, {"@echo Building driver list...", PYTHON .. " $(1) driverlist $(2) -f $(<) > $(@)" }},
|
{
|
||||||
|
GEN_DIR .. _target .."/" .. _subtarget ..".flt" ,
|
||||||
|
GEN_DIR .. _target .. "/" .. _subtarget .."/drivlist.cpp",
|
||||||
|
{ MAME_DIR .. "scripts/build/makedep.py", MAME_DIR .. "src/".._target .."/" .. _target ..".lst" },
|
||||||
|
{
|
||||||
|
"@echo Building driver list...",
|
||||||
|
PYTHON .. " $(1) driverlist $(2) -f $(<) > $(@)"
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,163 +1,201 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
|
|
||||||
import sys
|
import argparse
|
||||||
|
import glob
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
if len(sys.argv) != 2:
|
import re
|
||||||
print("Usage\n%s mame-cmake" % sys.argv[0])
|
import subprocess
|
||||||
sys.exit(0)
|
import sys
|
||||||
|
|
||||||
# Build the lists of files
|
|
||||||
|
|
||||||
src = sys.argv[1] + '/src/mame/'
|
|
||||||
|
|
||||||
for root, subdirs, files in os.walk(src + 'drivers'):
|
|
||||||
assert(len(subdirs) == 0)
|
|
||||||
srcd = files
|
|
||||||
|
|
||||||
for root, subdirs, files in os.walk(src + 'audio'):
|
|
||||||
assert(len(subdirs) == 0)
|
|
||||||
srca = files
|
|
||||||
|
|
||||||
for root, subdirs, files in os.walk(src + 'video'):
|
|
||||||
assert(len(subdirs) == 0)
|
|
||||||
srcv = files
|
|
||||||
|
|
||||||
for root, subdirs, files in os.walk(src + 'machine'):
|
|
||||||
assert(len(subdirs) == 0)
|
|
||||||
srcm = files
|
|
||||||
|
|
||||||
for root, subdirs, files in os.walk(src + 'includes'):
|
|
||||||
assert(len(subdirs) == 0)
|
|
||||||
srci = files
|
|
||||||
|
|
||||||
|
|
||||||
# Compute the future name of the files to avoid collisions
|
def parse_command():
|
||||||
present = {}
|
parser = argparse.ArgumentParser()
|
||||||
renaming = {}
|
parser.add_argument('srcroot', metavar='<srcroot>', help='MAME source root directory')
|
||||||
|
return parser.parse_args()
|
||||||
def add(l, c):
|
|
||||||
global present, renaming
|
|
||||||
for f in l:
|
|
||||||
if f in present:
|
|
||||||
nfx = f.split('.')
|
|
||||||
assert(len(nfx) == 2)
|
|
||||||
nf = nfx[0] + '_' + c + '.' + nfx[1]
|
|
||||||
# print("%s -> %s" % (f, nf))
|
|
||||||
assert(nf not in present)
|
|
||||||
else:
|
|
||||||
nf = f
|
|
||||||
present[nf] = True
|
|
||||||
renaming[c + '/' + f] = nf
|
|
||||||
|
|
||||||
add(srci, "i")
|
|
||||||
add(srcd, "d")
|
|
||||||
add(srca, "a")
|
|
||||||
add(srcv, "v")
|
|
||||||
add(srcm, "m")
|
|
||||||
|
|
||||||
|
|
||||||
# Update the .lua files, lookup the per-file target names
|
def resolve_conflicts(root, *parts):
|
||||||
|
def walk(subdir):
|
||||||
|
for path, subdirs, files in os.walk(os.path.join(root, subdir)):
|
||||||
|
if len(subdirs):
|
||||||
|
raise Exception('Found %d unwanted subdirectories in %s' % (len(subdirs), path))
|
||||||
|
return files
|
||||||
|
|
||||||
kl = {
|
present = set()
|
||||||
'includes': 'i',
|
result = {}
|
||||||
'drivers': 'd',
|
for part in parts:
|
||||||
'audio': 'a',
|
c = part[0]
|
||||||
'video': 'v',
|
for file in walk(part):
|
||||||
'machine' : 'm'
|
if file in present:
|
||||||
}
|
base, ext = os.path.splitext(file)
|
||||||
|
if not ext:
|
||||||
keys = ['createMAMEProjects', 'createMESSProjects']
|
raise Exception('File %s has no extension' % (file, ))
|
||||||
fpmap = {'v/konamiic.txt': 'konami' }
|
nf = base + '_' + c + ext
|
||||||
|
#print('%s -> %s' % (os.path.join(part, file), nf))
|
||||||
bad = False
|
if nf in present:
|
||||||
for scr in ['arcade.lua', 'mess.lua', 'ci.lua', 'dummy.lua', 'nl.lua', 'tiny.lua', 'virtual.lua']:
|
raise Exception('File %s still conflicted after renaming from %s' % (nf, file))
|
||||||
fname = sys.argv[1] + '/scripts/target/mame/' + scr
|
|
||||||
lines = open(fname, 'r').readlines()
|
|
||||||
cp = None
|
|
||||||
f = open(fname, 'w')
|
|
||||||
for l in lines:
|
|
||||||
ls = l.rstrip('\r\n')
|
|
||||||
for kk in keys:
|
|
||||||
p = ls.find(kk)
|
|
||||||
if p == 0 or p == 1:
|
|
||||||
p = ls.find('"')+1
|
|
||||||
p2 = ls.find('"', p)
|
|
||||||
cp = ls[p:p2]
|
|
||||||
if cp == 'mameshared':
|
|
||||||
cp = None
|
|
||||||
p = ls.find('MAME_DIR .. "src/mame/')
|
|
||||||
if p != -1:
|
|
||||||
p2 = ls.find('"', p+22)
|
|
||||||
fn = ls[p+22:p2]
|
|
||||||
fx = fn.split('/')
|
|
||||||
k = kl[fx[0]] + '/' + fx[1]
|
|
||||||
if cp != None:
|
|
||||||
if k in fpmap:
|
|
||||||
print("Duplicated: %s (%s and %s)" % (fn, cp, fpmap[k]))
|
|
||||||
bad = True
|
|
||||||
fpmap[k] = cp
|
|
||||||
ap = cp
|
|
||||||
else:
|
else:
|
||||||
if k not in fpmap:
|
nf = file
|
||||||
bad = True
|
present.add(nf)
|
||||||
# print("Missing in projects and seen in another .lua: %s" % fn)
|
result[part + '/' + file] = nf
|
||||||
ap = '?'
|
|
||||||
else:
|
|
||||||
ap = fpmap[k]
|
|
||||||
ls = ls[:p+22] + ap + '/' + renaming[k] + ls[p2:]
|
|
||||||
print(ls, file=f)
|
|
||||||
|
|
||||||
for k in renaming.keys():
|
return result
|
||||||
if k not in fpmap:
|
|
||||||
print("Missing in projects: %s" % k)
|
|
||||||
bad = True
|
|
||||||
|
|
||||||
if bad:
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Create the new subdirectories
|
def update_projects(root, renaming, *scripts):
|
||||||
for d in set(fpmap.values()):
|
keys = ('createMAMEProjects', 'createMESSProjects')
|
||||||
os.mkdir(src + d)
|
result = { 'video/konamiic.txt': 'konami' }
|
||||||
|
|
||||||
# Move the files around, patching the include paths as needed
|
bad = False
|
||||||
|
|
||||||
ikl = {}
|
for script in scripts:
|
||||||
for p, a in kl.items():
|
fname = os.path.join(root, 'scripts', 'target', 'mame', script)
|
||||||
ikl[a] = p
|
with open(fname, 'r', encoding='utf-8') as infile:
|
||||||
|
lines = infile.readlines()
|
||||||
for bfs, bfd in renaming.items():
|
cp = None
|
||||||
bfsx = bfs.split('/')
|
with open(fname, 'w', encoding='utf-8') as f:
|
||||||
fs = src + ikl[bfsx[0]] + '/' + bfsx[1]
|
for l in lines:
|
||||||
fdm = fpmap[bfs]
|
ls = l.rstrip('\r\n')
|
||||||
fd = src + fdm + '/' + bfd
|
for kk in keys:
|
||||||
fdh = open(fd, 'w')
|
p = ls.find(kk)
|
||||||
for l in open(fs):
|
if p == 0 or p == 1:
|
||||||
p0 = 0
|
p = ls.find('"')+1
|
||||||
while l[p0] == ' ' or l[p0] == '\t':
|
p2 = ls.find('"', p)
|
||||||
p0 += 1
|
cp = ls[p:p2]
|
||||||
if l[p0:p0+8] == '#include':
|
if cp == 'mameshared':
|
||||||
itype = '"'
|
cp = None
|
||||||
si = l.find('"')
|
p = ls.find('MAME_DIR .. "src/mame/')
|
||||||
if si != -1:
|
if p != -1:
|
||||||
si += 1
|
p2 = ls.find('"', p + 22)
|
||||||
ei = l.find('"', si)
|
fn = ls[p+22:p2]
|
||||||
fi = l[si:ei]
|
if cp is not None:
|
||||||
fix = fi.split('/')
|
if fn in result:
|
||||||
fik = None
|
print("Duplicated: %s (%s and %s)" % (fn, cp, result[fn]))
|
||||||
if len(fix) == 2 and fix[0] in kl:
|
bad = True
|
||||||
fik = kl[fix[0]] + '/' + fix[1]
|
result[fn] = cp
|
||||||
elif len(fix) == 1:
|
ap = cp
|
||||||
fik = bfsx[0] + '/' + fi
|
|
||||||
if fik != None and fik in fpmap:
|
|
||||||
fim = fpmap[fik]
|
|
||||||
if fim == fdm:
|
|
||||||
nfi = renaming[fik]
|
|
||||||
else:
|
else:
|
||||||
nfi = fim + '/' + renaming[fik]
|
if fn not in result:
|
||||||
l = l[:si] + nfi + l[ei:]
|
bad = True
|
||||||
fdh.write(l)
|
#print("Missing in projects and seen in another .lua: %s" % fn)
|
||||||
os.remove(fs)
|
ap = '?'
|
||||||
|
else:
|
||||||
|
ap = result[fn]
|
||||||
|
ls = ls[:p+22] + ap + '/' + renaming[fn] + ls[p2:]
|
||||||
|
print(ls, file=f)
|
||||||
|
|
||||||
for d in list(kl.keys()):
|
for k in renaming:
|
||||||
os.rmdir(src + d)
|
if k not in result:
|
||||||
|
print('Missing in projects: %s' % (k, ))
|
||||||
|
bad = True
|
||||||
|
|
||||||
|
if bad:
|
||||||
|
raise Exception('Error updating project scripts')
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def update_driver_list(fname, renaming, projectmap):
|
||||||
|
with open(fname, 'r', encoding='utf-8') as infile:
|
||||||
|
lines = infile.readlines()
|
||||||
|
with open(fname, 'w', encoding='utf-8') as outfile:
|
||||||
|
for l in lines:
|
||||||
|
ls = l.rstrip('\r\n')
|
||||||
|
match = re.match('(.*@source:)([-_0-9a-z]+\\.cpp)\\b(\s*)(.*)', ls)
|
||||||
|
if match:
|
||||||
|
f = 'drivers/' + match.group(2)
|
||||||
|
r = projectmap[f] + '/' + renaming.get(f, match.group(2))
|
||||||
|
if match.group(3):
|
||||||
|
w = len(match.group(2)) + len(match.group(3))
|
||||||
|
if len(r) < w:
|
||||||
|
r = r + (' ' * (w - len(r)))
|
||||||
|
else:
|
||||||
|
r = r + ' '
|
||||||
|
print(match.group(1) + r + match.group(4), file=outfile)
|
||||||
|
else:
|
||||||
|
print(ls, file=outfile)
|
||||||
|
|
||||||
|
|
||||||
|
def update_driver_filter(fname, renaming, projectmap):
|
||||||
|
with open(fname, 'r', encoding='utf-8') as infile:
|
||||||
|
lines = infile.readlines()
|
||||||
|
with open(fname, 'w', encoding='utf-8') as outfile:
|
||||||
|
for l in lines:
|
||||||
|
ls = l.rstrip('\r\n')
|
||||||
|
match = re.match('(.*)(?<![-_0-9a-z])([-_0-9a-z]+\\.cpp)\\b(.*)', ls)
|
||||||
|
if match:
|
||||||
|
f = 'drivers/' + match.group(2)
|
||||||
|
b = renaming.get(f, match.group(2))
|
||||||
|
print(match.group(1) + projectmap[f] + '/' + b + match.group(3), file=outfile)
|
||||||
|
else:
|
||||||
|
print(ls, file=outfile)
|
||||||
|
|
||||||
|
|
||||||
|
def relocate_source(root, filename, destbase, renaming, projectmap):
|
||||||
|
fsx = filename.split('/')
|
||||||
|
destproject = projectmap[filename]
|
||||||
|
sourcepath = os.path.join(root, 'src', 'mame', fsx[0], fsx[1])
|
||||||
|
destpath = os.path.join(root, 'src', 'mame', destproject, destbase)
|
||||||
|
with open(sourcepath, 'r', encoding='utf-8') as infile:
|
||||||
|
lines = infile.readlines()
|
||||||
|
subprocess.run(['git', '-C', root, 'mv', os.path.join('src', 'mame', fsx[0], fsx[1]), os.path.join('src', 'mame', destproject, destbase)])
|
||||||
|
|
||||||
|
# Patch the include paths as needed
|
||||||
|
with open(destpath, 'w', encoding='utf-8') as fdh:
|
||||||
|
for l in lines:
|
||||||
|
p0 = 0
|
||||||
|
while l[p0] == ' ' or l[p0] == '\t':
|
||||||
|
p0 += 1
|
||||||
|
if l[p0:p0+8] == '#include':
|
||||||
|
itype = '"'
|
||||||
|
si = l.find('"')
|
||||||
|
if si != -1:
|
||||||
|
si += 1
|
||||||
|
ei = l.find('"', si)
|
||||||
|
fi = l[si:ei]
|
||||||
|
fix = fi.split('/')
|
||||||
|
fik = None
|
||||||
|
if len(fix) == 2:
|
||||||
|
fik = fi
|
||||||
|
elif len(fix) == 1:
|
||||||
|
fik = fsx[0] + '/' + fi
|
||||||
|
if (fik is not None) and (fik in projectmap):
|
||||||
|
fim = fpmap[fik]
|
||||||
|
if fim == destproject:
|
||||||
|
nfi = renaming[fik]
|
||||||
|
else:
|
||||||
|
nfi = fim + '/' + renaming[fik]
|
||||||
|
l = l[:si] + nfi + l[ei:]
|
||||||
|
fdh.write(l)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
options = parse_command()
|
||||||
|
src = os.path.join(options.srcroot, 'src', 'mame')
|
||||||
|
areas = ('includes', 'drivers', 'audio', 'video', 'machine')
|
||||||
|
|
||||||
|
# Compute the future name of the files to avoid collisions
|
||||||
|
renaming = resolve_conflicts(src, *areas)
|
||||||
|
|
||||||
|
# Update the .lua files, lookup the per-file target names
|
||||||
|
fpmap = update_projects(options.srcroot, renaming, 'arcade.lua', 'mess.lua', 'ci.lua', 'dummy.lua', 'nl.lua', 'tiny.lua', 'virtual.lua')
|
||||||
|
|
||||||
|
# update .lst list files
|
||||||
|
for flt in glob.glob(os.path.join(src, '*.lst')):
|
||||||
|
update_driver_list(flt, renaming, fpmap)
|
||||||
|
|
||||||
|
# update .flt filter files
|
||||||
|
for flt in glob.glob(os.path.join(src, '*.flt')):
|
||||||
|
update_driver_filter(flt, renaming, fpmap)
|
||||||
|
|
||||||
|
# Create the new subdirectories
|
||||||
|
for d in fpmap.values():
|
||||||
|
os.makedirs(os.path.join(src, d), exist_ok=True)
|
||||||
|
|
||||||
|
# Move the files around
|
||||||
|
for fs, bfd in renaming.items():
|
||||||
|
relocate_source(options.srcroot, fs, bfd, renaming, fpmap)
|
||||||
|
|
||||||
|
for d in areas:
|
||||||
|
os.rmdir(os.path.join(src, d))
|
||||||
|
Loading…
Reference in New Issue
Block a user