summaryrefslogtreecommitdiffstats
path: root/build/SConscript.main
blob: d144c68a3b3197bbcef83abf1386079953deacbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
# Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import shutil
import sys


p = ARGUMENTS.get('PROGRESS')
if p == 'spinner':
  Progress(['/\r', '|\r', '\\\r', '-\r'], interval=5, file=open('con', 'w'))
elif p == 'name':
  Progress('$TARGET\r', overwrite=True, file=open('con', 'w'))


default_warnings = ['no-missing-sconscript', 'no-no-parallel-support']
default_warnings = ['no-no-parallel-support']
SetOption('warn', default_warnings + GetOption('warn'))


load = ARGUMENTS.get('LOAD')
if load:
    load = load.split(',')
else:
    load = []


env = Environment(
    BUILD_TYPE = ARGUMENTS.get('BUILD_TYPE', 'Hammer'),
    CHROME_SRC_DIR = Dir('#/..').abspath,
    TARGET_ROOT = Dir('#/$BUILD_TYPE').abspath,
    OBJ_ROOT = '$TARGET_ROOT',

    LIBS_DIR              = '$OBJ_ROOT/Libs',

    BASE_DIR              = '$OBJ_ROOT/base',
    BREAKPAD_DIR          = '$OBJ_ROOT/breakpad',
    CHROME_DIR            = '$OBJ_ROOT/chrome',
    GEARS_DIR             = '$OBJ_ROOT/gears',
    GOOGLE_UPDATE_DIR     = '$OBJ_ROOT/google_update',
    GOOGLEURL_DIR         = '$OBJ_ROOT/googleurl',
    NET_DIR               = '$OBJ_ROOT/net',
    RLZ_DIR               = '$OBJ_ROOT/rlz',
    SANDBOX_DIR           = '$OBJ_ROOT/sandbox',
    SDCH_DIR              = '$OBJ_ROOT/sdch',
    SKIA_DIR              = '$OBJ_ROOT/skia',
    TESTING_DIR           = '$OBJ_ROOT/testing',
    THIRD_PARTY_DIR       = '$OBJ_ROOT/third_party',
    V8_DIR                = '$OBJ_ROOT/v8',
    WEBKIT_DIR            = '$OBJ_ROOT/webkit',

    GTEST_DIR             = '$TESTING_DIR/gtest',

    BSDIFF_DIR            = '$THIRD_PARTY_DIR/bsdiff',
    BSPATCH_DIR           = '$THIRD_PARTY_DIR/bspatch',
    BZIP2_DIR             = '$THIRD_PARTY_DIR/bzip2',
    ICU38_DIR             = '$THIRD_PARTY_DIR/icu38',
    LIBEVENT_DIR          = '$THIRD_PARTY_DIR/libevent',
    LIBJPEG_DIR           = '$THIRD_PARTY_DIR/libjpeg',
    LIBPNG_DIR            = '$THIRD_PARTY_DIR/libpng',
    LIBXML_DIR            = '$THIRD_PARTY_DIR/libxml',
    LIBXSLT_DIR           = '$THIRD_PARTY_DIR/libxslt',
    LZMA_SDK_DIR          = '$THIRD_PARTY_DIR/lzma_sdk',
    MODP_B64_DIR          = '$THIRD_PARTY_DIR/modp_b64',
    NPAPI_DIR             = '$THIRD_PARTY_DIR/npapi',
    ZLIB_DIR              = '$THIRD_PARTY_DIR/zlib',

    THIRD_PARTY_WEBKIT_DIR = '$THIRD_PARTY_DIR/WebKit',

    PYTHON=sys.executable,

    LIBPATH               = ['$LIBS_DIR'],

    PERL                  = 'perl',
    PERL_INCLUDE_FLAG     = '-I ',
    PERL_INCLUDE_SUFFIX   = '',
    _PERL_INCLUDE_FLAGS   = ('${_concat(PERL_INCLUDE_FLAG, '
                             'PERL_INCLUDE_PATH, '
                             'PERL_INCLUDE_SUFFIX,'
                             '__env__, RDirs, TARGET, SOURCE)}'),
)

def AddPdbToTarget(args):
    """Add the windows pdb file to the build target.

    Arguments:
      args is a tuple passed to ChromeProgram or ChromeTestProgram
    Returns:
      A tuple to pass on to Environment.Program."""
    # Only add .pdb to the target if the target was only a string. We can't
    # blindly add foo.pdb because chrome.exe and chrome.dll use chrome_exe.pdb
    # and chrome_dll.pdb.
    if not isinstance(args[0], str):
        return args

    mutable_args = list(args)
    mutable_args[0] = [args[0], args[0] + '.pdb']
    return tuple(mutable_args)

def ChromeProgram(env, *args, **kw):
    if env['PLATFORM'] == 'win32':
        # TODO(tc): We should handle kw['target'] too.
        args = AddPdbToTarget(args)
    return env.Program(*args, **kw)
env.AddMethod(ChromeProgram, "ChromeProgram")

def ChromeTestProgram(env, *args, **kw):
    if env['PLATFORM'] == 'win32':
        # TODO(tc): We should handle kw['target'] too.
        args = AddPdbToTarget(args)
    return env.Program(*args, **kw)
env.AddMethod(ChromeTestProgram, "ChromeTestProgram")

def ChromeStaticLibrary(env, *args, **kw):
    result = env.StaticLibrary(*args, **kw)
    if env['PLATFORM'] == 'win32':
      # TODO(sgk):
      # We'd like to do this with env.Install() like we do on other systems,
      # but this causes problems on Windows when the Python copy of the file
      # in one thread prevents a linker spawned by another thread from
      # opening the copied .lib, despite the fact that the copy has
      # successfully concluded before the spawn occurs.  Work around the
      # underlying problem (whatever it is) by calling the external Windows
      # xcopy utility.
      env.Command('$LIBS_DIR/${RESULT.name}', '$RESULT',
                  "xcopy /q /y $SOURCE ${TARGET.dir}",
                  RESULT=result[0])
    else:
      env.Install('$LIBS_DIR', result)
    return result
env.AddMethod(ChromeStaticLibrary, "ChromeStaticLibrary")

def ChromeSharedLibrary(env, *args, **kw):
    return env.SharedLibrary(*args, **kw)
env.AddMethod(ChromeSharedLibrary, "ChromeSharedLibrary")


if env['PLATFORM'] == 'win32':

  processors = int(os.environ.get('NUMBER_OF_PROCESSORS', 1))
  SetOption('num_jobs', processors + 1)

  msvs_env = Environment(tools=['msvc', 'mslink', 'msvs'])['ENV']

  # Use the absolute path for MSVC because it might not be on the same drive
  # as our source checkout.
  visual_studio_path = (msvs_env['PATH'][0] +
                        ':/Program Files/Microsoft Visual Studio 8')

  env.Replace(
    CSCRIPT = 'c:\\Windows\\System32\\cscript',

    PLATFORMSDK_VISTA_REL = '../third_party/platformsdk_vista_6_0',
    PLATFORMSDK_VISTA = '$CHROME_SRC_DIR/$PLATFORMSDK_VISTA_REL',
    VISUAL_STUDIO = visual_studio_path,

    CYGWIN_DIR = env.Dir('$CHROME_SRC_DIR/third_party/cygwin'),
    CYGWIN_BIN_DIR = '$CYGWIN_DIR/bin',

    PERL = '$CYGWIN_BIN_DIR/perl.exe',

    MSVS_ENV = msvs_env,

    YACC = '$CYGWIN_BIN_DIR/bison.exe',

    ARFLAGS = [
        '/nologo',
    ],

    CCFLAGS = [
        '/nologo',

        '/Od',          # no optimization

        '/RTC1',
        '/MTd',         # static link to crt, and debug version
        '/Gy',
        '/GR-',

        '/W3',

        '/Z7',

        '/errorReport:prompt',

        '/wd4503',
        '/wd4819',
    ],

    CPPDEFINES = [
        '_CRT_SECURE_NO_DEPRECATE',
        '_CRT_NONSTDC_NO_WARNINGS',
        '_CRT_NONSTDC_NO_DEPRECATE',
        '_SCL_SECURE_NO_DEPRECATE',

        '_DEBUG',

        '_CRT_RAND_S',
        ('_WIN32_WINNT', '0x0600'),
        ('WINVER', '0x0600'),
        'WIN32',
        '_WINDOWS',
        ('_HAS_EXCEPTIONS', 0),
        'NOMINMAX',
        '_UNICODE',
        'UNICODE',

        'CERT_CHAIN_PARA_HAS_EXTRA_FIELDS',
        'WIN32_LEAN_AND_MEAN',
    ],

    CPPPATH = [
        '$PLATFORMSDK_VISTA/files/Include',
        '$PLATFORMSDK_VISTA/files/VC/INCLUDE',
        '$VISUAL_STUDIO/VC/atlmfc/include',
    ],

    LIBS = [
        'advapi32.lib',
        'comdlg32.lib',
        'gdi32.lib',
        'kernel32.lib',
        'msimg32.lib',
        'odbc32.lib',
        'odbccp32.lib',
        'ole32.lib',
        'oleaut32.lib',
        'psapi.lib',
        'shell32.lib',
        'user32.lib',
        'usp10.lib',
        'uuid.lib',
        'version.lib',
        'wininet.lib',
        'winspool.lib',
        'ws2_32.lib',

        'DelayImp.lib',
    ],

    LINKFLAGS = [
        '/nologo',
        '/DEBUG',
    ],

    ICU_LIBS = ['icu'],
  )

  env.Append(
    LIBPATH = [
        '$PLATFORMSDK_VISTA/files/Lib',
        '$PLATFORMSDK_VISTA/files/VC/LIB',
        '$VISUAL_STUDIO/VC/atlmfc/lib',
    ],
  )

  # TODO(sgk): remove once we upgrade to SCons 0.98.4
  for var in ['INCLUDE', 'LIB', 'PATH']:
    msvs_env[var] = msvs_env[var].split('|', 1)[0]
    env['ENV'][var] = env['ENV'][var].split('|', 1)[0]

  # Force scons to handle long include lines correctly.
  pchcom_fixed = env['PCHCOM']
  pchcom_fixed = pchcom_fixed.replace('${TARGETS[0]}', '$TARGET')
  pchcom_fixed = pchcom_fixed.replace('${TARGETS[1]}', '$TARGETS1')

  env.Replace(
      CCCOM = "${TEMPFILE('%s')}" % env['CCCOM'],
      CXXCOM = "${TEMPFILE('%s')}" % env['CXXCOM'],
      SHCCCOM = "${TEMPFILE('%s')}" % env['SHCCCOM'],
      SHCXXCOM = "${TEMPFILE('%s')}" % env['SHCXXCOM'],
      PCHCOM = "${TEMPFILE('%s')}" % pchcom_fixed,
      TARGETS1 = '${TARGETS[1]}',
  )

  env['ENV']['PROGRAMFILES'] = os.environ['PROGRAMFILES']
  env['ENV']['SystemDrive'] = os.environ['SystemDrive']
  env['ENV']['USERPROFILE'] = os.environ['USERPROFILE']

  env.AppendENVPath('PATH', ';C:\\WINDOWS\\system32')

elif env['PLATFORM'] == 'posix':

  # Copy some environment variables from the outer environment if they exist.
  for envvar in ['CC', 'CXX']:
    if envvar in os.environ:
      env[envvar] = os.environ[envvar]
  # Provide $HOME when compiling so distcc can find its lock file.
  env['ENV']['HOME'] = os.environ['HOME']
  if 'DISTCC_HOSTS' in os.environ:
    env['ENV']['DISTCC_HOSTS'] = os.environ['DISTCC_HOSTS']

  # TODO(evanm): this is Linux-specific, not posix.
  # Parse /proc/cpuinfo for processor count.
  cpus = len([l for l in open('/proc/cpuinfo') if l.startswith('processor\t')])
  SetOption('num_jobs', cpus + 1)

  # For now, linux only loads the components we know work on Linux, by default.
  load = [
      'base',
      'breakpad',
      'chrome',
      'googleurl',
      'net',
      'sdch',
      'skia',
      'testing',
      'third_party',
      'v8',
      'webkit',
  ]

  excluded_warnings = [
    # TODO: Clean up uses of ext/hash_map and remove this.
    # (see unordered_map and base/hash_tables.h)
    '-Wno-deprecated',  # Needed for using ext/hash_map on GCC 4.3
    '-Wno-unknown-pragmas',  # In wtf's ref counting system
  ]
  env.Replace(
      CCFLAGS = ['-m32', '-g', '-pthread'],
      CXXFLAGS = ['-Wall', '-Werror'] + excluded_warnings,
      LINKFLAGS = ['-m32', '-pthread'],

    # We have several cases where archives depend on each other in a cyclic
    # fashion. (V8Bindings, libport and WebCore being the most significant
    # example.) Since the GNU linker does only a single pass over the archives
    # we need some extra trickery to deal with these unavoidable cycles. That
    # trickery is --start-group and --end-group (aka -( and -) ). That causes ld
    # to loop over the group until no more undefined symbols are found. In an
    # ideal world we would only make groups from those libraries which we knew
    # to be in cycles. However, that's tough with SCons, so we bodge it by
    # making all the archives a group by redefining the linking command here.
    SHLINKCOM = ('$SHLINK -shared -o $TARGET $SHLINKFLAGS $SOURCES '
                 '$_LIBDIRFLAGS '
                 '-Wl,--start-group $_LIBFLAGS -Wl,--end-group'),
    LINKCOM = ('$LINK -o $TARGET $LINKFLAGS $SOURCES '
               '$_LIBDIRFLAGS '
               '-Wl,--start-group $_LIBFLAGS -Wl,--end-group'),

      # We need rt for clock_gettime.
      LIBS = ['rt'],

      PERL = '/usr/bin/perl',
      PERL_INCLUDE_FLAG = '-I ',
      PERL_INCLUDE_SUFFIX = '',
      _PERL_INCLUDE_FLAGS = ('${_concat(PERL_INCLUDE_FLAG, '
                             'PERL_INCLUDE_PATH, '
                             'PERL_INCLUDE_SUFFIX,'
                             '__env__, RDirs, TARGET, SOURCE)}'),

      ICU_LIBS = ['icu'],
  )
  # Build with support for gcov when COVERAGE=1.
  if ARGUMENTS.get('COVERAGE') == '1':
    env.Append(CCFLAGS=['-fprofile-arcs', '-ftest-coverage'])
    env.Append(LINKFLAGS=['-fprofile-arcs'])

  # Build with system-provided NSS and GTK.
  env.ParseConfig('pkg-config --cflags --libs nss')
  env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')

elif env['PLATFORM'] == 'darwin':

  # For now, mac only loads the components we know work on Mac, by default.
  load = [
      'base',
      #'breakpad',
      'googleurl',
      'net',
      'sdch',
      'skia',
      'testing',
      'third_party',
      #'webkit',
  ]

  env.Replace(
      # Reproduce XCode's behavior of using gcc even to link C++,
      # and distinguishing it the -x c++ option.
      CC = 'gcc-4.2',
      CXX = 'g++-4.2',
      LINK = '$CXX',

      CFLAGS = [
          '-std=c99',
      ],
      CXXFLAGS = [
          '-fvisibility-inlines-hidden',
          '${str(SOURCE).endswith(".mm") and "-fobjc-gc" or ""}',
      ],
      CCFLAGS = [
          '-fmessage-length=0',
          '-pipe',
          '-O0',
          '-mdynamic-no-pic',
          '-Werror',
          '-Wnewline-eof',
          '-fvisibility=hidden',
          '-gdwarf-2',
          '-Wall',
          '-Wendif-labels',
          '-fstack-protector',
          '-fstack-protector-all',
      ],
      CPPDEFINES = [
          'DEBUG',
      ],

      FRAMEWORKPATH = [
          env.Dir('${TARGET_ROOT}'),
          '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks',
      ],
      FRAMEWORKS = [
          'AppKit',
          'ApplicationServices',
          'Foundation',
      ],

      ICU_LIBS = ['icui18n', 'icuuc', 'icudata'],
  )

else:

  print "Unsupported SCons $PLATFORM value %s" % repr(env['PLATFORM'])
  Exit(1)


if ARGUMENTS.get('VERBOSE') in (None, '0'):
  env['CCCOMSTR'] = 'Compiling $TARGET ...'
  env['CXXCOMSTR'] = 'Compiling $TARGET ...'
  env['SHCCCOMSTR'] = 'Compiling $TARGET ...'
  env['SHCXXCOMSTR'] = 'Compiling $TARGET ...'
  env['ARCOMSTR'] = 'Archiving $TARGET ...'
  env['LINKCOMSTR'] = 'Linking $TARGET ...'
  env['BINDINGSCOMSTR'] = 'Building bindings in $TARGET ...'


# Add --clobber (for the buildbot).
# NOTE: seems to be crucial to do this before any builders are invoked.
AddOption('--clobber', action='store_true', dest='clobber', default=False,
          help='Delete build directory before building.')
if GetOption('clobber'):
  shutil.rmtree(env.Dir('$TARGET_ROOT').abspath, True)


# Place the .sconsign.dblite in the build directory.
target_dir = env.Dir('$TARGET_ROOT')
if not os.path.exists(target_dir.abspath):
  Execute(Mkdir(target_dir))
SConsignFile(target_dir.File('.sconsign').abspath)


# Use timestamps change, followed by MD5 for speed
env.Decider('MD5-timestamp')


# Overlay things from a layer below.
env.Dir('$TARGET_ROOT').addRepository(env.Dir('$CHROME_SRC_DIR'))
env.Dir('$TARGET_ROOT/googleurl').addRepository(env.Dir('$CHROME_SRC_DIR/build'))

included = [c for c in load if not c.startswith('-')]
excluded = [c[1:] for c in load if c.startswith('-')]
if not included:
  included = ['all']

components = ['all']

def LoadComponent(c):
  components.append(c)
  return (not GetOption('help') and
          c in included or
          ('all' in included and not c in excluded))

sconscripts = []

if LoadComponent('base'):
  sconscripts.append('$BASE_DIR/base.scons')

if LoadComponent('breakpad'):
  sconscripts.append('$BREAKPAD_DIR/SConscript')

if LoadComponent('chrome'):
  sconscripts.append('$CHROME_DIR/SConscript')

if LoadComponent('gears'):
  sconscripts.append('$GEARS_DIR/SConscript')

if LoadComponent('google_update'):
  sconscripts.append('$GOOGLE_UPDATE_DIR/SConscript')

if LoadComponent('googleurl'):
  # googleurl comes from a different repository so we provide the SConscript
  # file.
  sconscripts.append('$GOOGLEURL_DIR/googleurl.scons')

if LoadComponent('net'):
  sconscripts.append('$NET_DIR/net.scons')

if LoadComponent('rlz'):
  sconscripts.append('$RLZ_DIR/SConscript')

if LoadComponent('sandbox'):
  sconscripts.append('$SANDBOX_DIR/src/SConscript')

if LoadComponent('sdch'):
  sconscripts.append('$SDCH_DIR/SConscript')

if LoadComponent('skia'):
  sconscripts.append('$SKIA_DIR/SConscript')

if LoadComponent('testing'):
  sconscripts.append('$TESTING_DIR/SConscript.gtest')

if LoadComponent('third_party'):
  sconscripts.extend([
      '$BSDIFF_DIR/SConscript',
      '$BZIP2_DIR/bzip2.scons',
      '$ICU38_DIR/icu38.scons',
      '$LIBPNG_DIR/libpng.scons',
      '$LZMA_SDK_DIR/SConscript',
      '$MODP_B64_DIR/modp_b64.scons',
      '$ZLIB_DIR/zlib.scons',
  ])
  # Temporary until we get these building on Mac.
  if env['PLATFORM'] != 'darwin':
    sconscripts.extend([
      '$LIBJPEG_DIR/SConscript',
      '$LIBXML_DIR/SConscript',
      '$LIBXSLT_DIR/SConscript',
    ])
  if env['PLATFORM'] in ('posix', 'darwin'):
    sconscripts.extend([
      '$LIBEVENT_DIR/libevent.scons',
    ])
  # This is temporary until we get this lib to build on other platforms.
  if env['PLATFORM'] == 'win32':
    sconscripts.extend([
        '$BSPATCH_DIR/SConscript',
    ])

if LoadComponent('v8') and env.Dir('$CHROME_SRC_DIR/v8').exists():
  env.SConscript('SConscript.v8',
                 exports=['env'])

if LoadComponent('webkit'):
  sconscripts.append('$WEBKIT_DIR/SConscript')

env.SConscript(sconscripts, exports=['env'])


help_fmt = """
Usage: hammer [SCONS_OPTIONS] [VARIABLES] [TARGET] ...

Supported build variables:

  BUILD_TYPE=type           Build type.  Also used as the subdirectory name
                              in which the build occurs.
  LOAD=[module,...]         Comma-separated list of components to load in the
                              dependency graph ('-' prefix excludes):
%s
  PROGRESS=type             Display a progress indicator:
                              name:  print each evaluated target name
                              spinner:  print a spinner every 5 targets
  VERBOSE=1                 Display full command lines
"""

if GetOption('help'):
  import textwrap
  tw = textwrap.TextWrapper(
    width = 78,
    initial_indent = ' '*32,
    subsequent_indent = ' '*32,
  )
  components = tw.fill(', '.join(components))

  Help(help_fmt % components)


Import('build_component')
Default(build_component)