Commit 32adb721 authored by S. Ganesh's avatar S. Ganesh Committed by Commit Bot

Fix midl.py fails when building a brand new IDL file

This change handles the cases of brand new IDL files added to a build,
or cases where files under third_party\win_build_output\midl are
(unexpectedly) missing. This change also has some minor refactoring of
the |writes_tlb| midl.gni option.

Bug: 1149764
Change-Id: If2e608f2e986bd3fbc13a3a7b699801660c2ffa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2543367
Commit-Queue: S. Ganesh <ganesh@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828319}
parent 4c48b054
...@@ -87,7 +87,11 @@ template("midl") { ...@@ -87,7 +87,11 @@ template("midl") {
dlldata_file = "{{source_name_part}}.dlldata.c" dlldata_file = "{{source_name_part}}.dlldata.c"
interface_identifier_file = "{{source_name_part}}_i.c" interface_identifier_file = "{{source_name_part}}_i.c"
proxy_file = "{{source_name_part}}_p.c" proxy_file = "{{source_name_part}}_p.c"
type_library_file = "{{source_name_part}}.tlb" if (writes_tlb) {
type_library_file = "{{source_name_part}}.tlb"
} else {
type_library_file = "none"
}
# TODO(crbug.com/1112471): Get this to run cleanly under Python 3. # TODO(crbug.com/1112471): Get this to run cleanly under Python 3.
python2_action_foreach(action_name) { python2_action_foreach(action_name) {
......
...@@ -234,7 +234,8 @@ def overwrite_guids(h_file, iid_file, proxy_file, tlb_file, dynamic_guids): ...@@ -234,7 +234,8 @@ def overwrite_guids(h_file, iid_file, proxy_file, tlb_file, dynamic_guids):
overwrite_guids_h(h_file, dynamic_guids) overwrite_guids_h(h_file, dynamic_guids)
overwrite_guids_iid(iid_file, dynamic_guids) overwrite_guids_iid(iid_file, dynamic_guids)
overwrite_guids_proxy(proxy_file, dynamic_guids) overwrite_guids_proxy(proxy_file, dynamic_guids)
overwrite_guids_tlb(tlb_file, dynamic_guids) if tlb_file:
overwrite_guids_tlb(tlb_file, dynamic_guids)
# This function removes all occurrences of 'PLACEHOLDER-GUID-' from the # This function removes all occurrences of 'PLACEHOLDER-GUID-' from the
...@@ -324,12 +325,40 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy, ...@@ -324,12 +325,40 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy,
source = os.path.join(source, arch.split('.')[1]) # Append 'x86' or 'x64'. source = os.path.join(source, arch.split('.')[1]) # Append 'x86' or 'x64'.
source = os.path.normpath(source) source = os.path.normpath(source)
source_exists = True
if not os.path.isdir(source):
source_exists = False
if sys.platform != 'win32':
print('Directory %s needs to be populated from Windows first' % source)
return 1
# This is a brand new IDL file that does not have outputs under
# third_party\win_build_output\midl. We create an empty directory for now.
os.makedirs(source)
common_files = [h, dlldata, iid, proxy] common_files = [h, dlldata, iid, proxy]
if os.path.isfile(os.path.join(source, tlb)): if tlb != 'none':
# Not all projects use tlb files. # Not all projects use tlb files.
common_files += [tlb] common_files += [tlb]
else:
tlb = None
for source_file in common_files: for source_file in common_files:
shutil.copy(os.path.join(source, source_file), outdir) file_path = os.path.join(source, source_file)
if not os.path.isfile(file_path):
source_exists = False
if sys.platform != 'win32':
print('File %s needs to be generated from Windows first' % file_path)
return 1
# Either this is a brand new IDL file that does not have outputs under
# third_party\win_build_output\midl or the file is (unexpectedly) missing.
# We create an empty file for now. The rest of the machinery below will
# then generate the correctly populated file using the MIDL compiler and
# instruct the developer to copy that file under
# third_party\win_build_output\midl.
open(file_path, 'wb').close()
shutil.copy(file_path, outdir)
if dynamic_guids != 'none': if dynamic_guids != 'none':
assert '=' in dynamic_guids assert '=' in dynamic_guids
...@@ -348,9 +377,10 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy, ...@@ -348,9 +377,10 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy,
dynamic_guids = dynamic_guids.split(',') dynamic_guids = dynamic_guids.split(',')
dynamic_guids = dict(s.split('=') for s in dynamic_guids) dynamic_guids = dict(s.split('=') for s in dynamic_guids)
uuid5_substitutions(dynamic_guids) uuid5_substitutions(dynamic_guids)
overwrite_guids(os.path.join(outdir, h), os.path.join(outdir, iid), if source_exists:
os.path.join(outdir, proxy), os.path.join(outdir, tlb), overwrite_guids(*(os.path.join(outdir, file) if file else None
dynamic_guids) for file in [h, iid, proxy, tlb]),
dynamic_guids=dynamic_guids)
else: else:
dynamic_guids = None dynamic_guids = None
...@@ -387,9 +417,9 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy, ...@@ -387,9 +417,9 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy,
preprocessor_options = '-E -nologo -Wno-nonportable-include-path' preprocessor_options = '-E -nologo -Wno-nonportable-include-path'
preprocessor_options += ''.join( preprocessor_options += ''.join(
[' ' + flag for flag in flags if flag.startswith('/D')]) [' ' + flag for flag in flags if flag.startswith('/D')])
args = ['midl', '/nologo'] + list(flags) + [ args = ['midl', '/nologo'] + list(flags) + (['/tlb', tlb] if tlb else []) + [
'/tlb', tlb, '/h', h, '/dlldata', dlldata, '/iid', iid, '/proxy', proxy, '/h', h, '/dlldata', dlldata, '/iid', iid, '/proxy', proxy, '/cpp_cmd',
'/cpp_cmd', clang, '/cpp_opt', preprocessor_options, idl clang, '/cpp_opt', preprocessor_options, idl
] ]
returncode, midl_output_dir = run_midl(args, env_dict) returncode, midl_output_dir = run_midl(args, env_dict)
...@@ -399,6 +429,7 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy, ...@@ -399,6 +429,7 @@ def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy,
# Now compare the output in midl_output_dir to the copied-over outputs. # Now compare the output in midl_output_dir to the copied-over outputs.
_, mismatch, errors = filecmp.cmpfiles(midl_output_dir, outdir, common_files) _, mismatch, errors = filecmp.cmpfiles(midl_output_dir, outdir, common_files)
assert not errors assert not errors
if mismatch: if mismatch:
print('midl.exe output different from files in %s, see %s' % print('midl.exe output different from files in %s, see %s' %
(outdir, midl_output_dir)) (outdir, midl_output_dir))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment