Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
from argparse import (
|
|
|
|
Action,
|
|
|
|
ArgumentParser,
|
|
|
|
)
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
import buildconfig
|
|
|
|
|
|
|
|
|
|
|
|
class CPPFlag(Action):
|
|
|
|
all_flags = []
|
|
|
|
|
|
|
|
def __call__(self, parser, namespace, values, option_string=None):
|
2020-10-24 03:36:18 +03:00
|
|
|
if "windres" in buildconfig.substs["RC"].lower():
|
|
|
|
if option_string == "-U":
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
return
|
2020-10-24 03:36:18 +03:00
|
|
|
if option_string == "-I":
|
|
|
|
option_string = "--include-dir"
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
|
|
|
|
self.all_flags.extend((option_string, values))
|
|
|
|
|
|
|
|
|
|
|
|
def generate_res():
|
|
|
|
parser = ArgumentParser()
|
2020-10-24 03:36:18 +03:00
|
|
|
parser.add_argument(
|
|
|
|
"-D", action=CPPFlag, metavar="VAR[=VAL]", help="Define a variable"
|
|
|
|
)
|
|
|
|
parser.add_argument("-U", action=CPPFlag, metavar="VAR", help="Undefine a variable")
|
|
|
|
parser.add_argument(
|
|
|
|
"-I", action=CPPFlag, metavar="DIR", help="Search path for includes"
|
|
|
|
)
|
|
|
|
parser.add_argument("-o", dest="output", metavar="OUTPUT", help="Output file")
|
|
|
|
parser.add_argument("input", help="Input file")
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
is_windres = "windres" in buildconfig.substs["RC"].lower()
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
verbose = os.environ.get("BUILD_VERBOSE_LOG")
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
|
|
|
|
# llvm-rc doesn't preprocess on its own, so preprocess manually
|
|
|
|
# Theoretically, not windres could be rc.exe, but configure won't use it
|
|
|
|
# unless you really ask for it, and it will still work with preprocessed
|
|
|
|
# output.
|
|
|
|
try:
|
|
|
|
if not is_windres:
|
2020-10-24 03:36:18 +03:00
|
|
|
fd, path = tempfile.mkstemp(suffix=".rc")
|
|
|
|
command = buildconfig.substs["CXXCPP"] + CPPFlag.all_flags
|
|
|
|
command.extend(("-DRC_INVOKED", args.input))
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
if verbose:
|
2020-10-24 03:36:18 +03:00
|
|
|
print("Executing:", " ".join(command))
|
|
|
|
with os.fdopen(fd, "wb") as fh:
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
retcode = subprocess.run(command, stdout=fh).returncode
|
|
|
|
if retcode:
|
|
|
|
# Rely on the subprocess printing out any relevant error
|
|
|
|
return retcode
|
|
|
|
else:
|
|
|
|
path = args.input
|
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
command = [buildconfig.substs["RC"]]
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
if is_windres:
|
2020-10-24 03:36:18 +03:00
|
|
|
command.extend(("-O", "coff"))
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
|
|
|
|
# Even though llvm-rc doesn't preprocess, we still need to pass at least
|
|
|
|
# the -I flags.
|
|
|
|
command.extend(CPPFlag.all_flags)
|
|
|
|
|
|
|
|
if args.output:
|
|
|
|
if is_windres:
|
2020-10-24 03:36:18 +03:00
|
|
|
command.extend(("-o", args.output))
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
else:
|
|
|
|
# Use win1252 code page for the input.
|
2020-10-24 03:36:18 +03:00
|
|
|
command.extend(("-c", "1252", "-Fo" + args.output))
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
|
|
|
|
command.append(path)
|
|
|
|
|
|
|
|
if verbose:
|
2020-10-24 03:36:18 +03:00
|
|
|
print("Executing:", " ".join(command))
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
retcode = subprocess.run(command).returncode
|
|
|
|
if retcode:
|
|
|
|
# Rely on the subprocess printing out any relevant error
|
|
|
|
return retcode
|
|
|
|
finally:
|
|
|
|
if path != args.input:
|
|
|
|
os.remove(path)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2020-10-24 03:36:18 +03:00
|
|
|
if __name__ == "__main__":
|
Bug 1537703 - Use llvm-rc instead of rc.exe. r=mhentges,froydnj
This makes us use one less tool from MSVC, and removes one more use of wine
in cross builds.
We replace the call to either rc/llvm-rc or windres with a wrapper script.
While the script is not strictly needed for the latter, we use a wrapper
in that case anyway because it's one step towards fixing bug 1498414.
For llvm-rc, however, we need a wrapper because llvm-rc doesn't preprocess
on its own, so the wrapper does that too.
The wrapper script also allows to deal with the default flags passed to
llvm-rc or windres, rather than inherit them from old-configure.
We also need to explicitly pass the codepage to llvm-rc, which was not
necessary with rc (presumably, llvm-rc has a different default).
While here, remove the unused WINDRES subst from js/src/old-configure.in.
Also, while here, we remove --use-temp-file, because as described in the
linked bug and in the windres manual page, it was used to work around bugs
on Windows 98 and earlier.
Differential Revision: https://phabricator.services.mozilla.com/D86312
2020-08-09 00:02:04 +03:00
|
|
|
sys.exit(generate_res())
|