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/.
8 from datetime
import datetime
11 from mozbuild
.preprocessor
import Preprocessor
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/.
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.
29 Identity LimitedAccessFeature {{ L"{lafidentity}_pcsmm0jrprpb2" }}
32 /////////////////////////////////////////////////////////////////////////////
38 FILEVERSION {fileversion}
39 PRODUCTVERSION {productversion}
46 BLOCK "StringFileInfo"
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}"
65 VALUE "Translation", 0x0, 1200
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"))
82 def parse_module_ver(path
, defines
):
84 for line
in preprocess(path
, defines
):
85 content
, *comment
= line
.split("#", 1)
86 if not content
.strip():
88 entry
, value
= content
.split("=", 1)
89 result
[entry
.strip()] = value
.strip()
94 path
= os
.path
.join(buildconfig
.topobjdir
, "buildid.h")
95 define
, MOZ_BUILDID
, buildid
= io
.open(path
, "r", encoding
="utf-8").read().split()
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
106 for l
in range(len(s
), 0, -1):
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)
121 id, what
, *rest
= line
122 if id == manifest_id
and what
in ("24", "RT_MANIFEST"):
127 def generate_module_rc(binary
="", rcinclude
=None):
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
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")
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
):
161 overrides
= parse_module_ver(module_ver
, defines
)
166 include
= "// From included resource {}\n{}".format(
167 rcinclude
, preprocess(rcinclude
, defines
).read()
172 lafidentity
= buildconfig
.substs
.get(
173 "MOZ_WINDOWS_TASKBAR_PINNING_API_CLIENTID", "LAF_ID_UNDEFINED"
176 data
= TEMPLATE
.format(
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
),
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
:
208 if __name__
== "__main__":
209 generate_module_rc(*sys
.argv
[1:])