~ubuntu-branches/ubuntu/wily/bombono-dvd/wily

« back to all changes in this revision

Viewing changes to tools/scripts/BuildVars.py

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-11-04 11:46:25 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101104114625-8xfdhvhpsm51i0nu
Tags: upstream-0.8.0
ImportĀ upstreamĀ versionĀ 0.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
BuildCfg = ''
13
13
BuildDir = ''
14
 
BuildProfile = 0
15
14
# brief compiling/linking output
16
15
BuildBrief = 0
17
16
 
63
62
 
64
63
########################################################################
65
64
 
 
65
def IsBuildOrRunTests():
 
66
    return BuildTests or RunTests
 
67
 
66
68
def CheckSettings(main_env):
67
69
    global Cc, Cxx, BuildDir, Targets, RunTests, BuildTests
68
70
    if RunTests :
69
 
        print 'Building and running tests'
 
71
        print 'Tests: on'
70
72
    else:
71
73
        if BuildTests:
72
 
            print 'Building with tests'
 
74
            print 'Tests: on (only building)'
73
75
 
74
76
    def_env = GetDefEnv()
75
77
    # for SCons =<0.96 we need to warn that just 'scons' is not enough:
98
100
    # we use TestSConscript() function instead of SConscript()
99
101
    # to run tests 
100
102
    def TestSConscript(*args, **kwds):
101
 
        if BuildTests or RunTests:
 
103
        if IsBuildOrRunTests():
102
104
            def_env.SConscript(*args, **kwds)
103
105
    def_env.Export('TestSConscript')
104
106
    # make test Builder
105
107
    if RunTests:
106
 
        def generate_test_actions(source, target, env, for_signature):    
107
 
            return '%s' % (source[0])
108
 
        #test_bld = Builder(action = '$SOURCE $TARGET')
109
 
        test_bld = main_env.Builder(generator = generate_test_actions)
110
 
 
111
 
        def TestingString(target, source, env):
112
 
            return '\nRunning tests: %s' % (source[0])
113
 
        test_bld.action.strfunction = TestingString
 
108
        #def generate_test_actions(source, target, env, for_signature):    
 
109
        #    return '%s' % (source[0])
 
110
        #test_bld = main_env.Builder(generator = generate_test_actions)
 
111
        #
 
112
        #def TestingString(target, source, env):
 
113
        #    return '\nRunning tests: %s' % (source[0])
 
114
        #test_bld.action.strfunction = TestingString
 
115
 
 
116
        # :TODO: now all tests have the same args; should be fixed
 
117
        # by storing dict of (test_bin_Node, args) and using it in make_test_str()
 
118
        #
 
119
        # --catch_system_errors=no is needed because Boost.Test of new Boost versions conflicts
 
120
        # with other software (e.g. GTK) by handling signals its own way.
 
121
        # Attention: UNIX signals are CRAP!!! I hate you.
 
122
        UT_ARGS = '--catch_system_errors=no'
 
123
 
 
124
        def make_test_str(source, is_cmd):
 
125
            res = '%s' % (source[0])
 
126
            if is_cmd or (not BuildBrief):
 
127
                if UT_ARGS:
 
128
                    res += ' ' + UT_ARGS 
 
129
            return res
 
130
 
 
131
        def generate_test_actions(source, target, env, for_signature):
 
132
            return make_test_str(source, True)
 
133
 
 
134
        def generate_test_str(target, source, env):
 
135
            return '\nRunning tests: %s' % (make_test_str(source, False))
 
136
 
 
137
        test_act = MakeGenAction(generate_test_actions, generate_test_str)
 
138
        test_bld = main_env.Builder(action = test_act)
114
139
 
115
140
        main_env.Append( BUILDERS = {'UnitTest_': test_bld} )
116
141
 
117
142
    def UnitTest(test_program_name, env):
118
143
        if RunTests:
119
144
            # use non-existent target to run command always
120
 
            env.UnitTest_(target = '_fiction_target_', source = test_program_name)
 
145
            env.UnitTest_(target = '%s.run' % test_program_name, source = test_program_name)
121
146
    main_env.Export('UnitTest')
122
147
 
123
148
    # set brief output
287
312
    else:
288
313
        return SCons.Options.Options(*args, **kw)
289
314
 
 
315
def VariantDir(variant_dir, src_dir, duplicate=1):
 
316
    def_env = GetDefEnv()
 
317
    if IsVariablesNow:
 
318
        def_env.VariantDir(variant_dir, src_dir, duplicate)
 
319
    else:
 
320
        def_env.BuildDir(variant_dir, src_dir, duplicate)
 
321
 
290
322
################################################################
291
323
# Autoconfig stuff
292
324
 
312
344
    str = GetArch().lower()
313
345
    return str.startswith('alpha')
314
346
 
 
347
def IsGccLike():
 
348
    # all those compilers who understand gcc extensions: gcc, clang
 
349
    return UserOptDict['IS_GCC']
 
350
 
315
351
def IsGccCompiler():
316
352
    #return Cc == 'gcc'
317
 
    return UserOptDict['IS_GCC']
 
353
    return UserOptDict['IS_GCC'] and not UserOptDict['IS_CLANG']
 
354
 
 
355
def IsClangCompiler():
 
356
    def has_tail(name, tail):
 
357
        ln = len(name) - len(tail)
 
358
        return name[ln:] == tail
 
359
 
 
360
    #res = has_tail(BV.Cc, 'clang')
 
361
    res = UserOptDict['IS_CLANG']
 
362
    if res:
 
363
        assert( has_tail(Cxx, 'clang++') )
 
364
    return res
318
365
 
319
366
def MakeObjectComment(obj_name, is_one_set):
320
367
    prefix = "Define "
417
464
def GetDict(name):
418
465
    dict = UserOptDict[MakeDictName(name)]
419
466
    #reduce SCons' C scanner area, CPPPATH -> CPP_POST_FLAGS
420
 
    if UserOptDict['BUILD_QUICK']:
 
467
    if IsToBuildQuick():
421
468
        MoveIncludeOptions(dict)
422
469
    return dict
423
470
 
434
481
        GetSrcBuildDir.obj = GetDefEnv().Dir(BuildDir + '/' + GetSrcDirPath())
435
482
    return GetSrcBuildDir.obj
436
483
 
437
 
def CreateEnv(**kw):
 
484
def IsToBuildQuick():
 
485
    can_bq = IsGccLike() # gcc and clang only (because of PCH)
 
486
 
 
487
    val = UserOptDict['BUILD_QUICK']
 
488
    want_bq = val != 'false'
 
489
    if val == 'auto':
 
490
        want_bq = IsDebugCfg()
 
491
 
 
492
    res = False
 
493
    if want_bq:
 
494
        if can_bq:
 
495
            res = True
 
496
        elif not IsReenter(IsToBuildQuick):
 
497
            # warn once only
 
498
            print 'BUILD_QUICK=true is not supported for current compiler(%s)!' % Cc
 
499
 
 
500
    return res
 
501
 
 
502
def CreateEnvVersion2(**kw):
438
503
    tools = ['default', 'AuxTools']
439
504
    if kw.has_key('tools'):
440
505
        tools += kw['tools']
441
506
    kw['tools'] = tools
442
507
 
443
 
    return GetDefEnv().Environment(ENV = os.environ, toolpath = ['tools/scripts'], **kw)
444
 
 
445
 
def CreateLEnv(**kw):
446
 
    env = CreateEnv(**kw)
447
 
    # for local includes
 
508
    env = GetDefEnv().Environment(ENV = os.environ, toolpath = ['tools/scripts'], **kw)
448
509
    env.Prepend(CPPPATH = [GetSrcBuildDir(), '#/' + GetSrcDirPath()])
 
510
 
 
511
    # :TRICKY: relatively new ar (from binutils) needed for such things (Hardy doesn't have such)
 
512
    # so turn it off for releases completely
 
513
    if IsToBuildQuick():
 
514
        # thin archives ('T' option) are to speed up static libraries build
 
515
        # :TRICKY: libmpeg2.a and etc have to be built directly to build/lib (withour copying/symlinking)
 
516
        env.Replace(ARFLAGS = str(env['ARFLAGS']) + 'T')
449
517
    return env
450
518
 
451
519
def MakeMainEnv():
452
 
    if UserOptDict['BUILD_QUICK']:
 
520
    if IsToBuildQuick():
 
521
        
 
522
        if IsGccCompiler():
 
523
            is_clang = False
 
524
        elif IsClangCompiler():
 
525
            is_clang = True
 
526
        else:
 
527
            assert False
 
528
 
453
529
        def SetPCH(env, header_name, additional_envs=[]):
454
530
            # :COMMENT: the "is_def" version is done to
455
531
            # check gcc' .gch using; once not used, dummy_pc_.h
459
535
            # versions and so should be tested, resp.
460
536
            is_def = 1
461
537
            if is_def:
 
538
                def make_pch(pch_env):
 
539
                    # we need to set args definitely to override SCons '# and BuildDir' dualism
 
540
                    return pch_env.Gch(target = header_name + env['GCHSUFFIX'], source = env.File(header_name).srcnode())[0]
 
541
 
 
542
                if is_clang:
 
543
                    pch_file = make_pch(env.Clone())
 
544
                    # :KLUDGE: CPPFLAGS is right way but it breaks if there is an C file
 
545
                    # in environment
 
546
                    env.Append(CXXFLAGS = '-include %s' % env.File(header_name).path)
 
547
                else:
 
548
                    pch_file = make_pch(env)
 
549
                    env.Depends(pch_file, env.InstallAs(target = './'+header_name, source = '#tools/scripts/dummy_pc_.h'))
 
550
 
462
551
                env['DepGch'] = 1
463
 
                #
464
 
                # No need for this anymore
465
 
                #
466
 
                # # we need make own env for pch
467
 
                # # because it should not include dummy_pc_.h,
468
 
                # # so we modify CPPPATH
469
 
                # copy_env = env.Copy()
470
 
                #
471
 
                # cpp_path = copy_env['CPPPATH']
472
 
                # del_pos = None
473
 
                # try:
474
 
                #     del_pos = cpp_path.index(GetSrcBuildDir())
475
 
                #     cpp_path.pop(del_pos)
476
 
                # except ValueError:
477
 
                #     # no path - no problem
478
 
                #     pass
479
 
                #
480
 
                #     # :TEMP:
481
 
                #     print "cpp_path - ValueError"
482
 
                #
483
 
                # env['Gch'] = copy_env.Gch(target = header_name + env['GCHSUFFIX'], source = env.File(header_name).srcnode())[0]
484
 
    
485
 
                # we need to set args definitely to override SCons '# and BuildDir' dualism
486
 
                env['Gch'] = env.Gch(target = header_name + env['GCHSUFFIX'], source = env.File(header_name).srcnode())[0]
487
 
 
488
 
                env.Depends(env['Gch'], env.InstallAs(target = './'+header_name, source = '#tools/scripts/dummy_pc_.h'))
489
 
 
490
552
                for add_env in additional_envs:
491
553
                    add_env['DepGch'] = 1
492
554
            else:
493
 
                env['Gch'] = env.Gch(header_name)[0]
 
555
                pch_file = env.Gch(header_name)[0]
494
556
 
 
557
            env['Gch'] = pch_file
495
558
            for add_env in additional_envs:
496
 
                add_env['Gch'] = env['Gch']
497
 
 
498
 
        UserOptDict['SetPCH'] = SetPCH
499
 
 
500
 
        env = CreateLEnv(tools = ['gch'])
501
 
 
 
559
                add_env['Gch'] = pch_file
 
560
 
 
561
        env = CreateEnvVersion2(tools = ['gch'])
 
562
        suffix = '.pch' if is_clang else '.gch'
 
563
        env['GCHSUFFIX'] = suffix
 
564
    
502
565
        # 2 - reduce SCons' C scanner area, CPPPATH -> CPP_POST_FLAGS
503
566
        env['_CPPINCFLAGS'] = env['_CPPINCFLAGS'] + ' $CPP_POST_FLAGS'
504
567
    else:
505
568
        def SetPCH(env, header_name, additional_envs=[]):
506
569
            pass
507
 
        UserOptDict['SetPCH'] = SetPCH
508
 
 
509
 
        env = CreateLEnv()
510
 
 
 
570
        env = CreateEnvVersion2()
 
571
 
 
572
    UserOptDict['SetPCH'] = SetPCH
511
573
    # we use function Dir() so SCons do not change it
512
574
    # for local libs
513
 
    env.Append(LIBPATH = env.Dir(UserOptDict['LIB_BUILD_DIR']))
 
575
    env.Append(LIBPATH = [env.Dir(UserOptDict['LIB_BUILD_DIR'])])
514
576
    CheckSettings(env)
515
577
 
516
578
    return env
545
607
        tgt = env.InstallAs(dst_list, src_list)
546
608
    return tgt
547
609
 
 
610
def make_source_files(fpath, lst):
 
611
    typ = type(lst)
 
612
    if typ != list :
 
613
        assert( typ == str )
 
614
        lst = GetDefEnv().Split(lst)
 
615
 
 
616
    return [ os.path.join(fpath, fname) for fname in lst ]
 
617
 
 
618
def InitUOD(user_options_dict):
 
619
    global UserOptDict
 
620
    UserOptDict = user_options_dict
 
621
    UserOptDict['make_source_files'] = make_source_files
548
622