Bug 1892041 - Part 3: Update test exclusions. r=spidermonkey-reviewers,dminor
[gecko.git] / config / create_rc.py
blobb741952f43babe23144f5bbff1659e0ae63a8c16
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 import io
6 import os
7 import sys
8 from datetime import datetime
10 import buildconfig
11 from mozbuild.preprocessor import Preprocessor
13 TEMPLATE = """
14 // This Source Code Form is subject to the terms of the Mozilla Public
15 // License, v. 2.0. If a copy of the MPL was not distributed with this
16 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
18 #include<winuser.h>
19 #include<winver.h>
21 // Note: if you contain versioning information in an included
22 // RC script, it will be discarded
23 // Use module.ver to explicitly set these values
25 // Do not edit this file. Changes won't affect the build.
27 {include}
29 Identity LimitedAccessFeature {{ L"{lafidentity}_pcsmm0jrprpb2" }}
32 /////////////////////////////////////////////////////////////////////////////
34 // Version
37 1 VERSIONINFO
38 FILEVERSION {fileversion}
39 PRODUCTVERSION {productversion}
40 FILEFLAGSMASK 0x3fL
41 FILEFLAGS {fileflags}
42 FILEOS VOS__WINDOWS32
43 FILETYPE VFT_DLL
44 FILESUBTYPE 0x0L
45 BEGIN
46 BLOCK "StringFileInfo"
47 BEGIN
48 BLOCK "000004b0"
49 BEGIN
50 VALUE "Comments", "{comment}"
51 VALUE "LegalCopyright", "{copyright}"
52 VALUE "CompanyName", "{company}"
53 VALUE "FileDescription", "{description}"
54 VALUE "FileVersion", "{mfversion}"
55 VALUE "ProductVersion", "{mpversion}"
56 VALUE "InternalName", "{module}"
57 VALUE "LegalTrademarks", "{trademarks}"
58 VALUE "OriginalFilename", "{binary}"
59 VALUE "ProductName", "{productname}"
60 VALUE "BuildID", "{buildid}"
61 END
62 END
63 BLOCK "VarFileInfo"
64 BEGIN
65 VALUE "Translation", 0x0, 1200
66 END
67 END
69 """
72 def preprocess(path, defines):
73 pp = Preprocessor(defines=defines, marker="%")
74 pp.context.update(defines)
75 pp.out = io.StringIO()
76 pp.do_filter("substitution")
77 pp.do_include(io.open(path, "r", encoding="latin1"))
78 pp.out.seek(0)
79 return pp.out
82 def parse_module_ver(path, defines):
83 result = {}
84 for line in preprocess(path, defines):
85 content, *comment = line.split("#", 1)
86 if not content.strip():
87 continue
88 entry, value = content.split("=", 1)
89 result[entry.strip()] = value.strip()
90 return result
93 def get_buildid():
94 path = os.path.join(buildconfig.topobjdir, "buildid.h")
95 define, MOZ_BUILDID, buildid = io.open(path, "r", encoding="utf-8").read().split()
96 return buildid
99 def days_from_2000_to_buildid(buildid):
100 start = datetime(2000, 1, 1, 0, 0, 0)
101 buildid_time = datetime.strptime(buildid, "%Y%m%d%H%M%S")
102 return (buildid_time - start).days
105 def digits_only(s):
106 for l in range(len(s), 0, -1):
107 if s[:l].isdigit():
108 return s[:l]
109 return "0"
112 def split_and_normalize_version(version, len):
113 return ([digits_only(x) for x in version.split(".")] + ["0"] * len)[:len]
116 def has_manifest(module_rc, manifest_id):
117 for lineFromInput in module_rc.splitlines():
118 line = lineFromInput.split(None, 2)
119 if len(line) < 2:
120 continue
121 id, what, *rest = line
122 if id == manifest_id and what in ("24", "RT_MANIFEST"):
123 return True
124 return False
127 def generate_module_rc(binary="", rcinclude=None):
128 deps = set()
129 buildid = get_buildid()
130 milestone = buildconfig.substs["GRE_MILESTONE"]
131 app_version = buildconfig.substs.get("MOZ_APP_VERSION") or milestone
132 app_winversion = ",".join(split_and_normalize_version(app_version, 4))
133 milestone_winversion = ",".join(
134 split_and_normalize_version(milestone, 3)
135 + [str(days_from_2000_to_buildid(buildid))]
137 display_name = buildconfig.substs.get("MOZ_APP_DISPLAYNAME", "Mozilla")
139 milestone_string = milestone
141 flags = ["0"]
142 if buildconfig.substs.get("MOZ_DEBUG"):
143 flags.append("VS_FF_DEBUG")
144 milestone_string += " Debug"
145 if not buildconfig.substs.get("MOZILLA_OFFICIAL"):
146 flags.append("VS_FF_PRIVATEBUILD")
147 if buildconfig.substs.get("NIGHTLY_BUILD"):
148 flags.append("VS_FF_PRERELEASE")
150 defines = {
151 "MOZ_APP_DISPLAYNAME": display_name,
152 "MOZ_APP_VERSION": app_version,
153 "MOZ_APP_WINVERSION": app_winversion,
156 relobjdir = os.path.relpath(".", buildconfig.topobjdir)
157 srcdir = os.path.join(buildconfig.topsrcdir, relobjdir)
158 module_ver = os.path.join(srcdir, "module.ver")
159 if os.path.exists(module_ver):
160 deps.add(module_ver)
161 overrides = parse_module_ver(module_ver, defines)
162 else:
163 overrides = {}
165 if rcinclude:
166 include = "// From included resource {}\n{}".format(
167 rcinclude, preprocess(rcinclude, defines).read()
169 else:
170 include = ""
172 lafidentity = buildconfig.substs.get(
173 "MOZ_WINDOWS_TASKBAR_PINNING_API_CLIENTID", "LAF_ID_UNDEFINED"
176 data = TEMPLATE.format(
177 include=include,
178 lafidentity=lafidentity,
179 fileversion=overrides.get("WIN32_MODULE_FILEVERSION", milestone_winversion),
180 productversion=overrides.get(
181 "WIN32_MODULE_PRODUCTVERSION", milestone_winversion
183 fileflags=" | ".join(flags),
184 comment=overrides.get("WIN32_MODULE_COMMENT", ""),
185 copyright=overrides.get("WIN32_MODULE_COPYRIGHT", "License: MPL 2"),
186 company=overrides.get("WIN32_MODULE_COMPANYNAME", "Mozilla Foundation"),
187 description=overrides.get("WIN32_MODULE_DESCRIPTION", ""),
188 mfversion=overrides.get("WIN32_MODULE_FILEVERSION_STRING", milestone_string),
189 mpversion=overrides.get("WIN32_MODULE_PRODUCTVERSION_STRING", milestone_string),
190 module=overrides.get("WIN32_MODULE_NAME", ""),
191 trademarks=overrides.get("WIN32_MODULE_TRADEMARKS", "Mozilla"),
192 binary=overrides.get("WIN32_MODULE_ORIGINAL_FILENAME", binary),
193 productname=overrides.get("WIN32_MODULE_PRODUCTNAME", display_name),
194 buildid=buildid,
197 manifest_id = "2" if binary.lower().endswith(".dll") else "1"
198 if binary and not has_manifest(data, manifest_id):
199 manifest_path = os.path.join(srcdir, binary + ".manifest")
200 if os.path.exists(manifest_path):
201 manifest_path = manifest_path.replace("\\", "\\\\")
202 data += '\n{} RT_MANIFEST "{}"\n'.format(manifest_id, manifest_path)
204 with io.open("{}.rc".format(binary or "module"), "w", encoding="latin1") as fh:
205 fh.write(data)
208 if __name__ == "__main__":
209 generate_module_rc(*sys.argv[1:])