Example #1
0
def _PostParseCheck(options, _args):
    """Perform some usage validation (after we've parsed the arguments

  Args:
    options/args: The options/args object returned by optparse
  """
    if options.local_pkg_path and not os.path.isfile(options.local_pkg_path):
        cros_build_lib.Die('%s is not a file.', options.local_pkg_path)

    if not options.gyp_defines:
        gyp_env = os.getenv('GYP_DEFINES', None)
        if gyp_env is not None:
            options.gyp_defines = chrome_util.ProcessGypDefines(gyp_env)
            logging.debug('GYP_DEFINES taken from environment: %s',
                          options.gyp_defines)

    if options.strict and not options.gyp_defines:
        cros_build_lib.Die('When --strict is set, the GYP_DEFINES environment '
                           'variable must be set.')

    if options.build_dir:
        chrome_path = os.path.join(options.build_dir, 'chrome')
        if os.path.isfile(chrome_path):
            deps = lddtree.ParseELF(chrome_path)
            if 'libbase.so' in deps['libs']:
                cros_build_lib.Warning(
                    'Detected a component build of Chrome.  component build is '
                    'not working properly for Chrome OS.  See crbug.com/196317.  '
                    'Use at your own risk!')
Example #2
0
def _PostParseCheck(options):
    """Perform some usage validation (after we've parsed the arguments).

  Args:
    options: The options object returned by the cli parser.
  """
    if options.local_pkg_path and not os.path.isfile(options.local_pkg_path):
        cros_build_lib.Die('%s is not a file.', options.local_pkg_path)

    if not options.gyp_defines:
        gyp_env = os.getenv('GYP_DEFINES')
        if gyp_env is not None:
            options.gyp_defines = chrome_util.ProcessGypDefines(gyp_env)
            logging.info('GYP_DEFINES taken from environment: %s',
                         options.gyp_defines)

    if not options.gn_args:
        gn_env = os.getenv('GN_ARGS')
        if gn_env is not None:
            options.gn_args = gn_helpers.FromGNArgs(gn_env)
            logging.info('GN_ARGS taken from environment: %s', options.gn_args)

    if not options.staging_flags:
        use_env = os.getenv('USE')
        if use_env is not None:
            options.staging_flags = ' '.join(
                set(use_env.split()).intersection(chrome_util.STAGING_FLAGS))
            logging.info('Staging flags taken from USE in environment: %s',
                         options.staging_flags)
Example #3
0
    def testGomaInPath(self, inverted=False):
        """Verify that we do indeed add Goma to the PATH."""
        extra_args = ['--nogoma'] if inverted else None
        self.SetupCommandMock(extra_args)
        self.cmd_mock.inst.Run()

        assert_fn = self.assertNotIn if inverted else self.assertIn
        gyp_defines_str = self.cmd_mock.env['GYP_DEFINES']
        gyp_defines = chrome_util.ProcessGypDefines(gyp_defines_str)
        assert_fn('gomadir', gyp_defines)
        assert_fn('use_goma', gyp_defines)
Example #4
0
def _PostParseCheck(options, _args):
    """Perform some usage validation (after we've parsed the arguments

  Args:
    options/args: The options/args object returned by optparse
  """
    if options.local_pkg_path and not os.path.isfile(options.local_pkg_path):
        cros_build_lib.Die('%s is not a file.', options.local_pkg_path)

    if options.strict and not options.gyp_defines:
        gyp_env = os.getenv('GYP_DEFINES', None)
        if gyp_env is not None:
            options.gyp_defines = chrome_util.ProcessGypDefines(gyp_env)
            logging.info('GYP_DEFINES taken from environment: %s',
                         options.gyp_defines)
        else:
            cros_build_lib.Die(
                'When --strict is set, the GYP_DEFINES environment '
                'variable must be set.')
Example #5
0
    def _SetupEnvironment(self, board, version, key_map):
        """Sets environment variables to export to the SDK shell."""
        sysroot = key_map[constants.CHROME_SYSROOT_TAR].path
        environment = os.path.join(key_map[constants.CHROME_ENV_TAR].path,
                                   'environment')
        target_tc = key_map[self.sdk.TARGET_TOOLCHAIN_KEY].path

        env = osutils.SourceEnvironment(environment, self.EBUILD_ENV)

        os.environ[self.sdk.SDK_VERSION_ENV] = version
        os.environ[self.sdk.SDK_BOARD_ENV] = board
        # SYSROOT is necessary for Goma and the sysroot wrapper.
        env['SYSROOT'] = sysroot
        gyp_dict = chrome_util.ProcessGypDefines(env['GYP_DEFINES'])
        gyp_dict['sysroot'] = sysroot
        gyp_dict.pop('order_text_section', None)
        env['GYP_DEFINES'] = chrome_util.DictToGypDefines(gyp_dict)

        for tc_path in (target_tc, ):
            env['PATH'] = '%s:%s' % (os.path.join(tc_path,
                                                  'bin'), os.environ['PATH'])

        for var in ('CXX', 'CC', 'LD'):
            env[var] = self._FixGoldPath(env[var], target_tc)

        env['CXX_host'] = 'g++'
        env['CC_host'] = 'gcc'

        # PS1 sets the command line prompt and xterm window caption.
        env['PS1'] = self._CreatePS1(self.board, version)

        out_dir = 'out_%s' % self.board
        env['builddir_name'] = out_dir
        env['GYP_GENERATORS'] = 'ninja'
        env['GYP_GENERATOR_FLAGS'] = 'output_dir=%s' % out_dir
        return env
Example #6
0
    def _SetupEnvironment(self,
                          board,
                          sdk_ctx,
                          options,
                          goma_dir=None,
                          goma_port=None):
        """Sets environment variables to export to the SDK shell."""
        if options.chroot:
            sysroot = os.path.join(options.chroot, 'build', board)
            if not os.path.isdir(sysroot) and not options.cmd:
                logging.warning(
                    "Because --chroot is set, expected a sysroot to be at "
                    "%s, but couldn't find one.", sysroot)
        else:
            sysroot = sdk_ctx.key_map[constants.CHROME_SYSROOT_TAR].path

        environment = os.path.join(
            sdk_ctx.key_map[constants.CHROME_ENV_TAR].path, 'environment')
        if options.chroot:
            # Override with the environment from the chroot if available (i.e.
            # build_packages or emerge chromeos-chrome has been run for |board|).
            env_path = os.path.join(sysroot, 'var', 'db', 'pkg',
                                    'chromeos-base', 'chromeos-chrome-*')
            env_glob = glob.glob(env_path)
            if len(env_glob) != 1:
                logging.warning(
                    'Multiple Chrome versions in %s. This can be resolved'
                    ' by running "eclean-$BOARD -d packages". Using'
                    ' environment from: %s', env_path, environment)
            elif not os.path.isdir(env_glob[0]):
                logging.warning(
                    'Environment path not found: %s. Using enviroment from:'
                    ' %s.', env_path, environment)
            else:
                chroot_env_file = os.path.join(env_glob[0], 'environment.bz2')
                if os.path.isfile(chroot_env_file):
                    # Log a warning here since this is new behavior that is not obvious.
                    logging.notice('Environment fetched from: %s',
                                   chroot_env_file)
                    # Uncompress enviornment.bz2 to pass to osutils.SourceEnvironment.
                    chroot_cache = os.path.join(self.options.cache_dir,
                                                COMMAND_NAME, 'chroot')
                    osutils.SafeMakedirs(chroot_cache)
                    environment = os.path.join(chroot_cache,
                                               'environment_%s' % board)
                    cros_build_lib.UncompressFile(chroot_env_file, environment)

        env = osutils.SourceEnvironment(environment, self.EBUILD_ENV)
        self._SetupTCEnvironment(sdk_ctx, options, env)

        # Add managed components to the PATH.
        env['PATH'] = '%s:%s' % (constants.CHROMITE_BIN_DIR, env['PATH'])
        env['PATH'] = '%s:%s' % (os.path.dirname(
            self.sdk.gs_ctx.gsutil_bin), env['PATH'])

        # Export internally referenced variables.
        os.environ[self.sdk.SDK_BOARD_ENV] = board
        if self.options.sdk_path:
            os.environ[self.sdk.SDK_PATH_ENV] = self.options.sdk_path
        os.environ[self.sdk.SDK_VERSION_ENV] = sdk_ctx.version

        # Export the board/version info in a more accessible way, so developers can
        # reference them in their chrome_sdk.bashrc files, as well as within the
        # chrome-sdk shell.
        for var in [self.sdk.SDK_VERSION_ENV, self.sdk.SDK_BOARD_ENV]:
            env[var.lstrip('%')] = os.environ[var]

        # Export Goma information.
        if goma_dir:
            env[self.SDK_GOMA_DIR_ENV] = goma_dir
            env[self.SDK_GOMA_PORT_ENV] = goma_port

        # SYSROOT is necessary for Goma and the sysroot wrapper.
        env['SYSROOT'] = sysroot
        gyp_dict = chrome_util.ProcessGypDefines(env['GYP_DEFINES'])
        gn_args = gn_helpers.FromGNArgs(env['GN_ARGS'])
        gyp_dict['sysroot'] = sysroot
        gn_args['target_sysroot'] = sysroot
        gyp_dict.pop('pkg-config', None)
        gn_args.pop('pkg_config', None)
        if options.clang:
            gyp_dict['clang'] = 1
            gn_args['is_clang'] = True
        if options.internal:
            gyp_dict['branding'] = 'Chrome'
            gn_args['is_chrome_branded'] = True
            gyp_dict['buildtype'] = 'Official'
            gn_args['is_official_build'] = True
        else:
            gyp_dict.pop('branding', None)
            gn_args.pop('is_chrome_branded', None)
            gyp_dict.pop('buildtype', None)
            gn_args.pop('is_official_build', None)
            gyp_dict.pop('internal_gles2_conform_tests', None)
            gn_args.pop('internal_gles2_conform_tests', None)
        if options.component:
            gyp_dict['component'] = 'shared_library'
            gn_args['is_component_build'] = True
        if options.fastbuild:
            gyp_dict['fastbuild'] = 1
            gyp_dict.pop('release_extra_cflags', None)
            # symbol_level corresponds to GYP's fastbuild (https://goo.gl/ZC4fUO).
            gn_args['symbol_level'] = 1
        else:
            # Enable debug fission for GN.
            gn_args['use_debug_fission'] = True

        # For SimpleChrome, we use the binutils that comes bundled within Chrome.
        # We should not use the binutils from the host system.
        gn_args['linux_use_bundled_binutils'] = True

        gyp_dict['host_clang'] = 1
        # Need to reset these after the env vars have been fixed by
        # _SetupTCEnvironment.
        gn_args['cros_host_is_clang'] = True
        gn_args['cros_target_cc'] = env['CC']
        gn_args['cros_target_cxx'] = env['CXX']
        gn_args['cros_target_ld'] = env['LD']
        # We need to reset extra C/CXX flags to remove references to
        # EBUILD_CFLAGS, EBUILD_CXXFLAGS
        gn_args['cros_target_extra_cflags'] = env['CFLAGS']
        gn_args['cros_target_extra_cxxflags'] = env['CXXFLAGS']
        gn_args['cros_host_cc'] = env['CC_host']
        gn_args['cros_host_cxx'] = env['CXX_host']
        gn_args['cros_host_ld'] = env['LD_host']
        gn_args['cros_host_ar'] = env['AR_host']
        gn_args['cros_v8_snapshot_cc'] = env['CC_host']
        gn_args['cros_v8_snapshot_cxx'] = env['CXX_host']
        gn_args['cros_v8_snapshot_ld'] = env['LD_host']
        gn_args['cros_v8_snapshot_ar'] = env['AR_host']
        # No need to adjust CFLAGS and CXXFLAGS for GN since the only
        # adjustment made in _SetupTCEnvironment is for split debug which
        # is done with 'use_debug_fission'.

        # Enable goma if requested.
        if goma_dir:
            gyp_dict['use_goma'] = 1
            gn_args['use_goma'] = True
            gyp_dict['gomadir'] = goma_dir
            gn_args['goma_dir'] = goma_dir

        gn_args.pop('internal_khronos_glcts_tests', None)  # crbug.com/588080

        env['GYP_DEFINES'] = chrome_util.DictToGypDefines(gyp_dict)
        env['GN_ARGS'] = gn_helpers.ToGNString(gn_args)

        # PS1 sets the command line prompt and xterm window caption.
        full_version = sdk_ctx.version
        if full_version != CUSTOM_VERSION:
            full_version = self.sdk.GetFullVersion(sdk_ctx.version)
        env['PS1'] = self._CreatePS1(self.board,
                                     full_version,
                                     chroot=options.chroot)

        out_dir = 'out_%s' % self.board
        env['builddir_name'] = out_dir
        env['GYP_GENERATOR_FLAGS'] = 'output_dir=%s' % out_dir
        env['GYP_CROSSCOMPILE'] = '1'

        # deploy_chrome relies on the 'gn' USE flag to locate .so (and potentially
        # other) files. Set this by default if GYP_CHROMIUM_NO_ACTION=1.
        # TODO(stevenjb): Maybe figure out a better way to set this by default.
        if os.environ.get('GYP_CHROMIUM_NO_ACTION', '') == '1':
            env['USE'] = 'gn'
            logging.notice(
                'GYP_CHROMIUM_NO_ACTION=1, setting USE="gn" for deploy_chrome.'
            )

        return env
Example #7
0
def ValidateGypDefines(value):
    """Convert GYP_DEFINES-formatted string to dictionary."""
    return chrome_util.ProcessGypDefines(value)
Example #8
0
    def _SetupEnvironment(self,
                          board,
                          sdk_ctx,
                          options,
                          goma_dir=None,
                          goma_port=None):
        """Sets environment variables to export to the SDK shell."""
        if options.chroot:
            sysroot = os.path.join(options.chroot, 'build', board)
            if not os.path.isdir(sysroot) and not options.cmd:
                logging.warning(
                    "Because --chroot is set, expected a sysroot to be at "
                    "%s, but couldn't find one.", sysroot)
        else:
            sysroot = sdk_ctx.key_map[constants.CHROME_SYSROOT_TAR].path

        environment = os.path.join(
            sdk_ctx.key_map[constants.CHROME_ENV_TAR].path, 'environment')
        env = osutils.SourceEnvironment(environment, self.EBUILD_ENV)
        self._SetupTCEnvironment(sdk_ctx, options, env, goma_dir=goma_dir)

        # Add managed components to the PATH.
        env['PATH'] = '%s:%s' % (constants.CHROMITE_BIN_DIR, env['PATH'])

        # Export internally referenced variables.
        os.environ[self.sdk.SDK_VERSION_ENV] = sdk_ctx.version
        os.environ[self.sdk.SDK_BOARD_ENV] = board
        # Export the board/version info in a more accessible way, so developers can
        # reference them in their chrome_sdk.bashrc files, as well as within the
        # chrome-sdk shell.
        for var in [self.sdk.SDK_VERSION_ENV, self.sdk.SDK_BOARD_ENV]:
            env[var.lstrip('%')] = os.environ[var]

        # Export Goma information.
        if goma_dir:
            env[self.SDK_GOMA_DIR_ENV] = goma_dir
            env[self.SDK_GOMA_PORT_ENV] = goma_port

        # SYSROOT is necessary for Goma and the sysroot wrapper.
        env['SYSROOT'] = sysroot
        gyp_dict = chrome_util.ProcessGypDefines(env['GYP_DEFINES'])
        gyp_dict['sysroot'] = sysroot
        gyp_dict.pop('order_text_section', None)
        if options.clang:
            gyp_dict['clang'] = 1
            gyp_dict['werror'] = ''
            gyp_dict['clang_use_chrome_plugins'] = 0
            gyp_dict['linux_use_tcmalloc'] = 0
        if options.internal:
            gyp_dict['branding'] = 'Chrome'
            gyp_dict['buildtype'] = 'Official'
        else:
            gyp_dict.pop('branding', None)
            gyp_dict.pop('buildtype', None)

        env['GYP_DEFINES'] = chrome_util.DictToGypDefines(gyp_dict)

        # PS1 sets the command line prompt and xterm window caption.
        env['PS1'] = self._CreatePS1(self.board,
                                     self.sdk.GetFullVersion(sdk_ctx.version),
                                     chroot=options.chroot)

        out_dir = 'out_%s' % self.board
        env['builddir_name'] = out_dir
        env['GYP_GENERATORS'] = 'make' if options.make else 'ninja'
        env['GYP_GENERATOR_FLAGS'] = 'output_dir=%s' % out_dir
        return env