Beispiel #1
0
def generate(env):
    """Add Builders and construction variables for Xcode project files
    to an Environment."""
    from SCons.Script import AddOption, GetOption, SetOption

    global _added
    if not _added:
        _added = True
        AddOption(
            "--xcode-action",
            dest="xcode_action",
            type="string",
            action="store",
            default="",
            help="The action Xcode wishes to perform",
        )
        AddOption(
            "--xcode-variant",
            dest="xcode_variant",
            type="string",
            action="store",
            default="",
            help="The variant Xcode wishes to activate",
        )

    xcode = GetOption("xcode_action")
    if xcode == "clean":
        SetOption("clean", True)

    projectAction = SCons.Action.Action(GenerateProject, None)

    projectBuilder = SCons.Builder.Builder(
        action="$XCODEPROJECTCOM",
        suffix="$XCODEPROJECTSUFFIX",
        emitter=projectEmitter,
        target_factory=env.fs.Dir,
        source_factory=env.fs.Dir,
    )

    if "XcodeProject" not in env:
        env["BUILDERS"]["XcodeProject"] = projectBuilder

    env["XCODEPROJECTCOM"] = projectAction
    env["XCODEPROJECTSUFFIX"] = ".xcodeproj"
    env["XCODEORGANIZATION"] = "n/a"

    if "XCODE" not in env:
        env["XCODE"] = {}
Beispiel #2
0
def generate(env):
    """Add Builders and construction variables for Xcode project files
    to an Environment."""
    from SCons.Script import AddOption, GetOption, SetOption

    global _added
    if not _added:
        _added = True
        AddOption('--xcode-action',
                  dest='xcode_action',
                  type='string',
                  action='store',
                  default='',
                  help='The action Xcode wishes to perform')
        AddOption('--xcode-variant',
                  dest='xcode_variant',
                  type='string',
                  action='store',
                  default='',
                  help='The variant Xcode wishes to activate')

    xcode = GetOption('xcode_action')
    if xcode == 'clean':
        SetOption('clean', True)

    projectAction = SCons.Action.Action(GenerateProject, None)

    projectBuilder = SCons.Builder.Builder(action='$XCODEPROJECTCOM',
                                           suffix='$XCODEPROJECTSUFFIX',
                                           emitter=projectEmitter,
                                           target_factory=env.fs.Dir,
                                           source_factory=env.fs.Dir)

    if 'XcodeProject' not in env:
        env['BUILDERS']['XcodeProject'] = projectBuilder

    env['XCODEPROJECTCOM'] = projectAction
    env['XCODEPROJECTSUFFIX'] = '.xcodeproj'
    env['XCODEORGANIZATION'] = 'n/a'

    if 'XCODE' not in env:
        env['XCODE'] = {}
Beispiel #3
0
def SetupBuildEnvironment(conf):
    AddOption(
        '--optimization',
        '--opt',
        dest='opt',
        action='store',
        default='debug',
        choices=['debug', 'production', 'coverage', 'profile', 'valgrind'],
        help='optimization level: [debug|production|coverage|profile|valgrind]'
    )

    AddOption('--target',
              dest='target',
              action='store',
              choices=['i686', 'x86_64', 'armhf'])

    AddOption('--root', dest='install_root', action='store')
    AddOption('--prefix', dest='install_prefix', action='store')
    AddOption('--pytest', dest='pytest', action='store')

    env = CheckBuildConfiguration(conf)

    env.AddMethod(PlatformExclude, "PlatformExclude")
    env.AddMethod(GetPlatformInfo, "GetPlatformInfo")

    # Let's decide how many jobs (-jNN) we should use.
    nj = GetOption('num_jobs')
    if nj == 1:
        # Should probably check for CLI over-ride of -j1 (i.e., do not
        # assume 1 means -j not specified).
        nj = determine_job_value()
        if nj > 1:
            print "scons: setting jobs (-j) to %d" % nj
            SetOption('num_jobs', nj)
            env['NUM_JOBS'] = nj

    env['OPT'] = GetOption('opt')
    env['TARGET_MACHINE'] = GetOption('target')
    env['INSTALL_PREFIX'] = GetOption('install_prefix')
    env['INSTALL_BIN'] = ''
    env['INSTALL_SHARE'] = ''
    env['INSTALL_LIB'] = ''
    env['INSTALL_INIT'] = ''
    env['INSTALL_INITD'] = ''
    env['INSTALL_SYSTEMD'] = ''
    env['INSTALL_CONF'] = ''
    env['INSTALL_SNMP_CONF'] = ''
    env['INSTALL_EXAMPLE'] = ''
    env['PYTHON_INSTALL_OPT'] = ''
    env['INSTALL_DOC'] = ''

    install_root = GetOption('install_root')
    if install_root:
        env['INSTALL_BIN'] = install_root
        env['INSTALL_SHARE'] = install_root
        env['INSTALL_LIB'] = install_root
        env['INSTALL_INIT'] = install_root
        env['INSTALL_INITD'] = install_root
        env['INSTALL_SYSTEMD'] = install_root
        env['INSTALL_CONF'] = install_root
        env['INSTALL_SNMP_CONF'] = install_root
        env['INSTALL_EXAMPLE'] = install_root
        env['INSTALL_DOC'] = install_root
        env['PYTHON_INSTALL_OPT'] = '--root ' + install_root + ' '

    install_prefix = GetOption('install_prefix')
    if install_prefix:
        env['INSTALL_BIN'] += install_prefix
        env['INSTALL_SHARE'] += install_prefix
        env['INSTALL_LIB'] += install_prefix
        env['INSTALL_INIT'] += install_prefix
        env['INSTALL_INITD'] += install_prefix
        env['INSTALL_SYSTEMD'] += install_prefix
        env['PYTHON_INSTALL_OPT'] += '--prefix ' + install_prefix + ' '
    elif install_root:
        env['INSTALL_BIN'] += '/usr'
        env['INSTALL_SHARE'] += '/usr'
        env['INSTALL_LIB'] += '/usr'
        env['PYTHON_INSTALL_OPT'] += '--prefix /usr '
    else:
        env['INSTALL_BIN'] += '/usr/local'

    env['INSTALL_BIN'] += '/bin'
    env['INSTALL_SHARE'] += '/share'
    env['INSTALL_LIB'] += '/lib'
    env['INSTALL_INIT'] += '/etc/init'
    env['INSTALL_INITD'] += '/etc/init.d'
    env['INSTALL_SYSTEMD'] += '/lib/systemd/system'
    env['INSTALL_CONF'] += '/etc/contrail'
    env['INSTALL_SNMP_CONF'] += '/etc/snmp'
    env['INSTALL_EXAMPLE'] += '/usr/share/contrail'
    env['INSTALL_DOC'] += '/usr/share/doc'

    distribution = env.GetPlatformInfo()[0]

    if distribution in ["Ubuntu", "debian", "raspbian"]:
        env['PYTHON_INSTALL_OPT'] += '--install-layout=deb '

    if distribution == 'Darwin':
        PlatformDarwin(env)
        env['ENV_SHLIB_PATH'] = 'DYLD_LIBRARY_PATH'
    else:
        env['ENV_SHLIB_PATH'] = 'LD_LIBRARY_PATH'

    if env.get('TARGET_MACHINE') == 'i686':
        env.Append(CCFLAGS='-march=' + 'i686')
    elif env.get('TARGET_MACHINE') == 'armhf' or platform.machine().startswith(
            'arm'):
        env.Append(
            CCFLAGS=['-DTBB_USE_GCC_BUILTINS=1', '-D__TBB_64BIT_ATOMICS=0'])

    env['TOP_BIN'] = '#build/bin'
    env['TOP_INCLUDE'] = '#build/include'
    env['TOP_LIB'] = '#build/lib'

    pytest = GetOption('pytest')
    if pytest:
        env['PYTESTARG'] = pytest
    else:
        env['PYTESTARG'] = None

    # Store path to sandesh compiler in the env
    env['SANDESH'] = os.path.join(env.Dir(env['TOP_BIN']).path, 'sandesh')

    # Store the hostname in env.
    try:
        build_host = env['HOSTNAME'] if 'HOSTNAME' in env else os.environ[
            'HOSTNAME']
    except KeyError:
        build_host = os.uname()[1]
    env['HOSTNAME'] = build_host

    # Store repo projects in the environment
    proc = subprocess.Popen('repo list',
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell='True')
    repo_out, err = proc.communicate()
    repo_lines = repo_out.splitlines()
    repo_list = {}
    for l in repo_lines:
        (path, repo) = l.split(" : ")
        repo_list[path] = repo
    env['REPO_PROJECTS'] = repo_list

    opt_level = env['OPT']
    if opt_level == 'production':
        env.Append(CCFLAGS='-O3')
        env['TOP'] = '#build/production'
    elif opt_level == 'debug':
        env.Append(CCFLAGS=['-O0', '-DDEBUG'])
        env['TOP'] = '#build/debug'
    elif opt_level == 'profile':
        # Enable profiling through gprof
        env.Append(CCFLAGS=['-O3', '-DDEBUG', '-pg'])
        env.Append(LINKFLAGS=['-pg'])
        env['TOP'] = '#build/profile'
    elif opt_level == 'coverage':
        env.Append(CCFLAGS=['-O0', '--coverage'])
        env['TOP'] = '#build/coverage'
        env.Append(LIBS='gcov')
    elif opt_level == 'valgrind':
        env.Append(CCFLAGS=['-O0', '-DDEBUG'])
        env['TOP'] = '#build/valgrind'

    if not "CONTRAIL_COMPILE_WITHOUT_SYMBOLS" in os.environ:
        env.Append(CCFLAGS='-g')
        env.Append(LINKFLAGS='-g')

    env.Append(BUILDERS={'PyTestSuite': PyTestSuite})
    env.Append(BUILDERS={'TestSuite': TestSuite})
    env.Append(BUILDERS={'UnitTest': UnitTest})
    env.Append(BUILDERS={'GenerateBuildInfoCode': GenerateBuildInfoCode})
    env.Append(BUILDERS={'GenerateBuildInfoPyCode': GenerateBuildInfoPyCode})
    env.Append(BUILDERS={'GenerateBuildInfoCCode': GenerateBuildInfoCCode})

    env.Append(BUILDERS={'setup_venv': setup_venv})
    env.Append(BUILDERS={'venv_add_pip_pkg': venv_add_pip_pkg})
    env.Append(BUILDERS={'venv_add_build_pkg': venv_add_build_pkg})
    env.Append(BUILDERS={'build_maven': build_maven})

    env.AddMethod(ExtractCppFunc, "ExtractCpp")
    env.AddMethod(ExtractCFunc, "ExtractC")
    env.AddMethod(ExtractHeaderFunc, "ExtractHeader")
    env.AddMethod(GetBuildVersion, "GetBuildVersion")
    env.AddMethod(ProtocGenDescFunc, "ProtocGenDesc")
    env.AddMethod(ProtocGenCppFunc, "ProtocGenCpp")
    env.AddMethod(SandeshGenOnlyCppFunc, "SandeshGenOnlyCpp")
    env.AddMethod(SandeshGenCppFunc, "SandeshGenCpp")
    env.AddMethod(SandeshGenCFunc, "SandeshGenC")
    env.AddMethod(SandeshGenPyFunc, "SandeshGenPy")
    env.AddMethod(SandeshGenDocFunc, "SandeshGenDoc")
    env.AddMethod(GoCniFunc, "GoCniBuild")
    env.AddMethod(ThriftGenCppFunc, "ThriftGenCpp")
    ThriftSconsEnvPyFunc(env)
    env.AddMethod(ThriftGenPyFunc, "ThriftGenPy")
    CreateIFMapBuilder(env)
    CreateTypeBuilder(env)
    CreateDeviceAPIBuilder(env)

    PyTestSuiteCovBuilder = Builder(action=PyTestSuiteCov)
    env.Append(BUILDERS={'PyTestSuiteCov': PyTestSuiteCovBuilder})

    # Not used?
    symlink_builder = Builder(action="cd ${TARGET.dir} && " +
                              "ln -s ${SOURCE.file} ${TARGET.file}")
    env.Append(BUILDERS={'Symlink': symlink_builder})

    env.AddMethod(UseSystemBoost, "UseSystemBoost")
    env.AddMethod(UseSystemTBB, "UseSystemTBB")
    env.AddMethod(UseCassandraCql, "UseCassandraCql")
    env.AddMethod(CppDisableExceptions, "CppDisableExceptions")
    env.AddMethod(CppEnableExceptions, "CppEnableExceptions")
    return env
Beispiel #4
0
def SetupBuildEnvironment(conf):
    AddOption(
        '--optimization',
        dest='opt',
        action='store',
        default='debug',
        choices=['debug', 'production', 'coverage', 'profile', 'valgrind'],
        help='optimization level: [debug|production|coverage|profile|valgrind]'
    )

    AddOption('--target',
              dest='target',
              action='store',
              choices=['i686', 'x86_64', 'armhf'])

    AddOption('--root', dest='install_root', action='store')
    AddOption('--prefix', dest='install_prefix', action='store')
    AddOption('--pytest', dest='pytest', action='store')

    env = CheckBuildConfiguration(conf)

    env.AddMethod(PlatformExclude, "PlatformExclude")
    env.AddMethod(GetPlatformInfo, "GetPlatformInfo")
    env.AddMethod(create_if_needed_dir, "CreateDirectory")
    # Let's decide how many jobs (-jNN) we should use.
    nj = GetOption('num_jobs')
    if nj == 1:
        # Should probably check for CLI over-ride of -j1 (i.e., do not
        # assume 1 means -j not specified).
        nj = determine_job_value()
        if nj > 1:
            print "scons: setting jobs (-j) to %d" % nj
            SetOption('num_jobs', nj)
            env['NUM_JOBS'] = nj

    env['OPT'] = GetOption('opt')
    #    env['TARGET_MACHINE'] = GetOption('target')
    env['INSTALL_PREFIX'] = GetOption('install_prefix')
    env['INSTALL_BIN'] = ''
    env['INSTALL_SHARE'] = ''
    env['INSTALL_LIB'] = ''
    env['INSTALL_INIT'] = ''
    env['INSTALL_INITD'] = ''
    env['INSTALL_CONF'] = ''
    env['INSTALL_EXAMPLE'] = ''
    env['PYTHON_INSTALL_OPT'] = ''
    env['INSTALL_DOC'] = ''

    install_root = GetOption('install_root')
    if install_root:
        env['INSTALL_BIN'] = install_root
        env['INSTALL_SHARE'] = install_root
        env['INSTALL_LIB'] = install_root
        env['INSTALL_INIT'] = install_root
        env['INSTALL_INITD'] = install_root
        env['INSTALL_CONF'] = install_root
        env['INSTALL_EXAMPLE'] = install_root
        env['INSTALL_DOC'] = install_root
        env['PYTHON_INSTALL_OPT'] = '--root ' + install_root + ' '

    install_prefix = GetOption('install_prefix')
    if install_prefix:
        env['INSTALL_BIN'] += install_prefix
        env['INSTALL_SHARE'] += install_prefix
        env['INSTALL_LIB'] += install_prefix
        env['INSTALL_INIT'] += install_prefix
        env['INSTALL_INITD'] += install_prefix
        env['PYTHON_INSTALL_OPT'] += '--prefix ' + install_prefix + ' '
    elif install_root:
        env['INSTALL_BIN'] += '/usr'
        env['INSTALL_SHARE'] += '/usr'
        env['INSTALL_LIB'] += '/usr'
        env['PYTHON_INSTALL_OPT'] += '--prefix /usr '
    else:
        env['INSTALL_BIN'] += '/usr/local'

    env['INSTALL_BIN'] += '/bin'
    env['INSTALL_SHARE'] += '/share'
    env['INSTALL_LIB'] += '/lib'
    env['INSTALL_INIT'] += '/etc/init'
    env['INSTALL_INITD'] += '/etc/init.d'
    env['INSTALL_CONF'] += '/etc/contrail'
    env['INSTALL_EXAMPLE'] += '/usr/share/contrail'
    env['INSTALL_DOC'] += '/usr/share/doc'

    distribution = env.GetPlatformInfo()[0]

    if distribution in ["Ubuntu", "debian", "raspbian"]:
        env['PYTHON_INSTALL_OPT'] += '--install-layout=deb '

    if distribution == 'Darwin':
        PlatformDarwin(env)
        env['ENV_SHLIB_PATH'] = 'DYLD_LIBRARY_PATH'
    else:
        env['ENV_SHLIB_PATH'] = 'LD_LIBRARY_PATH'

    if env.get('TARGET_MACHINE') == 'i686':
        env.Append(CCFLAGS='-march=' + 'i686')
    elif env.get('TARGET_MACHINE') == 'armhf' or platform.machine().startswith(
            'arm'):
        env.Append(
            CCFLAGS=['-DTBB_USE_GCC_BUILTINS=1', '-D__TBB_64BIT_ATOMICS=0'])

    env['TOP_BIN'] = '#build/bin'
    env['TOP_INCLUDE'] = '#build/include'
    env['TOP_LIB'] = '#build/lib'

    pytest = GetOption('pytest')
    if pytest:
        env['PYTESTARG'] = pytest
    else:
        env['PYTESTARG'] = None

    # Store path to sandesh compiler in the env
    env['SANDESH'] = os.path.join(env.Dir(env['TOP_BIN']).path, 'sandesh.exe')

    # Store the hostname in env.
    try:
        build_host = env['HOSTNAME'] if 'HOSTNAME' in env else platform.node()
    except KeyError:
        build_host = platform.uname()
    env['HOSTNAME'] = build_host

    # Store repo projects in the environment
    proc = subprocess.Popen('repo list',
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell='True')
    repo_out, err = proc.communicate()
    repo_lines = repo_out.splitlines()
    repo_list = {}
    for l in repo_lines:
        (path, repo) = l.split(" : ")
        repo_list[path] = repo
    env['REPO_PROJECTS'] = repo_list
    env['CC'] = 'cl.exe'
    env['CXX'] = 'cl.exe'
    env['TARGET_ARCH'] = 'x64'
    env['TARGET_CONFIG'] = 'debug'

    env['CCPDBFLAGS'] = '/Z7'
    opt_level = env['OPT']
    env['OBJSUFFIX'] = '.o'
    # /GS /analyze- /W3 /Zc:wchar_t /ZI /Gm /Od /Fd"Debug\vc140.pdb" /Zc:inline /fp:precise /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\compilerproj.pch"
    env.Append(
        CCFLAGS=
        '/Iwindows /GS /analyze- /w /Zc:wchar_t /Od /Zc:inline /fp:precise /D_WIN32_WINNT=0x0601 /D "_WINDOWS" /D "WIN32" /D "CURL_STATICLIB" /D "_DEBUG" /D "_CONSOLE" /errorReport:prompt /WX- /w /wd4996 /wd4150 /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc '
    )
    env['CCFLAGS'].remove('/nologo')
    env['LINKFLAGS'].remove('/nologo')
    env['ARFLAGS'].remove('/nologo')
    env.Append(LINKFLAGS='/MACHINE:' + env['TARGET_ARCH'])
    env.Append(ARFLAGS='/MACHINE:' + env['TARGET_ARCH'])

    opt_level = env['OPT']
    if opt_level == 'production':
        env.Append(CCFLAGS='-g -O3')
        env.Append(LINKFLAGS=['-g'])
        env['TOP'] = '#build/production'
    elif opt_level == 'debug':
        env.Append(CCFLAGS=['/D "_DEBUG"'])
        env.Append(LINKFLAGS=['/DEBUG'])
        env['TOP'] = '#build/debug'
    elif opt_level == 'profile':
        # Enable profiling through gprof
        env.Append(CCFLAGS=['-g', '-O3', '-DDEBUG', '-pg'])
        env.Append(LINKFLAGS=['-pg'])
        env['TOP'] = '#build/profile'
    elif opt_level == 'coverage':
        env.Append(CCFLAGS=['-g', '-O0', '--coverage'])
        env.Append(LINKFLAGS=['-g'])
        env['TOP'] = '#build/coverage'
        env.Append(LIBS='gcov')
    elif opt_level == 'valgrind':
        env.Append(CCFLAGS=['-g', '-O0', '-DDEBUG'])
        env.Append(LINKFLAGS=['-g'])
        env['TOP'] = '#build/valgrind'

    env.Append(BUILDERS={'PyTestSuite': PyTestSuite})
    env.Append(BUILDERS={'TestSuite': TestSuite})
    env.Append(BUILDERS={'UnitTest': UnitTest})
    env.Append(BUILDERS={'GenerateBuildInfoCode': GenerateBuildInfoCode})
    env.Append(BUILDERS={'GenerateBuildInfoPyCode': GenerateBuildInfoPyCode})
    env.Append(BUILDERS={'GenerateBuildInfoCCode': GenerateBuildInfoCCode})

    env.Append(BUILDERS={'setup_venv': setup_venv})
    env.Append(BUILDERS={'venv_add_pip_pkg': venv_add_pip_pkg})
    env.Append(BUILDERS={'venv_add_build_pkg': venv_add_build_pkg})
    env.Append(BUILDERS={'build_maven': build_maven})

    env.AddMethod(SymLink, "SymLink")
    env.AddMethod(ExtractCppFunc, "ExtractCpp")
    env.AddMethod(ExtractCFunc, "ExtractC")
    env.AddMethod(ExtractHeaderFunc, "ExtractHeader")
    env.AddMethod(ProtocGenDescFunc, "ProtocGenDesc")
    env.AddMethod(ProtocGenCppFunc, "ProtocGenCpp")
    env.AddMethod(SandeshGenOnlyCppFunc, "SandeshGenOnlyCpp")
    env.AddMethod(SandeshGenCppFunc, "SandeshGenCpp")
    env.AddMethod(SandeshGenCFunc, "SandeshGenC")
    env.AddMethod(SandeshGenPyFunc, "SandeshGenPy")
    env.AddMethod(SandeshGenDocFunc, "SandeshGenDoc")
    env.AddMethod(ThriftGenCppFunc, "ThriftGenCpp")
    ThriftSconsEnvPyFunc(env)
    env.AddMethod(ThriftGenPyFunc, "ThriftGenPy")
    CreateIFMapBuilder(env)
    CreateTypeBuilder(env)

    PyTestSuiteCovBuilder = Builder(action=PyTestSuiteCov)
    env.Append(BUILDERS={'PyTestSuiteCov': PyTestSuiteCovBuilder})

    # Not used?
    symlink_builder = Builder(action="cd ${TARGET.dir} && " +
                              "ln -s ${SOURCE.file} ${TARGET.file}")
    env.Append(BUILDERS={'Symlink': symlink_builder})

    env.AddMethod(UseSystemBoost, "UseSystemBoost")
    env.AddMethod(UseSystemTBB, "UseSystemTBB")
    env.AddMethod(UseCassandraCql, "UseCassandraCql")
    env.AddMethod(CppDisableExceptions, "CppDisableExceptions")
    env.AddMethod(CppEnableExceptions, "CppEnableExceptions")
    if os.name == "nt":

        def symlink_ms(source, link_name):
            import ctypes
            kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
            csl = kernel32.CreateSymbolicLinkW
            csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p,
                            ctypes.c_uint32)
            csl.restype = ctypes.c_ubyte
            source = source.replace('/', '\\')
            print "Creating symbolic link:%s  ----> %s" % (source, link_name)
            if not os.path.exists(source):
                print "ERROR: dir %s does not exist" % source
                quit()
            print source, os.path.isdir(source)
            IsDir = 1 if os.path.isdir(source) else 0
            try:
                if csl(link_name, source, IsDir) == 0:
                    #                 print get_last_error()
                    raise ctypes.WinError()
                print "SUCCESS: created symbolic link:%s  ----> %s" % (
                    source, link_name)
            except Exception as e:
                print "ERROR: could not create symbolic link:%s  ----> %s" % (
                    source, link_name)
                print(e)

        os.symlink = symlink_ms
    return env