Bug 1661739 - Don't use -out with midl. r=nalexander

The work in bug 1620133 ended up moving the execution of some of the
midl commands to the top-level, which was alleviated by adding the -out
midl command line option to make midl place its output in the expected
directory. Unfortunately, that option is not handled by widl, which is
the alternative command used in mingw builds.

So instead of using -out, we set the cwd for the midl command, and
readjust the command line arguments to be relative to that.

Differential Revision: https://phabricator.services.mozilla.com/D88937
This commit is contained in:
Mike Hommey 2020-09-01 20:25:49 +00:00
Родитель 2692897b74
Коммит 968f3b8fd6
1 изменённых файлов: 16 добавлений и 10 удалений

Просмотреть файл

@ -8,30 +8,36 @@ import os
import sys
# Windows program run via Wine don't like Unix absolute paths (they look
# like command line arguments). So when needed, create relative paths
# from absolute paths.
def relativize(path):
def relativize(path, base=None):
# For absolute path in Unix builds, we need relative paths because
# Windows programs run via Wine don't like these Unix absolute paths
# (they look like command line arguments).
if path.startswith('/'):
return os.path.relpath(path)
return path
return os.path.relpath(path, base)
# For Windows absolute paths, we can just use the unmodified path.
# And if the path starts with '-', it's a command line argument.
if os.path.isabs(path) or path.startswith('-'):
return path
# Remaining case is relative paths, which may be relative to a different
# directory (os.getcwd()) than the needed `base`, so we "rebase" it.
return os.path.relpath(path, base)
def midl(out, input, *flags):
out.avoid_writing_to_file()
midl = buildconfig.substs['MIDL']
wine = buildconfig.substs.get('WINE')
base = os.path.dirname(out.name) or '.'
if midl.lower().endswith('.exe') and wine:
command = [wine, midl]
else:
command = [midl]
command.extend(buildconfig.substs['MIDL_FLAGS'])
command.extend([relativize(f) for f in flags])
command.extend([relativize(f, base) for f in flags])
command.append('-Oicf')
command.extend(['-out', relativize(os.path.dirname(out.name) or '.')])
command.append(relativize(input))
command.append(relativize(input, base))
print('Executing:', ' '.join(command))
result = subprocess.run(command)
result = subprocess.run(command, cwd=base)
return result.returncode