Skip to content

Commit

Permalink
midl.py remove legacy |dynamic_guid|, replace with new |dynamic_guids|.
Browse files Browse the repository at this point in the history
* Changed all Chromium projects using |dynamic_guid| to use the new
|dynamic_guids| multiple guid substitution enhancements.
* Removed the legacy |dynamic_guid| code.

Bug: 1109612
Change-Id: I2fb012884db39ad5489e988aef75113dd8c0258f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2500952
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Joe Downing <joedow@google.com>
Commit-Queue: S. Ganesh <ganesh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821517}
  • Loading branch information
GitHubGanesh authored and Commit Bot committed Oct 28, 2020
1 parent 25ebb7a commit 8684297
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 111 deletions.
19 changes: 13 additions & 6 deletions build/toolchain/win/midl.gni
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ import("//build/config/win/visual_studio_version.gni")
# Directory where generated files were previously persisted.
# Defaults to third_party\win_build_output\midl\|out_dir|.
#
# dynamic_guid (optional)
# If the GUID is not constant across builds, the current GUID.
# dynamic_guids (optional)
# If the GUIDs are not constant across builds, the current GUID
# substitutions.
# |dynamic_guids| is of the form:
# "PLACEHOLDER-GUID-158428a4-6014-4978-83ba-9fad0dabe791="
# "3d852661-c795-4d20-9b95-5561e9a1d2d9,"
# "PLACEHOLDER-GUID-63B8FFB1-5314-48C9-9C57-93EC8BC6184B="
# "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83".
# See midl.py for more details.
#
# writes_tlb (optional)
# Whether a .tlb file should be added to outputs. Defaults to false.
Expand Down Expand Up @@ -58,10 +65,10 @@ template("midl") {
rebase_path(out_dir, root_gen_dir)
}

if (defined(invoker.dynamic_guid)) {
dynamic_guid = invoker.dynamic_guid
if (defined(invoker.dynamic_guids)) {
dynamic_guids = invoker.dynamic_guids
} else {
dynamic_guid = "none"
dynamic_guids = "none"
}

if (defined(invoker.header_file)) {
Expand Down Expand Up @@ -117,7 +124,7 @@ template("midl") {
win_tool_arch,
generated_dir,
rebase_path(out_dir, root_build_dir),
dynamic_guid,
dynamic_guids,
type_library_file,
header_file,
dlldata_file,
Expand Down
79 changes: 13 additions & 66 deletions build/toolchain/win/midl.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,6 @@ def ZapTimestamp(filename):
open(filename, 'wb').write(contents)


def overwrite_cls_guid_h(h_file, dynamic_guid):
contents = open(h_file, 'rb').read()
contents = re.sub(br'class DECLSPEC_UUID\("[^"]*"\)',
br'class DECLSPEC_UUID("%s")' % str(dynamic_guid).encode(),
contents)
open(h_file, 'wb').write(contents)


def overwrite_cls_guid_iid(iid_file, dynamic_guid):
contents = open(iid_file, 'rb').read()
hexuuid = '0x%08x,0x%04x,0x%04x,' % dynamic_guid.fields[0:3]

# dynamic_guid.bytes is a bytestring in Py3, but a normal string in Py2.
if sys.version_info.major == 2:
hexuuid += ','.join('0x%02x' % ord(b) for b in dynamic_guid.bytes[8:])
else:
hexuuid += ','.join('0x%02x' % b for b in dynamic_guid.bytes[8:])

contents = re.sub(br'MIDL_DEFINE_GUID\(CLSID, ([^,]*),[^)]*\)',
br'MIDL_DEFINE_GUID(CLSID, \1,%s)' % hexuuid.encode(),
contents)
open(iid_file, 'wb').write(contents)


def get_tlb_contents(tlb_file):
# See ZapTimestamp() for a short overview of the .tlb format.
contents = open(tlb_file, 'rb').read()
Expand Down Expand Up @@ -160,33 +136,6 @@ def recreate_guid_hashtable(contents, ntypes, guid_off, guid_len):
struct.pack_into('<I', contents, hash_off + 4*i, hashval)


def overwrite_cls_guid_tlb(tlb_file, dynamic_guid):
contents, ntypes, type_off, guid_off, guid_len = get_tlb_contents(tlb_file)

# The first type should be a coclass. It points to the type's GUID in
# section 6, the GUID section.
coclass, = struct.unpack_from('<B', contents, type_off)
assert coclass == 0x25, "expected coclass"

guidind = struct.unpack_from('<I', contents, type_off + 0x2c)[0]
assert guidind + 14 <= guid_len
struct.pack_into('<IHH8s', contents, guid_off + guidind,
*(dynamic_guid.fields[0:3] + (dynamic_guid.bytes[8:], )))

recreate_guid_hashtable(contents, ntypes, guid_off, guid_len)
open(tlb_file, 'wb').write(contents)


# Handle a single clsid substitution where |dynamic_guid| is of the form
# "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83".
def overwrite_cls_guid(h_file, iid_file, tlb_file, dynamic_guid):
# Fix up GUID in .h, _i.c, and .tlb. This function assumes that there is only
# one coclass in the idl file, and that that's the type with the dynamic type.
overwrite_cls_guid_h(h_file, dynamic_guid)
overwrite_cls_guid_iid(iid_file, dynamic_guid)
overwrite_cls_guid_tlb(tlb_file, dynamic_guid)


def overwrite_guids_h(h_file, dynamic_guids):
contents = open(h_file, 'rb').read()
for key in dynamic_guids:
Expand Down Expand Up @@ -339,8 +288,8 @@ def run_midl(args, env_dict):
return 0, midl_output_dir


def main(arch, gendir, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, clang,
idl, *flags):
def main(arch, gendir, outdir, dynamic_guids, tlb, h, dlldata, iid, proxy,
clang, idl, *flags):
# Copy checked-in outputs to final location.
source = gendir
if os.path.isdir(os.path.join(source, os.path.basename(idl))):
Expand All @@ -349,18 +298,16 @@ def main(arch, gendir, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, clang,
source = os.path.normpath(source)
distutils.dir_util.copy_tree(source, outdir, preserve_times=False)

dynamic_guids = None
if dynamic_guid != 'none':
if '=' not in dynamic_guid:
overwrite_cls_guid(os.path.join(outdir, h), os.path.join(outdir, iid),
os.path.join(outdir, tlb), uuid.UUID(dynamic_guid))
else:
dynamic_guids = re.sub('PLACEHOLDER-GUID-', '', dynamic_guid, flags=re.I)
dynamic_guids = dynamic_guids.split(',')
dynamic_guids = dict(s.split('=') for s in dynamic_guids)
overwrite_guids(os.path.join(outdir, h), os.path.join(outdir, iid),
os.path.join(outdir, proxy), os.path.join(outdir, tlb),
dynamic_guids)
if dynamic_guids != 'none':
assert '=' in dynamic_guids
dynamic_guids = re.sub('PLACEHOLDER-GUID-', '', dynamic_guids, flags=re.I)
dynamic_guids = dynamic_guids.split(',')
dynamic_guids = dict(s.split('=') for s in dynamic_guids)
overwrite_guids(os.path.join(outdir, h), os.path.join(outdir, iid),
os.path.join(outdir, proxy), os.path.join(outdir, tlb),
dynamic_guids)
else:
dynamic_guids = None

# On non-Windows, that's all we can do.
if sys.platform != 'win32':
Expand All @@ -383,7 +330,7 @@ def main(arch, gendir, outdir, dynamic_guid, tlb, h, dlldata, iid, proxy, clang,

# On Windows, run midl.exe on the input and check that its outputs are
# identical to the checked-in outputs (after replacing guids if
# |dynamic_guid(s)| is specified).
# |dynamic_guids| is specified).

# Read the environment block from the file. This is stored in the format used
# by CreateProcess. Drop last 2 NULs, one for list terminator, one for
Expand Down
21 changes: 4 additions & 17 deletions chrome/credential_provider/gaiacp/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -237,31 +237,18 @@ process_version_rc_template("version") {
output = "$root_out_dir/gaia_credential_provider.rc"
}

GCP_PLACEHOLDER_CLSID = "PLACEHOLDER-GUID-89adae71-aee5-4ee2-bffb-e8424e06f519"

if (is_chrome_branded) {
gaia_credential_provider_clsid = "0b5bfdf0-4594-47ac-940a-cfc69abc561c"
} else {
gaia_credential_provider_clsid = "89adae71-aee5-4ee2-bffb-e8424e06f519"
}

action("generate_credential_provider_idl_file") {
script = "//build/util/version.py"

inputs = [ "gaia_credential_provider_idl.templ" ]
outputs = [ "$target_gen_dir/gaia_credential_provider.idl" ]

args = [
"-e",
"GAIA_CREDENTIAL_PROVIDER_CLSID='$gaia_credential_provider_clsid'",
rebase_path(inputs[0], root_build_dir),
rebase_path(outputs[0], root_build_dir),
]
}

midl("gaia_credential_provider_idl") {
dynamic_guid = gaia_credential_provider_clsid
deps = [ ":generate_credential_provider_idl_file" ]
dynamic_guids = "$GCP_PLACEHOLDER_CLSID=$gaia_credential_provider_clsid"
header_file = "gaia_credential_provider_i.h"
sources = get_target_outputs(":generate_credential_provider_idl_file")
sources = [ "gaia_credential_provider.templ" ]
}

grit("static_resources") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ library GaiaCredentialProviderLib
{
importlib("stdole2.tlb");
[
uuid(@GAIA_CREDENTIAL_PROVIDER_CLSID@),
uuid(PLACEHOLDER-GUID-89adae71-aee5-4ee2-bffb-e8424e06f519),
]
coclass GaiaCredentialProvider
{
Expand Down
4 changes: 2 additions & 2 deletions chrome/updater/app/server/win/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ updater_clsid = "3d852661-c795-4d20-9b95-5561e9a1d2d9"
IUPDATER_IID = "D0E1CACC-C63C-4192-94AB-BF8EAD0E3B83"

midl("updater_idl_idl") {
dynamic_guid = "$UpdaterClass_replaceable_uuid=$updater_clsid," +
"$IUpdater_replaceable_uuid=$IUPDATER_IID"
dynamic_guids = "$UpdaterClass_replaceable_uuid=$updater_clsid," +
"$IUpdater_replaceable_uuid=$IUPDATER_IID"

header_file = "updater_idl.h"
sources = [ "updater_idl.template" ]
Expand Down
25 changes: 7 additions & 18 deletions remoting/host/win/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -176,24 +176,13 @@ source_set("unit_tests") {
]
}

action("generate_idl") {
script = "//build/util/version.py"

inputs = [ "chromoting_lib_idl.templ" ]
outputs = [ "$target_gen_dir/chromoting_lib.idl" ]

args = [
"-e",
"RDP_DESKTOP_SESSION_CLSID='$rdp_desktop_session_clsid'",
rebase_path(inputs[0], root_build_dir),
rebase_path(outputs[0], root_build_dir),
]
}
RDP_DESKTOP_SESSION_PLACEHOLDER_CLSID =
"PLACEHOLDER-GUID-6741fd0a-6a8a-5838-a35e-8088697e2088"

midl("remoting_lib_idl") {
sources = get_target_outputs(":generate_idl")
dynamic_guid = rdp_desktop_session_clsid
deps = [ ":generate_idl" ]
sources = [ "chromoting_lib.templ" ]
dynamic_guids =
"$RDP_DESKTOP_SESSION_PLACEHOLDER_CLSID=$rdp_desktop_session_clsid"
writes_tlb = true
}

Expand All @@ -218,8 +207,8 @@ config("MIDL_config") {

static_library("remoting_lib_ps") {
sources = [
"$root_gen_dir/remoting/host/win/chromoting_lib.dlldata.c",
"$root_gen_dir/remoting/host/win/chromoting_lib_p.c",
"$target_gen_dir/chromoting_lib.dlldata.c",
"$target_gen_dir/chromoting_lib_p.c",
]

configs -= [ "//build/config/compiler:chromium_code" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ library ChromotingLib {
importlib("stdole2.tlb");

[
uuid(@RDP_DESKTOP_SESSION_CLSID@),
uuid(PLACEHOLDER-GUID-6741fd0a-6a8a-5838-a35e-8088697e2088),
helpstring("RdpDesktopSession Class")
]
coclass RdpDesktopSession {
Expand Down

0 comments on commit 8684297

Please sign in to comment.