Source code

Revision control

Other Tools

1
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2
# vim: set filetype=python:
3
# This Source Code Form is subject to the terms of the Mozilla Public
4
# License, v. 2.0. If a copy of the MPL was not distributed with this
5
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7
include('util.configure')
8
include('checks.configure')
9
10
# Make `toolkit` available when toolkit/moz.configure is not included.
11
toolkit = dependable(None)
12
# Likewise with `bindgen_config_paths` when
13
# build/moz.configure/bindgen.configure is not included.
14
bindgen_config_paths = dependable(None)
15
16
option(env='DIST', nargs=1, help='DIST directory')
17
18
19
# Do not allow objdir == srcdir builds.
20
# ==============================================================
21
@depends('--help', 'DIST')
22
@imports(_from='__builtin__', _import='open')
23
@imports(_from='os.path', _import='exists')
24
def check_build_environment(help, dist):
25
topobjdir = os.path.realpath(os.path.abspath('.'))
26
topsrcdir = os.path.realpath(os.path.abspath(
27
os.path.join(os.path.dirname(__file__), '..', '..')))
28
29
if dist:
30
dist = normsep(dist[0])
31
else:
32
dist = os.path.join(topobjdir, 'dist')
33
34
result = namespace(
35
topsrcdir=topsrcdir,
36
topobjdir=topobjdir,
37
dist=dist,
38
)
39
40
if help:
41
return result
42
43
# This limitation has mostly to do with GNU make. Since make can't represent
44
# variables with spaces without correct quoting and many paths are used
45
# without proper quoting, using paths with spaces commonly results in
46
# targets or dependencies being treated as multiple paths. This, of course,
47
# undermines the ability for make to perform up-to-date checks and makes
48
# the build system not work very efficiently. In theory, a non-make build
49
# backend will make this limitation go away. But there is likely a long tail
50
# of things that will need fixing due to e.g. lack of proper path quoting.
51
if len(topsrcdir.split()) > 1:
52
die('Source directory cannot be located in a path with spaces: %s' %
53
topsrcdir)
54
if len(topobjdir.split()) > 1:
55
die('Object directory cannot be located in a path with spaces: %s' %
56
topobjdir)
57
58
if topsrcdir == topobjdir:
59
die(' ***\n'
60
' * Building directly in the main source directory is not allowed.\n'
61
' *\n'
62
' * To build, you must run configure from a separate directory\n'
63
' * (referred to as an object directory).\n'
64
' *\n'
65
' * If you are building with a mozconfig, you will need to change your\n'
66
' * mozconfig to point to a different object directory.\n'
67
' ***'
68
)
69
70
# Check for CRLF line endings.
71
with open(os.path.join(topsrcdir, 'configure.py'), 'rb') as fh:
72
data = fh.read()
73
if '\r' in data:
74
die('\n ***\n'
75
' * The source tree appears to have Windows-style line endings.\n'
76
' *\n'
77
' * If using Git, Git is likely configured to use Windows-style\n'
78
' * line endings.\n'
79
' *\n'
80
' * To convert the working copy to UNIX-style line endings, run\n'
81
' * the following:\n'
82
' *\n'
83
' * $ git config core.autocrlf false\n'
84
' * $ git config core.eof lf\n'
85
' * $ git rm --cached -r .\n'
86
' * $ git reset --hard\n'
87
' *\n'
88
' * If not using Git, the tool you used to obtain the source\n'
89
' * code likely converted files to Windows line endings. See\n'
90
' * usage information for that tool for more.\n'
91
' ***')
92
93
# Check for a couple representative files in the source tree
94
conflict_files = [
95
'* %s' % f for f in ('Makefile', 'config/autoconf.mk')
96
if exists(os.path.join(topsrcdir, f))
97
]
98
if conflict_files:
99
die(' ***\n'
100
' * Your source tree contains these files:\n'
101
' %s\n'
102
' * This indicates that you previously built in the source tree.\n'
103
' * A source tree build can confuse the separate objdir build.\n'
104
' *\n'
105
' * To clean up the source tree:\n'
106
' * 1. cd %s\n'
107
' * 2. gmake distclean\n'
108
' ***'
109
% ('\n '.join(conflict_files), topsrcdir)
110
)
111
112
return result
113
114
115
set_config('TOPSRCDIR', check_build_environment.topsrcdir)
116
set_config('TOPOBJDIR', check_build_environment.topobjdir)
117
set_config('MOZ_BUILD_ROOT', check_build_environment.topobjdir)
118
set_config('DIST', check_build_environment.dist)
119
120
add_old_configure_assignment(
121
'_topsrcdir', check_build_environment.topsrcdir)
122
add_old_configure_assignment(
123
'_objdir', check_build_environment.topobjdir)
124
add_old_configure_assignment(
125
'MOZ_BUILD_ROOT', check_build_environment.topobjdir)
126
add_old_configure_assignment(
127
'DIST', check_build_environment.dist)
128
129
option(env='MOZ_AUTOMATION', help='Enable options for automated builds')
130
set_config('MOZ_AUTOMATION', depends_if('MOZ_AUTOMATION')(lambda x: True))
131
132
133
option(env='OLD_CONFIGURE', nargs=1, help='Path to the old configure script')
134
135
option(env='MOZCONFIG', nargs=1, help='Mozconfig location')
136
137
option('--with-external-source-dir', env='EXTERNAL_SOURCE_DIR', nargs=1,
138
help='External directory containing additional build files')
139
140
141
@depends('--with-external-source-dir')
142
def external_source_dir(value):
143
if value:
144
return value[0]
145
146
147
set_config('EXTERNAL_SOURCE_DIR', external_source_dir)
148
add_old_configure_assignment('EXTERNAL_SOURCE_DIR', external_source_dir)
149
150
# Read user mozconfig
151
# ==============================================================
152
# Note: the dependency on --help is only there to always read the mozconfig,
153
# even when --help is passed. Without this dependency, the function wouldn't
154
# be called when --help is passed, and the mozconfig wouldn't be read.
155
156
157
@depends('MOZCONFIG', 'OLD_CONFIGURE',
158
check_build_environment, '--with-external-source-dir',
159
'--help')
160
@imports(_from='mozbuild.mozconfig', _import='MozconfigLoader')
161
def mozconfig(mozconfig, old_configure, build_env,
162
external_source_dir, help):
163
if not old_configure and not help:
164
die('The OLD_CONFIGURE environment variable must be set')
165
166
# Don't read the mozconfig for the js configure (yay backwards
167
# compatibility)
168
# While the long term goal is that js and top-level use the same configure
169
# and the same overall setup, including the possibility to use mozconfigs,
170
# figuring out what we want to do wrt mozconfig vs. command line and
171
# environment variable is not a clear-cut case, and it's more important to
172
# fix the immediate problem mozconfig causes to js developers by
173
# "temporarily" returning to the previous behavior of not loading the
174
# mozconfig for the js configure.
175
# Separately to the immediate problem for js developers, there is also the
176
# need to not load a mozconfig when running js configure as a subconfigure.
177
# Unfortunately, there is no direct way to tell whether the running
178
# configure is the js configure. The indirect way is to look at the
179
# OLD_CONFIGURE path, which points to js/src/old-configure.
180
# I expect we'll have figured things out for mozconfigs well before
181
# old-configure dies.
182
if old_configure and os.path.dirname(os.path.abspath(old_configure[0])).endswith('/js/src'):
183
return {'path': None}
184
185
topsrcdir = build_env.topsrcdir
186
if external_source_dir:
187
topsrcdir = external_source_dir[0]
188
loader = MozconfigLoader(topsrcdir)
189
mozconfig = mozconfig[0] if mozconfig else None
190
mozconfig = loader.find_mozconfig(env={'MOZCONFIG': mozconfig})
191
mozconfig = loader.read_mozconfig(mozconfig)
192
193
return mozconfig
194
195
196
set_config('MOZCONFIG', depends(mozconfig)(lambda m: m['path']))
197
198
199
option(env='PYTHON', nargs=1, help='Python interpreter')
200
201
# Setup python virtualenv
202
# ==============================================================
203
204
205
@depends('PYTHON', check_build_environment, mozconfig, '--help')
206
@imports('os')
207
@imports('sys')
208
@imports('subprocess')
209
@imports(_from='mozbuild.configure.util', _import='LineIO')
210
@imports(_from='mozbuild.virtualenv', _import='VirtualenvManager')
211
@imports(_from='mozbuild.virtualenv', _import='verify_python_version')
212
@imports('distutils.sysconfig')
213
def virtualenv_python(env_python, build_env, mozconfig, help):
214
if help:
215
return
216
217
python = env_python[0] if env_python else None
218
219
# Ideally we'd rely on the mozconfig injection from mozconfig_options,
220
# but we'd rather avoid the verbosity when we need to reexecute with
221
# a different python.
222
if mozconfig['path']:
223
if 'PYTHON' in mozconfig['env']['added']:
224
python = mozconfig['env']['added']['PYTHON']
225
elif 'PYTHON' in mozconfig['env']['modified']:
226
python = mozconfig['env']['modified']['PYTHON'][1]
227
elif 'PYTHON' in mozconfig['vars']['added']:
228
python = mozconfig['vars']['added']['PYTHON']
229
elif 'PYTHON' in mozconfig['vars']['modified']:
230
python = mozconfig['vars']['modified']['PYTHON'][1]
231
232
with LineIO(lambda l: log.error(l)) as out:
233
verify_python_version(out)
234
topsrcdir, topobjdir = build_env.topsrcdir, build_env.topobjdir
235
if topobjdir.endswith('/js/src'):
236
topobjdir = topobjdir[:-7]
237
238
virtualenvs_root = os.path.join(topobjdir, '_virtualenvs')
239
with LineIO(lambda l: log.info(l), 'replace') as out:
240
manager = VirtualenvManager(
241
topsrcdir, topobjdir,
242
os.path.join(virtualenvs_root, 'init'), out,
243
os.path.join(topsrcdir, 'build', 'virtualenv_packages.txt'))
244
245
if python:
246
# If we're not in the virtualenv, we need the which module for
247
# find_program.
248
if normsep(sys.executable) != normsep(manager.python_path):
249
sys.path.append(os.path.join(
250
topsrcdir, 'third_party', 'python', 'which'))
251
found_python = find_program(python)
252
if not found_python:
253
die('The PYTHON environment variable does not contain '
254
'a valid path. Cannot find %s', python)
255
python = found_python
256
else:
257
python = sys.executable
258
259
if not manager.up_to_date(python):
260
log.info('Creating Python environment')
261
manager.build(python)
262
263
python = normsep(manager.python_path)
264
265
if not normsep(sys.executable).startswith(normsep(virtualenvs_root)):
266
log.info('Reexecuting in the virtualenv')
267
if env_python:
268
del os.environ['PYTHON']
269
# One would prefer to use os.execl, but that's completely borked on
270
# Windows.
271
sys.exit(subprocess.call([python] + sys.argv))
272
273
# We are now in the virtualenv
274
if not distutils.sysconfig.get_python_lib():
275
die('Could not determine python site packages directory')
276
277
return python
278
279
280
set_config('PYTHON', virtualenv_python)
281
add_old_configure_assignment('PYTHON', virtualenv_python)
282
283
# Inject mozconfig options
284
# ==============================================================
285
# All options defined above this point can't be injected in mozconfig_options
286
# below, so collect them.
287
288
289
@template
290
def early_options():
291
@dependable
292
@imports('__sandbox__')
293
def early_options():
294
return set(
295
option.env
296
for option in __sandbox__._options.itervalues()
297
if option.env
298
)
299
return early_options
300
301
302
early_options = early_options()
303
304
305
@depends(mozconfig, 'MOZ_AUTOMATION', '--help')
306
# This gives access to the sandbox. Don't copy this blindly.
307
@imports('__sandbox__')
308
@imports('os')
309
@imports('six')
310
def mozconfig_options(mozconfig, automation, help):
311
if mozconfig['path']:
312
if 'MOZ_AUTOMATION_MOZCONFIG' in mozconfig['env']['added']:
313
if not automation:
314
log.error('%s directly or indirectly includes an in-tree '
315
'mozconfig.', mozconfig['path'])
316
log.error('In-tree mozconfigs make strong assumptions about '
317
'and are only meant to be used by Mozilla '
318
'automation.')
319
die("Please don't use them.")
320
helper = __sandbox__._helper
321
log.info('Adding configure options from %s' % mozconfig['path'])
322
for arg in mozconfig['configure_args']:
323
log.info(' %s' % arg)
324
# We could be using imply_option() here, but it has other
325
# contraints that don't really apply to the command-line
326
# emulation that mozconfig provides.
327
helper.add(arg, origin='mozconfig', args=helper._args)
328
329
def add(key, value):
330
if key.isupper():
331
arg = '%s=%s' % (key, value)
332
log.info(' %s' % arg)
333
helper.add(arg, origin='mozconfig', args=helper._args)
334
335
for key, value in six.iteritems(mozconfig['env']['added']):
336
add(key, value)
337
os.environ[key] = value
338
for key, (_, value) in six.iteritems(mozconfig['env']['modified']):
339
add(key, value)
340
os.environ[key] = value
341
for key, value in six.iteritems(mozconfig['vars']['added']):
342
add(key, value)
343
for key, (_, value) in six.iteritems(mozconfig['vars']['modified']):
344
add(key, value)
345
346
347
# Mozilla-Build
348
# ==============================================================
349
option(env='MOZILLABUILD', nargs=1,
350
help='Path to Mozilla Build (Windows-only)')
351
352
option(env='CONFIG_SHELL', nargs=1, help='Path to a POSIX shell')
353
354
# It feels dirty replicating this from python/mozbuild/mozbuild/mozconfig.py,
355
# but the end goal being that the configure script would go away...
356
357
358
@depends('CONFIG_SHELL', 'MOZILLABUILD')
359
@checking('for a shell')
360
@imports('sys')
361
def shell(value, mozillabuild):
362
if value:
363
return find_program(value[0])
364
shell = 'sh'
365
if mozillabuild:
366
shell = mozillabuild[0] + '/msys/bin/sh'
367
if sys.platform == 'win32':
368
shell = shell + '.exe'
369
return find_program(shell)
370
371
372
# This defines a reasonable shell for when running with --help.
373
# If one was passed in the environment, though, fall back to that.
374
@depends('--help', 'CONFIG_SHELL')
375
def help_shell(help, shell):
376
if help and not shell:
377
return 'sh'
378
379
380
shell = help_shell | shell
381
382
383
# Python 3
384
# ========
385
386
option(env='PYTHON3', nargs=1, help='Python 3 interpreter (3.5 or later)')
387
388
389
@depends('PYTHON3', 'MOZILLABUILD')
390
@checking('for Python 3',
391
callback=lambda x: '%s (%s)' % (x.path, x.str_version) if x else 'no')
392
@imports(_from='__builtin__', _import='Exception')
393
@imports(_from='mozbuild.pythonutil', _import='find_python3_executable')
394
@imports(_from='mozbuild.pythonutil', _import='python_executable_version')
395
def python3(env_python, mozillabuild):
396
python = env_python[0] if env_python else None
397
398
# If Python given by environment variable, it must work.
399
if python:
400
try:
401
version = python_executable_version(python).version
402
except Exception as e:
403
raise FatalCheckError('could not determine version of PYTHON '
404
'(%s): %s' % (python, e))
405
elif mozillabuild:
406
# MozillaBuild provides a Python 3.
407
python = normsep('%s/python3/python3.exe' % mozillabuild)
408
409
try:
410
version = python_executable_version(python).version
411
except Exception as e:
412
raise FatalCheckError('could not determine version of '
413
'MozillaBuild python: %s' % e)
414
else:
415
# Fall back to the search routine.
416
python, version = find_python3_executable(min_version='3.5.0')
417
418
# The API returns a bytes whereas everything in configure is unicode.
419
if python:
420
python = python.decode('utf-8')
421
422
if not python:
423
raise FatalCheckError('Python 3.5 or newer is required to build. '
424
'Ensure a `python3.x` executable is in your '
425
'PATH or define PYTHON3 to point to a Python '
426
'3.5 executable.')
427
428
if version < (3, 5, 0):
429
raise FatalCheckError('Python 3.5 or newer is required to build; '
430
'%s is Python %d.%d' % (python, version[0],
431
version[1]))
432
433
return namespace(
434
path=python,
435
version=version,
436
str_version='.'.join(str(v) for v in version),
437
)
438
439
440
set_config('PYTHON3', depends_if(python3)(lambda p: p.path))
441
set_config('PYTHON3_VERSION', depends_if(python3)(lambda p: p.str_version))
442
443
# Source checkout and version control integration.
444
# ================================================
445
446
447
@depends(check_build_environment, 'MOZ_AUTOMATION', '--help')
448
@checking('for vcs source checkout')
449
@imports('os')
450
def vcs_checkout_type(build_env, automation, help):
451
if os.path.exists(os.path.join(build_env.topsrcdir, '.hg')):
452
return 'hg'
453
elif os.path.exists(os.path.join(build_env.topsrcdir, '.git')):
454
return 'git'
455
elif automation and not help:
456
raise FatalCheckError('unable to resolve VCS type; must run '
457
'from a source checkout when MOZ_AUTOMATION '
458
'is set')
459
460
# Resolve VCS binary for detected repository type.
461
462
463
# TODO remove hg.exe once bug 1382940 addresses ambiguous executables case.
464
hg = check_prog('HG', ('hg.exe', 'hg',), allow_missing=True,
465
when=depends(vcs_checkout_type)(lambda x: x == 'hg'))
466
git = check_prog('GIT', ('git',), allow_missing=True,
467
when=depends(vcs_checkout_type)(lambda x: x == 'git'))
468
469
470
@depends_if(hg)
471
@checking('for Mercurial version')
472
@imports('os')
473
@imports('re')
474
def hg_version(hg):
475
# HGPLAIN in Mercurial 1.5+ forces stable output, regardless of set
476
# locale or encoding.
477
env = dict(os.environ)
478
env['HGPLAIN'] = '1'
479
480
out = check_cmd_output(hg, '--version', env=env)
481
482
match = re.search(r'Mercurial Distributed SCM \(version ([^\)]+)', out)
483
484
if not match:
485
raise FatalCheckError(
486
'unable to determine Mercurial version: %s' % out)
487
488
# The version string may be "unknown" for Mercurial run out of its own
489
# source checkout or for bad builds. But LooseVersion handles it.
490
491
return Version(match.group(1))
492
493
# Resolve Mercurial config items so other checks have easy access.
494
# Do NOT set this in the config because it may contain sensitive data
495
# like API keys.
496
497
498
@depends_all(check_build_environment, hg, hg_version)
499
@imports('os')
500
def hg_config(build_env, hg, version):
501
env = dict(os.environ)
502
env['HGPLAIN'] = '1'
503
504
# Warnings may get sent to stderr. But check_cmd_output() ignores
505
# stderr if exit code is 0. And the command should always succeed if
506
# `hg version` worked.
507
out = check_cmd_output(hg, 'config', env=env, cwd=build_env.topsrcdir)
508
509
config = {}
510
511
for line in out.strip().splitlines():
512
key, value = [s.strip() for s in line.split('=', 1)]
513
config[key] = value
514
515
return config
516
517
518
@depends_if(git)
519
@checking('for Git version')
520
@imports('re')
521
def git_version(git):
522
out = check_cmd_output(git, '--version').rstrip()
523
524
match = re.search('git version (.*)$', out)
525
526
if not match:
527
raise FatalCheckError('unable to determine Git version: %s' % out)
528
529
return Version(match.group(1))
530
531
# Only set VCS_CHECKOUT_TYPE if we resolved the VCS binary.
532
# Require resolved VCS info when running in automation so automation's
533
# environment is more well-defined.
534
535
536
@depends(vcs_checkout_type, hg_version, git_version, 'MOZ_AUTOMATION')
537
def exposed_vcs_checkout_type(vcs_checkout_type, hg, git, automation):
538
if vcs_checkout_type == 'hg':
539
if hg:
540
return 'hg'
541
542
if automation:
543
raise FatalCheckError('could not resolve Mercurial binary info')
544
545
elif vcs_checkout_type == 'git':
546
if git:
547
return 'git'
548
549
if automation:
550
raise FatalCheckError('could not resolve Git binary info')
551
elif vcs_checkout_type:
552
raise FatalCheckError('unhandled VCS type: %s' % vcs_checkout_type)
553
554
555
set_config('VCS_CHECKOUT_TYPE', exposed_vcs_checkout_type)
556
557
# Obtain a Repository interface for the current VCS repository.
558
559
560
@depends(check_build_environment, exposed_vcs_checkout_type, hg, git)
561
@imports(_from='mozversioncontrol', _import='get_repository_object')
562
def vcs_repository(build_env, vcs_checkout_type, hg, git):
563
if vcs_checkout_type == 'hg':
564
return get_repository_object(build_env.topsrcdir, hg=hg)
565
elif vcs_checkout_type == 'git':
566
return get_repository_object(build_env.topsrcdir, git=git)
567
elif vcs_checkout_type:
568
raise FatalCheckError('unhandled VCS type: %s' % vcs_checkout_type)
569
570
571
@depends_if(vcs_repository)
572
@checking('for sparse checkout')
573
def vcs_sparse_checkout(repo):
574
return repo.sparse_checkout_present()
575
576
577
set_config('VCS_SPARSE_CHECKOUT', vcs_sparse_checkout)
578
579
# The application/project to build
580
# ==============================================================
581
option('--enable-application', nargs=1, env='MOZ_BUILD_APP',
582
help='Application to build. Same as --enable-project.')
583
584
585
@depends('--enable-application')
586
def application(app):
587
if app:
588
return app
589
590
591
imply_option('--enable-project', application)
592
593
594
@depends(check_build_environment)
595
def default_project(build_env):
596
if build_env.topobjdir.endswith('/js/src'):
597
return 'js'
598
return 'browser'
599
600
601
option('--enable-project', nargs=1, default=default_project,
602
help='Project to build')
603
604
605
# Host and target systems
606
# ==============================================================
607
option('--host', nargs=1, help='Define the system type performing the build')
608
609
option('--target', nargs=1,
610
help='Define the system type where the resulting executables will be '
611
'used')
612
613
614
@imports(_from='mozbuild.configure.constants', _import='CPU')
615
@imports(_from='mozbuild.configure.constants', _import='CPU_bitness')
616
@imports(_from='mozbuild.configure.constants', _import='Endianness')
617
@imports(_from='mozbuild.configure.constants', _import='Kernel')
618
@imports(_from='mozbuild.configure.constants', _import='OS')
619
@imports(_from='__builtin__', _import='ValueError')
620
def split_triplet(triplet):
621
# The standard triplet is defined as
622
# CPU_TYPE-VENDOR-OPERATING_SYSTEM
623
# There is also a quartet form:
624
# CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
625
# But we can consider the "KERNEL-OPERATING_SYSTEM" as one.
626
# Additionally, some may omit "unknown" when the vendor
627
# is not specified and emit
628
# CPU_TYPE-OPERATING_SYSTEM
629
vendor = 'unknown'
630
parts = triplet.split('-', 2)
631
if len(parts) == 3:
632
cpu, vendor, os = parts
633
elif len(parts) == 2:
634
cpu, os = parts
635
else:
636
raise ValueError("Unexpected triplet string: %s" % triplet)
637
638
# Autoconf uses config.sub to validate and canonicalize those triplets,
639
# but the granularity of its results has never been satisfying to our
640
# use, so we've had our own, different, canonicalization. We've also
641
# historically not been very consistent with how we use the canonicalized
642
# values. Hopefully, this will help us make things better.
643
# The tests are inherited from our decades-old autoconf-based configure,
644
# which can probably be improved/cleaned up because they are based on a
645
# mix of uname and config.guess output, while we now only use the latter,
646
# which presumably has a cleaner and leaner output. Let's refine later.
647
os = os.replace('/', '_')
648
if 'android' in os:
649
canonical_os = 'Android'
650
canonical_kernel = 'Linux'
651
elif os.startswith('linux'):
652
canonical_os = 'GNU'
653
canonical_kernel = 'Linux'
654
elif os.startswith('kfreebsd') and os.endswith('-gnu'):
655
canonical_os = 'GNU'
656
canonical_kernel = 'kFreeBSD'
657
elif os.startswith('gnu'):
658
canonical_os = canonical_kernel = 'GNU'
659
elif os.startswith('mingw'):
660
canonical_os = canonical_kernel = 'WINNT'
661
elif os.startswith('darwin'):
662
canonical_kernel = 'Darwin'
663
canonical_os = 'OSX'
664
elif os.startswith('ios'):
665
canonical_kernel = 'Darwin'
666
canonical_os = 'iOS'
667
elif os.startswith('dragonfly'):
668
canonical_os = canonical_kernel = 'DragonFly'
669
elif os.startswith('freebsd'):
670
canonical_os = canonical_kernel = 'FreeBSD'
671
elif os.startswith('netbsd'):
672
canonical_os = canonical_kernel = 'NetBSD'
673
elif os.startswith('openbsd'):
674
canonical_os = canonical_kernel = 'OpenBSD'
675
elif os.startswith('solaris'):
676
canonical_os = canonical_kernel = 'SunOS'
677
else:
678
raise ValueError('Unknown OS: %s' % os)
679
680
# The CPU granularity is probably not enough. Moving more things from
681
# old-configure will tell us if we need more
682
if cpu.endswith('86') or (cpu.startswith('i') and '86' in cpu):
683
canonical_cpu = 'x86'
684
endianness = 'little'
685
elif cpu in ('x86_64', 'ia64'):
686
canonical_cpu = cpu
687
endianness = 'little'
688
elif cpu in ('s390', 's390x'):
689
canonical_cpu = cpu
690
endianness = 'big'
691
elif cpu in ('powerpc64', 'ppc64', 'powerpc64le', 'ppc64le'):
692
canonical_cpu = 'ppc64'
693
endianness = 'little' if 'le' in cpu else 'big'
694
elif cpu in ('powerpc', 'ppc', 'rs6000') or cpu.startswith('powerpc'):
695
canonical_cpu = 'ppc'
696
endianness = 'big'
697
elif cpu in ('Alpha', 'alpha', 'ALPHA'):
698
canonical_cpu = 'Alpha'
699
endianness = 'little'
700
elif cpu.startswith('hppa') or cpu == 'parisc':
701
canonical_cpu = 'hppa'
702
endianness = 'big'
703
elif cpu.startswith('sparc64') or cpu.startswith('sparcv9'):
704
canonical_cpu = 'sparc64'
705
endianness = 'big'
706
elif cpu.startswith('sparc') or cpu == 'sun4u':
707
canonical_cpu = 'sparc'
708
endianness = 'big'
709
elif cpu.startswith('arm'):
710
canonical_cpu = 'arm'
711
endianness = 'big' if cpu.startswith(('armeb', 'armbe')) else 'little'
712
elif cpu in ('mips', 'mipsel'):
713
canonical_cpu = 'mips32'
714
endianness = 'little' if 'el' in cpu else 'big'
715
elif cpu in ('mips64', 'mips64el'):
716
canonical_cpu = 'mips64'
717
endianness = 'little' if 'el' in cpu else 'big'
718
elif cpu.startswith('aarch64'):
719
canonical_cpu = 'aarch64'
720
endianness = 'little'
721
elif cpu == 'sh4':
722
canonical_cpu = 'sh4'
723
endianness = 'little'
724
else:
725
raise ValueError('Unknown CPU type: %s' % cpu)
726
727
# Toolchains, most notably for cross compilation may use cpu-os
728
# prefixes. We need to be more specific about the LLVM target on Mac
729
# so cross-language LTO will work correctly.
730
731
if os.startswith('darwin'):
732
toolchain = '%s-apple-%s' % (cpu, os)
733
elif canonical_cpu == 'aarch64' and canonical_os == 'WINNT':
734
toolchain = 'aarch64-windows-msvc'
735
else:
736
toolchain = '%s-%s' % (cpu, os)
737
738
return namespace(
739
alias=triplet,
740
cpu=CPU(canonical_cpu),
741
bitness=CPU_bitness[canonical_cpu],
742
kernel=Kernel(canonical_kernel),
743
os=OS(canonical_os),
744
endianness=Endianness(endianness),
745
raw_cpu=cpu,
746
raw_os=os,
747
toolchain=toolchain,
748
vendor=vendor,
749
)
750
751
752
# This defines a fake target/host namespace for when running with --help
753
# If either --host or --target is passed on the command line, then fall
754
# back to the real deal.
755
@depends('--help', '--host', '--target')
756
def help_host_target(help, host, target):
757
if help and not host and not target:
758
return namespace(
759
alias='unknown-unknown-unknown',
760
cpu='unknown',
761
bitness='unknown',
762
kernel='unknown',
763
os='unknown',
764
endianness='unknown',
765
raw_cpu='unknown',
766
raw_os='unknown',
767
toolchain='unknown-unknown',
768
)
769
770
771
def config_sub(shell, triplet):
772
config_sub = os.path.join(os.path.dirname(__file__), '..',
773
'autoconf', 'config.sub')
774
return check_cmd_output(shell, config_sub, triplet).strip()
775
776
777
@depends('--host', shell)
778
@checking('for host system type', lambda h: h.alias)
779
@imports('os')
780
@imports('sys')
781
@imports(_from='__builtin__', _import='ValueError')
782
def real_host(value, shell):
783
if not value and sys.platform == 'win32':
784
arch = (os.environ.get('PROCESSOR_ARCHITEW6432') or
785
os.environ.get('PROCESSOR_ARCHITECTURE'))
786
if arch == 'AMD64':
787
return split_triplet('x86_64-pc-mingw32')
788
elif arch == 'x86':
789
return split_triplet('i686-pc-mingw32')
790
791
if not value:
792
config_guess = os.path.join(os.path.dirname(__file__), '..',
793
'autoconf', 'config.guess')
794
host = check_cmd_output(shell, config_guess).strip()
795
try:
796
return split_triplet(host)
797
except ValueError:
798
pass
799
else:
800
host = value[0]
801
802
host = config_sub(shell, host)
803
804
try:
805
return split_triplet(host)
806
except ValueError as e:
807
die(e.message)
808
809
810
host = help_host_target | real_host
811
812
813
@depends('--target', real_host, shell, '--enable-project', '--enable-application')
814
@checking('for target system type', lambda t: t.alias)
815
@imports(_from='__builtin__', _import='ValueError')
816
def real_target(value, host, shell, project, application):
817
# Because --enable-project is implied by --enable-application, and
818
# implied options are not currently handled during --help, which is
819
# used get the build target in mozbuild.base, we manually check
820
# whether --enable-application was given, and fall back to
821
# --enable-project if not. Both can't be given contradictory values
822
# under normal circumstances, so it's fine.
823
if application:
824
project = application[0]
825
elif project:
826
project = project[0]
827
if not value:
828
if project == 'mobile/android':
829
return split_triplet('arm-unknown-linux-androideabi')
830
return host
831
# If --target was only given a cpu arch, expand it with the
832
# non-cpu part of the host. For mobile/android, expand it with
833
# unknown-linux-android.
834
target = value[0]
835
if '-' not in target:
836
if project == 'mobile/android':
837
rest = 'unknown-linux-android'
838
if target.startswith('arm'):
839
rest += 'eabi'
840
else:
841
cpu, rest = host.alias.split('-', 1)
842
target = '-'.join((target, rest))
843
try:
844
return split_triplet(target)
845
except ValueError:
846
pass
847
848
try:
849
return split_triplet(config_sub(shell, target))
850
except ValueError as e:
851
die(e.message)
852
853
854
target = help_host_target | real_target
855
856
857
@depends(host, target)
858
@checking('whether cross compiling')
859
def cross_compiling(host, target):
860
return host != target
861
862
863
set_config('CROSS_COMPILE', cross_compiling)
864
set_define('CROSS_COMPILE', cross_compiling)
865
add_old_configure_assignment('CROSS_COMPILE', cross_compiling)
866
867
868
@depends(target)
869
def have_64_bit(target):
870
if target.bitness == 64:
871
return True
872
873
874
set_config('HAVE_64BIT_BUILD', have_64_bit)
875
set_define('HAVE_64BIT_BUILD', have_64_bit)
876
add_old_configure_assignment('HAVE_64BIT_BUILD', have_64_bit)
877
878
879
@depends(host)
880
def host_os_kernel_major_version(host):
881
versions = host.raw_os.split('.')
882
version = ''.join(x for x in versions[0] if x.isdigit())
883
return version
884
885
886
set_config('HOST_MAJOR_VERSION', host_os_kernel_major_version)
887
888
# Autoconf needs these set
889
890
891
@depends(host)
892
def host_for_old_configure(host):
893
return '--host=%s' % host.alias
894
895
896
add_old_configure_arg(host_for_old_configure)
897
898
899
@depends(target)
900
def target_for_old_configure(target):
901
target_alias = target.alias
902
# old-configure does plenty of tests against $target and $target_os
903
# and expects darwin for iOS, so make it happy.
904
if target.os == 'iOS':
905
target_alias = target_alias.replace('-ios', '-darwin')
906
return '--target=%s' % target_alias
907
908
909
add_old_configure_arg(target_for_old_configure)
910
911
912
# These variables are for compatibility with the current moz.builds and
913
# old-configure. Eventually, we'll want to canonicalize better.
914
@depends(target)
915
def target_variables(target):
916
if target.kernel == 'kFreeBSD':
917
os_target = 'GNU/kFreeBSD'
918
os_arch = 'GNU_kFreeBSD'
919
elif target.kernel == 'Darwin' or (target.kernel == 'Linux' and
920
target.os == 'GNU'):
921
os_target = target.kernel
922
os_arch = target.kernel
923
else:
924
os_target = target.os
925
os_arch = target.kernel
926
927
return namespace(
928
OS_TARGET=os_target,
929
OS_ARCH=os_arch,
930
INTEL_ARCHITECTURE=target.cpu in ('x86', 'x86_64') or None,
931
)
932
933
934
set_config('OS_TARGET', target_variables.OS_TARGET)
935
add_old_configure_assignment('OS_TARGET',
936
target_variables.OS_TARGET)
937
set_config('OS_ARCH', target_variables.OS_ARCH)
938
add_old_configure_assignment('OS_ARCH',
939
target_variables.OS_ARCH)
940
set_config('CPU_ARCH', target.cpu)
941
add_old_configure_assignment('CPU_ARCH', target.cpu)
942
set_config('INTEL_ARCHITECTURE', target_variables.INTEL_ARCHITECTURE)
943
set_config('TARGET_CPU', target.raw_cpu)
944
set_config('TARGET_OS', target.raw_os)
945
set_config('TARGET_ENDIANNESS', target.endianness)
946
947
948
@depends(host)
949
def host_variables(host):
950
if host.kernel == 'kFreeBSD':
951
os_arch = 'GNU_kFreeBSD'
952
else:
953
os_arch = host.kernel
954
return namespace(
955
HOST_OS_ARCH=os_arch,
956
)
957
958
959
set_config('HOST_CPU_ARCH', host.cpu)
960
set_config('HOST_OS_ARCH', host_variables.HOST_OS_ARCH)
961
add_old_configure_assignment('HOST_OS_ARCH',
962
host_variables.HOST_OS_ARCH)
963
964
965
@depends(target)
966
def target_is_windows(target):
967
if target.kernel == 'WINNT':
968
return True
969
970
971
set_define('_WINDOWS', target_is_windows)
972
set_define('WIN32', target_is_windows)
973
set_define('XP_WIN', target_is_windows)
974
975
976
@depends(target)
977
def target_is_unix(target):
978
if target.kernel != 'WINNT':
979
return True
980
981
982
set_define('XP_UNIX', target_is_unix)
983
984
985
@depends(target)
986
def target_is_darwin(target):
987
if target.kernel == 'Darwin':
988
return True
989
990
991
set_define('XP_DARWIN', target_is_darwin)
992
993
994
@depends(target)
995
def target_is_ios(target):
996
if target.kernel == 'Darwin' and target.os == 'iOS':
997
return True
998
999
1000
set_define('XP_IOS', target_is_ios)
1001
1002
1003
@depends(target)
1004
def target_is_osx(target):
1005
if target.kernel == 'Darwin' and target.os == 'OSX':
1006
return True
1007
1008
1009
set_define('XP_MACOSX', target_is_osx)
1010
1011
1012
@depends(target)
1013
def target_is_linux(target):
1014
if target.kernel == 'Linux':
1015
return True
1016
1017
1018
set_define('XP_LINUX', target_is_linux)
1019
1020
1021
@depends(target)
1022
def target_is_android(target):
1023
if target.os == 'Android':
1024
return True
1025
1026
1027
set_define('ANDROID', target_is_android)
1028
1029
1030
@depends(target)
1031
def target_is_openbsd(target):
1032
if target.kernel == 'OpenBSD':
1033
return True
1034
1035
1036
set_define('XP_OPENBSD', target_is_openbsd)
1037
1038
@depends(target)
1039
def target_is_netbsd(target):
1040
if target.kernel == 'NetBSD':
1041
return True
1042
1043
1044
set_define('XP_NETBSD', target_is_netbsd)
1045
1046
@depends(target)
1047
def target_is_freebsd(target):
1048
if target.kernel == 'FreeBSD':
1049
return True
1050
1051
1052
set_define('XP_FREEBSD', target_is_freebsd)
1053
1054
@depends(target)
1055
def target_is_solaris(target):
1056
if target.kernel == 'SunOS':
1057
return True
1058
1059
1060
set_define('XP_SOLARIS', target_is_solaris)
1061
1062
1063
@depends(target)
1064
def target_is_sparc(target):
1065
if target.cpu == 'sparc64':
1066
return True
1067
1068
set_define('SPARC64', target_is_sparc)
1069
1070
1071
@depends('--enable-project', '--with-external-source-dir',
1072
check_build_environment, '--help')
1073
@imports(_from='os.path', _import='exists')
1074
def include_project_configure(project, external_source_dir, build_env, help):
1075
if not project:
1076
die('--enable-project is required.')
1077
1078
base_dir = build_env.topsrcdir
1079
if external_source_dir:
1080
base_dir = os.path.join(base_dir, external_source_dir[0])
1081
1082
path = os.path.join(base_dir, project[0], 'moz.configure')
1083
if not exists(path):
1084
die('Cannot find project %s', project[0])
1085
return path
1086
1087
1088
@depends(include_project_configure, check_build_environment)
1089
def build_project(include_project_configure, build_env):
1090
ret = os.path.dirname(os.path.relpath(include_project_configure,
1091
build_env.topsrcdir))
1092
return ret
1093
1094
1095
set_config('MOZ_BUILD_APP', build_project)
1096
set_define('MOZ_BUILD_APP', build_project)
1097
add_old_configure_assignment('MOZ_BUILD_APP', build_project)
1098
1099
1100
# This is temporary until js/src/configure and configure are merged.
1101
# Use instead of option() in js/moz.configure and more generally, for
1102
# options that are shared between configure and js/src/configure.
1103
@template
1104
def js_option(*args, **kwargs):
1105
opt = option(*args, **kwargs)
1106
1107
@depends(opt.option, build_project, when=kwargs.get('when'))
1108
def js_option(value, build_project):
1109
if build_project != 'js':
1110
return value.format(opt.option)
1111
1112
add_old_configure_arg(js_option)
1113
1114
1115
js_option(env='MOZILLA_OFFICIAL',
1116
help='Build an official release')
1117
1118
1119
@depends('MOZILLA_OFFICIAL')
1120
def mozilla_official(official):
1121
if official:
1122
return True
1123
1124
1125
set_config('MOZILLA_OFFICIAL', mozilla_official)
1126
set_define('MOZILLA_OFFICIAL', mozilla_official)
1127
add_old_configure_assignment('MOZILLA_OFFICIAL', mozilla_official)
1128
1129
1130
# Allow specifying custom paths to the version files used by the milestone() function below.
1131
option('--with-version-file-path',
1132
nargs=1,
1133
help='Specify a custom path to app version files instead of auto-detecting',
1134
default=None)
1135
1136
@depends('--with-version-file-path')
1137
def version_path(path):
1138
return path
1139
1140
# set RELEASE_OR_BETA and NIGHTLY_BUILD variables depending on the cycle we're in
1141
# The logic works like this:
1142
# - if we have "a1" in GRE_MILESTONE, we're building Nightly (define NIGHTLY_BUILD)
1143
# - otherwise, if we have "a" in GRE_MILESTONE, we're building Nightly or Aurora
1144
# - otherwise, we're building Release/Beta (define RELEASE_OR_BETA)
1145
@depends(check_build_environment, build_project, version_path, '--help')
1146
@imports(_from='__builtin__', _import='open')
1147
@imports('os')
1148
@imports('re')
1149
def milestone(build_env, build_project, version_path, _):
1150
versions = []
1151
paths = ['config/milestone.txt']
1152
if build_project == 'js':
1153
paths = paths * 3
1154
else:
1155
paths += [
1156
'browser/config/version.txt',
1157
'browser/config/version_display.txt',
1158
]
1159
if version_path:
1160
version_path = version_path[0]
1161
else:
1162
version_path = os.path.join(build_project, 'config')
1163
for f in ('version.txt', 'version_display.txt'):
1164
f = os.path.join(version_path, f)
1165
if not os.path.exists(os.path.join(build_env.topsrcdir, f)):
1166
break
1167
paths.append(f)
1168
1169
for p in paths:
1170
with open(os.path.join(build_env.topsrcdir, p), 'r') as fh:
1171
content = fh.read().splitlines()
1172
if not content:
1173
die('Could not find a version number in {}'.format(p))
1174
versions.append(content[-1])
1175
1176
milestone, firefox_version, firefox_version_display = versions[:3]
1177
1178
# version.txt content from the project directory if there is one, otherwise
1179
# the firefox version.
1180
app_version = versions[3] if len(versions) > 3 else firefox_version
1181
# version_display.txt content from the project directory if there is one,
1182
# otherwise version.txt content from the project directory, otherwise the
1183
# firefox version for display.
1184
app_version_display = versions[-1] if len(versions) > 3 else firefox_version_display
1185
1186
is_nightly = is_release_or_beta = None
1187
1188
if 'a1' in milestone:
1189
is_nightly = True
1190
elif 'a' not in milestone:
1191
is_release_or_beta = True
1192
1193
major_version = milestone.split('.')[0]
1194
m = re.search(r"([ab]\d+)", milestone)
1195
ab_patch = m.group(1) if m else ''
1196
1197
# Only expose the major version milestone in the UA string and hide the
1198
# patch leve (bugs 572659 and 870868).
1199
#
1200
# Only expose major milestone and alpha version in the symbolversion
1201
# string; as the name suggests, we use it for symbol versioning on Linux.
1202
return namespace(version=milestone,
1203
uaversion='%s.0' % major_version,
1204
symbolversion='%s%s' % (major_version, ab_patch),
1205
is_nightly=is_nightly,
1206
is_release_or_beta=is_release_or_beta,
1207
app_version=app_version,
1208
app_version_display=app_version_display)
1209
1210
1211
set_config('GRE_MILESTONE', milestone.version)
1212
set_config('NIGHTLY_BUILD', milestone.is_nightly)
1213
set_define('NIGHTLY_BUILD', milestone.is_nightly)
1214
set_config('RELEASE_OR_BETA', milestone.is_release_or_beta)
1215
set_define('RELEASE_OR_BETA', milestone.is_release_or_beta)
1216
add_old_configure_assignment('RELEASE_OR_BETA',
1217
milestone.is_release_or_beta)
1218
set_define('MOZILLA_VERSION', depends(milestone)(lambda m: '"%s"' % m.version))
1219
set_config('MOZILLA_VERSION', milestone.version)
1220
set_define('MOZILLA_VERSION_U', milestone.version)
1221
set_define('MOZILLA_UAVERSION', depends(milestone)(lambda m: '"%s"' % m.uaversion))
1222
set_config('MOZILLA_SYMBOLVERSION', milestone.symbolversion)
1223
# JS configure still wants to look at these.
1224
add_old_configure_assignment('MOZILLA_VERSION', milestone.version)
1225
add_old_configure_assignment('MOZILLA_SYMBOLVERSION', milestone.symbolversion)
1226
1227
set_config('MOZ_APP_VERSION', milestone.app_version)
1228
set_config('MOZ_APP_VERSION_DISPLAY', milestone.app_version_display)
1229
add_old_configure_assignment('MOZ_APP_VERSION', milestone.app_version)
1230
1231
1232
# Dummy function for availability in toolkit/moz.configure. Overridden in
1233
# mobile/android/moz.configure.
1234
@depends(milestone.is_nightly)
1235
def fennec_nightly(is_nightly):
1236
return is_nightly
1237
1238
1239
# The app update channel is 'default' when not supplied. The value is used in
1240
# the application's confvars.sh (and is made available to a project specific
1241
# moz.configure).
1242
option('--enable-update-channel',
1243
nargs=1,
1244
help='Select application update channel',
1245
default='default')
1246
1247
1248
@depends('--enable-update-channel')
1249
def update_channel(channel):
1250
if channel[0] == '':
1251
return 'default'
1252
return channel[0].lower()
1253
1254
1255
set_config('MOZ_UPDATE_CHANNEL', update_channel)
1256
set_define('MOZ_UPDATE_CHANNEL', update_channel)
1257
add_old_configure_assignment('MOZ_UPDATE_CHANNEL', update_channel)
1258
1259
1260
js_option(env='MOZBUILD_STATE_PATH', nargs=1,
1261
help='Path to a persistent state directory for the build system '
1262
'and related tools')
1263
1264
1265
@depends('MOZBUILD_STATE_PATH', '--help')
1266
@imports('os')
1267
def mozbuild_state_path(path, _):
1268
if path:
1269
return path[0]
1270
return os.path.expanduser(os.path.join('~', '.mozbuild'))
1271
1272
1273
# A template providing a shorthand for setting a variable. The created
1274
# option will only be settable with imply_option.
1275
# It is expected that a project-specific moz.configure will call imply_option
1276
# to set a value other than the default.
1277
# If required, the set_as_define and set_for_old_configure arguments
1278
# will additionally cause the variable to be set using set_define and
1279
# add_old_configure_assignment. util.configure would be an appropriate place for
1280
# this, but it uses add_old_configure_assignment, which is defined in this file.
1281
@template
1282
def project_flag(env=None, set_for_old_configure=False,
1283
set_as_define=False, **kwargs):
1284
1285
if not env:
1286
configure_error(
1287
"A project_flag must be passed a variable name to set.")
1288
1289
opt = option(env=env, possible_origins=('implied',), **kwargs)
1290
1291
@depends(opt.option)
1292
def option_implementation(value):
1293
if value:
1294
if len(value):
1295
return value
1296
return bool(value)
1297
1298
set_config(env, option_implementation)
1299
if set_as_define:
1300
set_define(env, option_implementation)
1301
if set_for_old_configure:
1302
add_old_configure_assignment(env, option_implementation)
1303
1304
# milestone.is_nightly corresponds to cases NIGHTLY_BUILD is set.
1305
1306
1307
@depends(milestone)
1308
def enabled_in_nightly(milestone):
1309
return milestone.is_nightly