Skip to content

Commit

Permalink
Unify mc.exe calling in GN, set environment.
Browse files Browse the repository at this point in the history
There were previously two message compiler wrapper scripts which this unifies into one template and script in build.

Explicitly sets the environment block when running mc.exe. Currently GN sets this automatically but will soon stop doing this.

Review URL: https://codereview.chromium.org/1440693003

Cr-Commit-Position: refs/heads/master@{#359155}
  • Loading branch information
brettw authored and Commit bot committed Nov 11, 2015
1 parent f37b704 commit 4744642
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 119 deletions.
42 changes: 7 additions & 35 deletions base/trace_event/etw_manifest/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,19 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(is_win, "This only runs on Windows.")

# Makes the .h/.rc files from the .man file.
action("chrome_events_win_generate") {
visibility = [ ":*" ]
script = "build/message_compiler.py"

sources = [
"chrome_events_win.man",
]

outputs = [
"$target_gen_dir/chrome_events_win.h",
"$target_gen_dir/chrome_events_win.rc",
]

args = [
# Where to put the header.
"-h",
rebase_path("$target_gen_dir", root_build_dir),
import("//build/win/message_compiler.gni")

# Where to put the .rc file.
"-r",
rebase_path("$target_gen_dir", root_build_dir),

# Generate the user-mode code.
"-um",
rebase_path("chrome_events_win.man", root_build_dir),
]
}
assert(is_win, "This only runs on Windows.")

# Compile the generated files.
source_set("chrome_events_win") {
message_compiler("chrome_events_win") {
visibility = [
"//base/trace_event/*",
"//chrome:main_dll",
]

sources = get_target_outputs(":chrome_events_win_generate")

deps = [
":chrome_events_win_generate",
sources = [
"chrome_events_win.man",
]

user_mode_logging = true
}
16 changes: 0 additions & 16 deletions base/trace_event/etw_manifest/BUILD/message_compiler.py

This file was deleted.

71 changes: 71 additions & 0 deletions build/win/message_compiler.gni
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(is_win, "This only runs on Windows.")

# Runs mc.exe over a list of sources. The outputs (a header and rc file) are
# placed in the target gen dir, and compiled.
#
# sources
# List of message files to process.
#
# user_mode_logging (optional bool)
# Generates user-mode logging code. Defaults to false (no logging code).
#
# deps, public_deps, visibility
# Normal meaning.
template("message_compiler") {
action_name = "${target_name}_mc"
source_set_name = target_name

action_foreach(action_name) {
visibility = [ ":$source_set_name" ]

script = "//build/win/message_compiler.py"

outputs = [
"$target_gen_dir/{{source_name_part}}.h",
"$target_gen_dir/{{source_name_part}}.rc",
]

args = [
# The first argument is the environment file saved to the build
# directory. This is required because the Windows toolchain setup saves
# the VC paths and such so that running "mc.exe" will work with the
# configured toolchain. This file is in the root build dir.
"environment.$current_cpu",

# Where to put the header.
"-h",
rebase_path(target_gen_dir, root_build_dir),

# Where to put the .rc file.
"-r",
rebase_path(target_gen_dir, root_build_dir),

# Input is Unicode.
"-u",
]
if (defined(invoker.user_mode_logging) && invoker.user_mode_logging) {
args += [ "-um" ]
}
args += [ "{{source}}" ]

forward_variables_from(invoker,
[
"deps",
"public_deps",
"sources",
])
}

# Compile the generated rc file.
source_set(source_set_name) {
forward_variables_from(invoker, [ "visibility" ])
sources = get_target_outputs(":$action_name")
deps = [
":$action_name",
]
}
}
26 changes: 26 additions & 0 deletions build/win/message_compiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Runs the Microsoft Message Compiler (mc.exe). This Python adapter is for the
# GN build, which can only run Python and not native binaries.
#
# Usage: message_compiler.py <environment_file> [<args to mc.exe>*]

import subprocess
import sys

# 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 trailing
# vs. separator.
env_pairs = open(sys.argv[1]).read()[:-2].split('\0')
env_dict = dict([item.split('=', 1) for item in env_pairs])

# mc writes to stderr, so this explicitly redirects to stdout and eats it.
try:
subprocess.check_output(["mc.exe"] + sys.argv[2:],
env=env_dict,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print e.output
sys.exit(e.returncode)
2 changes: 1 addition & 1 deletion remoting/host/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ if (is_mac) { # TODO(GYP) Mac build of remoting host.

if (is_win) {
import("//build/toolchain/win/midl.gni")
import("//remoting/tools/build/message_compiler.gni")
import("//build/win/message_compiler.gni")

# TODO(brettw) these should not be generated via exec_script. This should be
# part of the build process rather than the metabuild. Instead, a script
Expand Down
51 changes: 0 additions & 51 deletions remoting/tools/build/message_compiler.gni

This file was deleted.

16 changes: 0 additions & 16 deletions remoting/tools/build/message_compiler.py

This file was deleted.

0 comments on commit 4744642

Please sign in to comment.