Skip to content

Commit 75045e1

Browse files
sdefresnecopybara-github
authored andcommitted
[ios/mac] Preliminary work to untangle templates and scripts
Create new directories //build/apple, //build/config/apple and //build/toolchain/apple to hold templates, configs and scripts shared by Apple platforms (iOS and macOS). This will allow to isolate platform specific templates, configs and scripts in //build/{ios,mac}, //build/config/{ios,mac} and //build/toolchain/{ios,mac} eventually making easier to change one platform without breaking the other. Move tweak_info_plist.{py,gni} to //build/apple as a first step to ensure that it is possible to move files without breaking the projects based on //build (webrtc, ios_internal, ...). Bug: 635745 Change-Id: Ieb9df43fc638891f3975495f87a9612e22bc3c7e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2270464 Reviewed-by: Rohit Rao <[email protected]> Reviewed-by: Mike Pinkerton <[email protected]> Reviewed-by: Mark Mentovai <[email protected]> Commit-Queue: Sylvain Defresne <[email protected]> Cr-Commit-Position: refs/heads/master@{#784006} GitOrigin-RevId: b3a8c60411360e89c3a729e8aaf1ea98db661129
1 parent 9e3cf1d commit 75045e1

File tree

12 files changed

+208
-151
lines changed

12 files changed

+208
-151
lines changed

apple/OWNERS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
3+
4+

apple/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# About
2+
3+
`//build/apple` contains:
4+
* GN templates and configurations shared by Apple platforms
5+
* Python build scripts shared by Apple platforms
6+
7+
This directory should only contain templates, configurations and scripts
8+
that are used exclusively on Apple platforms (currently iOS and macOS).
9+
They must also be independent of the specific platform.
10+
11+
If a template, configuration or script is limited to only iOS or macOS,
12+
then they should instead be located in `//build/ios` or `//build/mac`.

apple/tweak_info_plist.gni

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Copyright 2016 The Chromium Authors. All rights reserved.
2+
# Use of this source code is governed by a BSD-style license that can be
3+
# found in the LICENSE file.
4+
5+
import("//build/util/lastchange.gni")
6+
7+
# Template to run the tweak_info_plist.py script on a plist.
8+
#
9+
# Arguments:
10+
#
11+
# info_plist:
12+
# (optional), string, the plist to tweak.
13+
#
14+
# info_plists:
15+
# (optional), list of string, the plist files to merge and tweak.
16+
#
17+
# args:
18+
# (optional), list of string, the arguments to pass to the
19+
# tweak_info_plist.py script.
20+
#
21+
# Callers should use get_target_outputs() to get the output name. One of
22+
# info_plist or info_plists must be specified.
23+
template("tweak_info_plist") {
24+
_output_name = "$target_gen_dir/${target_name}_tweaked.plist"
25+
26+
if (defined(invoker.info_plists)) {
27+
assert(!defined(invoker.info_plist),
28+
"Cannot have both info_plist and info_plists for $target_name")
29+
30+
_source_name = "$target_gen_dir/${target_name}_merged.plist"
31+
_deps = [ ":" + target_name + "_merge_plist" ]
32+
33+
action(target_name + "_merge_plist") {
34+
forward_variables_from(invoker,
35+
[
36+
"testonly",
37+
"deps",
38+
])
39+
script = "//build/config/mac/plist_util.py"
40+
sources = invoker.info_plists
41+
outputs = [ _source_name ]
42+
args = [
43+
"merge",
44+
"-f=xml1",
45+
"-o=" + rebase_path(_source_name, root_build_dir),
46+
] + rebase_path(invoker.info_plists, root_build_dir)
47+
}
48+
} else {
49+
assert(defined(invoker.info_plist),
50+
"The info_plist must be specified in $target_name")
51+
52+
_source_name = invoker.info_plist
53+
_deps = []
54+
if (defined(invoker.deps)) {
55+
_deps += invoker.deps
56+
}
57+
}
58+
59+
action(target_name) {
60+
forward_variables_from(invoker,
61+
[
62+
"args",
63+
"testonly",
64+
])
65+
script = "//build/apple/tweak_info_plist.py"
66+
inputs = [
67+
script,
68+
"//build/util/version.py",
69+
lastchange_file,
70+
"//chrome/VERSION",
71+
]
72+
sources = [ _source_name ]
73+
outputs = [ _output_name ]
74+
if (!defined(args)) {
75+
args = []
76+
}
77+
args += [
78+
"--plist",
79+
rebase_path(_source_name, root_build_dir),
80+
"--output",
81+
rebase_path(_output_name, root_build_dir),
82+
"--platform=$current_os",
83+
]
84+
deps = _deps
85+
}
86+
}

mac/tweak_info_plist.py renamed to apple/tweak_info_plist.py

Lines changed: 93 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def _GetOutputNoError(args):
5252
the child (like file not found), the exception will be caught and (None, 1)
5353
will be returned to mimic quiet failure."""
5454
try:
55-
proc = subprocess.Popen(args, stdout=subprocess.PIPE,
55+
proc = subprocess.Popen(args,
56+
stdout=subprocess.PIPE,
5657
stderr=subprocess.PIPE)
5758
except OSError:
5859
return (None, 1)
@@ -101,17 +102,18 @@ def _GetVersion(version_format, values, overrides=None):
101102
return result
102103

103104

104-
def _AddVersionKeys(
105-
plist, version_format_for_key, version=None, overrides=None):
105+
def _AddVersionKeys(plist, version_format_for_key, version=None,
106+
overrides=None):
106107
"""Adds the product version number into the plist. Returns True on success and
107108
False on error. The error will be printed to stderr."""
108109
if not version:
109110
# Pull in the Chrome version number.
110111
VERSION_TOOL = os.path.join(TOP, 'build/util/version.py')
111112
VERSION_FILE = os.path.join(TOP, 'chrome/VERSION')
112113
(stdout, retval) = _GetOutput([
113-
VERSION_TOOL, '-f', VERSION_FILE,
114-
'-t', '@MAJOR@.@MINOR@.@BUILD@.@PATCH@'])
114+
VERSION_TOOL, '-f', VERSION_FILE, '-t',
115+
'@MAJOR@.@MINOR@.@BUILD@.@PATCH@'
116+
])
115117

116118
# If the command finished with a non-zero return code, then report the
117119
# error up.
@@ -144,8 +146,8 @@ def _DoSCMKeys(plist, add_keys):
144146
# Pull in the Chrome revision number.
145147
VERSION_TOOL = os.path.join(TOP, 'build/util/version.py')
146148
LASTCHANGE_FILE = os.path.join(TOP, 'build/util/LASTCHANGE')
147-
(stdout, retval) = _GetOutput([VERSION_TOOL, '-f', LASTCHANGE_FILE, '-t',
148-
'@LASTCHANGE@'])
149+
(stdout, retval) = _GetOutput(
150+
[VERSION_TOOL, '-f', LASTCHANGE_FILE, '-t', '@LASTCHANGE@'])
149151
if retval:
150152
return False
151153
scm_revision = stdout.rstrip()
@@ -178,20 +180,15 @@ def _AddBreakpadKeys(plist, branding, platform, staging):
178180

179181
def _RemoveBreakpadKeys(plist):
180182
"""Removes any set Breakpad keys."""
181-
_RemoveKeys(plist,
182-
'BreakpadURL',
183-
'BreakpadReportInterval',
184-
'BreakpadProduct',
185-
'BreakpadProductDisplay',
186-
'BreakpadVersion',
187-
'BreakpadSendAndExit',
188-
'BreakpadSkipConfirm')
183+
_RemoveKeys(plist, 'BreakpadURL', 'BreakpadReportInterval', 'BreakpadProduct',
184+
'BreakpadProductDisplay', 'BreakpadVersion',
185+
'BreakpadSendAndExit', 'BreakpadSkipConfirm')
189186

190187

191188
def _TagSuffixes():
192189
# Keep this list sorted in the order that tag suffix components are to
193190
# appear in a tag value. That is to say, it should be sorted per ASCII.
194-
components = ('full',)
191+
components = ('full', )
195192
assert tuple(sorted(components)) == components
196193

197194
components_len = len(components)
@@ -221,10 +218,7 @@ def _AddKeystoneKeys(plist, bundle_identifier):
221218

222219
def _RemoveKeystoneKeys(plist):
223220
"""Removes any set Keystone keys."""
224-
_RemoveKeys(plist,
225-
'KSVersion',
226-
'KSProductID',
227-
'KSUpdateURL')
221+
_RemoveKeys(plist, 'KSVersion', 'KSProductID', 'KSUpdateURL')
228222

229223
tag_keys = []
230224
for tag_suffix in _TagSuffixes():
@@ -234,36 +228,72 @@ def _RemoveKeystoneKeys(plist):
234228

235229
def Main(argv):
236230
parser = optparse.OptionParser('%prog [options]')
237-
parser.add_option('--plist', dest='plist_path', action='store',
238-
type='string', default=None, help='The path of the plist to tweak.')
231+
parser.add_option('--plist',
232+
dest='plist_path',
233+
action='store',
234+
type='string',
235+
default=None,
236+
help='The path of the plist to tweak.')
239237
parser.add_option('--output', dest='plist_output', action='store',
240238
type='string', default=None, help='If specified, the path to output ' + \
241239
'the tweaked plist, rather than overwriting the input.')
242-
parser.add_option('--breakpad', dest='use_breakpad', action='store',
243-
type='int', default=False, help='Enable Breakpad [1 or 0]')
244-
parser.add_option('--breakpad_staging', dest='use_breakpad_staging',
245-
action='store_true', default=False,
240+
parser.add_option('--breakpad',
241+
dest='use_breakpad',
242+
action='store',
243+
type='int',
244+
default=False,
245+
help='Enable Breakpad [1 or 0]')
246+
parser.add_option(
247+
'--breakpad_staging',
248+
dest='use_breakpad_staging',
249+
action='store_true',
250+
default=False,
246251
help='Use staging breakpad to upload reports. Ignored if --breakpad=0.')
247-
parser.add_option('--keystone', dest='use_keystone', action='store',
248-
type='int', default=False, help='Enable Keystone [1 or 0]')
249-
parser.add_option('--scm', dest='add_scm_info', action='store', type='int',
250-
default=True, help='Add SCM metadata [1 or 0]')
251-
parser.add_option('--branding', dest='branding', action='store',
252-
type='string', default=None, help='The branding of the binary')
253-
parser.add_option('--bundle_id', dest='bundle_identifier',
254-
action='store', type='string', default=None,
255-
help='The bundle id of the binary')
256-
parser.add_option('--platform', choices=('ios', 'mac'), default='mac',
257-
help='The target platform of the bundle')
258-
parser.add_option('--version-overrides', action='append',
252+
parser.add_option('--keystone',
253+
dest='use_keystone',
254+
action='store',
255+
type='int',
256+
default=False,
257+
help='Enable Keystone [1 or 0]')
258+
parser.add_option('--scm',
259+
dest='add_scm_info',
260+
action='store',
261+
type='int',
262+
default=True,
263+
help='Add SCM metadata [1 or 0]')
264+
parser.add_option('--branding',
265+
dest='branding',
266+
action='store',
267+
type='string',
268+
default=None,
269+
help='The branding of the binary')
270+
parser.add_option('--bundle_id',
271+
dest='bundle_identifier',
272+
action='store',
273+
type='string',
274+
default=None,
275+
help='The bundle id of the binary')
276+
parser.add_option('--platform',
277+
choices=('ios', 'mac'),
278+
default='mac',
279+
help='The target platform of the bundle')
280+
parser.add_option(
281+
'--version-overrides',
282+
action='append',
259283
help='Key-value pair to override specific component of version '
260-
'like key=value (can be passed multiple time to configure '
261-
'more than one override)')
262-
parser.add_option('--format', choices=('binary1', 'xml1', 'json'),
263-
default='xml1', help='Format to use when writing property list '
264-
'(default: %(default)s)')
265-
parser.add_option('--version', dest='version', action='store', type='string',
266-
default=None, help='The version string [major.minor.build.patch]')
284+
'like key=value (can be passed multiple time to configure '
285+
'more than one override)')
286+
parser.add_option('--format',
287+
choices=('binary1', 'xml1', 'json'),
288+
default='xml1',
289+
help='Format to use when writing property list '
290+
'(default: %(default)s)')
291+
parser.add_option('--version',
292+
dest='version',
293+
action='store',
294+
type='string',
295+
default=None,
296+
help='The version string [major.minor.build.patch]')
267297
(options, args) = parser.parse_args(argv)
268298

269299
if len(args) > 0:
@@ -297,32 +327,33 @@ def Main(argv):
297327

298328
if options.platform == 'mac':
299329
version_format_for_key = {
300-
# Add public version info so "Get Info" works.
301-
'CFBundleShortVersionString': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@',
302-
303-
# Honor the 429496.72.95 limit. The maximum comes from splitting 2^32 - 1
304-
# into 6, 2, 2 digits. The limitation was present in Tiger, but it could
305-
# have been fixed in later OS release, but hasn't been tested (it's easy
306-
# enough to find out with "lsregister -dump).
307-
# http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html
308-
# BUILD will always be an increasing value, so BUILD_PATH gives us
309-
# something unique that meetings what LS wants.
310-
'CFBundleVersion': '@BUILD@.@PATCH@',
330+
# Add public version info so "Get Info" works.
331+
'CFBundleShortVersionString': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@',
332+
333+
# Honor the 429496.72.95 limit. The maximum comes from splitting
334+
# 2^32 - 1 into 6, 2, 2 digits. The limitation was present in Tiger,
335+
# but it could have been fixed in later OS release, but hasn't been
336+
# tested (it's easy enough to find out with "lsregister -dump).
337+
# http://lists.apple.com/archives/carbon-dev/2006/Jun/msg00139.html
338+
# BUILD will always be an increasing value, so BUILD_PATH gives us
339+
# something unique that meetings what LS wants.
340+
'CFBundleVersion': '@BUILD@.@PATCH@',
311341
}
312342
else:
313343
version_format_for_key = {
314-
'CFBundleShortVersionString': '@MAJOR@.@BUILD@.@PATCH@',
315-
'CFBundleVersion': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@'
344+
'CFBundleShortVersionString': '@MAJOR@.@BUILD@.@PATCH@',
345+
'CFBundleVersion': '@MAJOR@.@MINOR@.@BUILD@.@PATCH@'
316346
}
317347

318348
if options.use_breakpad:
319349
version_format_for_key['BreakpadVersion'] = \
320350
'@MAJOR@.@MINOR@.@BUILD@.@PATCH@'
321351

322352
# Insert the product version.
323-
if not _AddVersionKeys(
324-
plist, version_format_for_key, version=options.version,
325-
overrides=overrides):
353+
if not _AddVersionKeys(plist,
354+
version_format_for_key,
355+
version=options.version,
356+
overrides=overrides):
326357
return 2
327358

328359
# Add Breakpad if configured to do so.
@@ -334,7 +365,7 @@ def Main(argv):
334365
# to the platform as known by breakpad.
335366
platform = {'mac': 'Mac', 'ios': 'iOS'}[options.platform]
336367
_AddBreakpadKeys(plist, options.branding, platform,
337-
options.use_breakpad_staging)
368+
options.use_breakpad_staging)
338369
else:
339370
_RemoveBreakpadKeys(plist)
340371

config/apple/OWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
file://build/apple/OWNERS

config/ios/OWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
file://build/config/mac/OWNERS
1+
file://build/apple/OWNERS

config/mac/OWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
1+
file://build/apple/OWNERS

ios/OWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
file://build/apple/OWNERS

mac/OWNERS

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
1+
file://build/apple/OWNERS

0 commit comments

Comments
 (0)