Commit 82c2ac25 authored by Nico Weber's avatar Nico Weber Committed by Commit Bot

win: Stop relying on %INCLUDE% for the resource compiler.

Instead, use -imsvc and the hermetic toolchain for the preprocessor, and
don't look in system include dirs for resources.

This means we can't include resources from the system include dirs,
but we don't want to do that anyways.

For now, keep using tool_wrapper to set the env so that we can
find MS rc.exe on %PATH%.

Bug: none
Change-Id: I1065be2513659c6eb5b4de440299fa86cfb58736
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1863149Reviewed-by: default avatarHans Wennborg <hans@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706916}
parent e4635fff
...@@ -212,7 +212,7 @@ template("msvc_toolchain") { ...@@ -212,7 +212,7 @@ template("msvc_toolchain") {
} }
tool("rc") { tool("rc") {
command = "$python_path $tool_wrapper_path rc-wrapper $env rc.exe /nologo {{defines}} {{include_dirs}} /fo{{output}} {{source}}" command = "$python_path $tool_wrapper_path rc-wrapper $env rc.exe /nologo $sys_include_flags{{defines}} {{include_dirs}} /fo{{output}} {{source}}"
depsformat = "msvc" depsformat = "msvc"
outputs = [ outputs = [
"$object_subdir/{{source_name_part}}.res", "$object_subdir/{{source_name_part}}.res",
......
...@@ -8,7 +8,8 @@ A resource compiler for .rc files. ...@@ -8,7 +8,8 @@ A resource compiler for .rc files.
options: options:
-h, --help Print this message. -h, --help Print this message.
-I<dir> Add include path. -I<dir> Add include path, used for both headers and resources.
-imsvc<dir> Add system include path, used for preprocessing only.
-D<sym> Define a macro for the preprocessor. -D<sym> Define a macro for the preprocessor.
/fo<out> Set path of output .res file. /fo<out> Set path of output .res file.
/nologo Ignored (rc.py doesn't print a logo by default). /nologo Ignored (rc.py doesn't print a logo by default).
...@@ -33,6 +34,7 @@ def ParseFlags(): ...@@ -33,6 +34,7 @@ def ParseFlags():
"""Parses flags off sys.argv and returns the parsed flags.""" """Parses flags off sys.argv and returns the parsed flags."""
# Can't use optparse / argparse because of /fo flag :-/ # Can't use optparse / argparse because of /fo flag :-/
includes = [] includes = []
imsvcs = []
defines = [] defines = []
output = None output = None
input = None input = None
...@@ -44,6 +46,8 @@ def ParseFlags(): ...@@ -44,6 +46,8 @@ def ParseFlags():
sys.exit(0) sys.exit(0)
if flag.startswith('-I'): if flag.startswith('-I'):
includes.append(flag) includes.append(flag)
elif flag.startswith('-imsvc'):
imsvcs.append(flag)
elif flag.startswith('-D'): elif flag.startswith('-D'):
defines.append(flag) defines.append(flag)
elif flag.startswith('/fo'): elif flag.startswith('/fo'):
...@@ -72,10 +76,10 @@ def ParseFlags(): ...@@ -72,10 +76,10 @@ def ParseFlags():
sys.exit(1) sys.exit(1)
if not output: if not output:
output = os.path.splitext(input)[0] + '.res' output = os.path.splitext(input)[0] + '.res'
Flags = namedtuple('Flags', ['includes', 'defines', 'output', 'input', Flags = namedtuple('Flags', ['includes', 'defines', 'output', 'imsvcs',
'show_includes']) 'input', 'show_includes'])
return Flags(includes=includes, defines=defines, output=output, input=input, return Flags(includes=includes, defines=defines, output=output, imsvcs=imsvcs,
show_includes=show_includes) input=input, show_includes=show_includes)
def ReadInput(input): def ReadInput(input):
...@@ -119,13 +123,13 @@ def Preprocess(rc_file_data, flags): ...@@ -119,13 +123,13 @@ def Preprocess(rc_file_data, flags):
# Closing temp_handle immediately defeats the purpose of mkstemp(), but I # Closing temp_handle immediately defeats the purpose of mkstemp(), but I
# can't figure out how to let write to the temp file on Windows otherwise. # can't figure out how to let write to the temp file on Windows otherwise.
os.close(temp_handle) os.close(temp_handle)
clang_cmd = [clang, '/P', '/DRC_INVOKED', '/TC', '-', '/Fi' + temp_file] clang_cmd = [clang, '/P', '/X', '/DRC_INVOKED', '/TC', '-', '/Fi' + temp_file]
if os.path.dirname(flags.input): if os.path.dirname(flags.input):
# This must precede flags.includes. # This must precede flags.includes.
clang_cmd.append('-I' + os.path.dirname(flags.input)) clang_cmd.append('-I' + os.path.dirname(flags.input))
if flags.show_includes: if flags.show_includes:
clang_cmd.append('/showIncludes') clang_cmd.append('/showIncludes')
clang_cmd += flags.includes + flags.defines clang_cmd += flags.imsvcs + flags.includes + flags.defines
p = subprocess.Popen(clang_cmd, stdin=subprocess.PIPE) p = subprocess.Popen(clang_cmd, stdin=subprocess.PIPE)
p.communicate(input=rc_file_data) p.communicate(input=rc_file_data)
if p.returncode != 0: if p.returncode != 0:
...@@ -198,7 +202,7 @@ def CompareToMsRcOutput(preprocessed_output, is_utf8, flags): ...@@ -198,7 +202,7 @@ def CompareToMsRcOutput(preprocessed_output, is_utf8, flags):
f.write(preprocessed_output) f.write(preprocessed_output)
msrc_out = flags.output + '_ms_rc' msrc_out = flags.output + '_ms_rc'
msrc_cmd = ['rc', '/nologo', '/fo' + msrc_out] msrc_cmd = ['rc', '/nologo', '/x', '/fo' + msrc_out]
# Make sure rc-relative resources can be found. rc.exe looks for external # Make sure rc-relative resources can be found. rc.exe looks for external
# resource files next to the file, but the preprocessed file isn't where the # resource files next to the file, but the preprocessed file isn't where the
......
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