Esempio n. 1
0
def main_xcode(options, args):
  """Interprets options, clobbers object files, and calls xcodebuild.
  """

  env = EchoDict(os.environ)
  goma_ready = goma_setup(options, env)
  if not goma_ready:
    assert options.compiler not in ('goma', 'goma-clang')
    assert options.goma_dir is None

  # Print some basic information about xcodebuild to ease debugging.
  chromium_utils.RunCommand(['xcodebuild', '-sdk', '-version'], env=env)

  # If the project isn't in args, add all.xcodeproj to simplify configuration.
  command = ['xcodebuild', '-configuration', options.target]

  # TODO(mmoss) Support the old 'args' usage until we're confident the master is
  # switched to passing '--solution' everywhere.
  if not '-project' in args:
    # TODO(mmoss) Temporary hack to ignore the Windows --solution flag that is
    # passed to all builders. This can be taken out once the master scripts are
    # updated to only pass platform-appropriate --solution values.
    if (not options.solution or
        os.path.splitext(options.solution)[1] != '.xcodeproj'):
      options.solution = '../build/all.xcodeproj'
    command.extend(['-project', options.solution])

  if options.xcode_target:
    command.extend(['-target', options.xcode_target])

  # Note: this clobbers all targets, not just Debug or Release.
  if options.clobber:
    clobber_dir = os.path.dirname(options.target_output_dir)
    print 'Removing %s' % clobber_dir
    # Deleting output_dir would also delete all the .ninja files. iOS builds
    # generates ninja configuration inside the xcodebuild directory to be able
    # to run sub builds. crbug.com/138950 is tracking this issue.
    # Moreover clobbering should run before runhooks (which creates
    # .ninja files). For now, only delete all non-.ninja files.
    # TODO(thakis): Make "clobber" a step that runs before "runhooks". Once the
    # master has been restarted, remove all clobber handling from compile.py.
    build_directory.RmtreeExceptNinjaOrGomaFiles(clobber_dir)

  common_xcode_settings(command, options, env, options.compiler)
  maybe_set_official_build_envvars(options, env)

  # Add on any remaining args
  command.extend(args)

  # Set up the filter before changing directories so the raw build log can
  # be recorded.
  # Support a local file blocking filters (for debugging).  Also check the
  # Xcode version to make sure it is 3.2, as that is what the filter is coded
  # to.
  xcodebuild_filter = None
  no_filter_path = os.path.join(os.getcwd(), 'no_xcodebuild_filter')
  xcode_info = chromium_utils.GetCommandOutput(['xcodebuild', '-version'])
  if os.path.exists(no_filter_path):
    print 'NOTE: "%s" exists, output is unfiltered' % no_filter_path
  elif not xcode_info.startswith('Xcode 3.2.'):
    # Note: The filter sometimes hides real errors on 4.x+, see crbug.com/260989
    print 'NOTE: Not using Xcode 3.2, output is unfiltered'
  else:
    full_log_path = os.path.join(os.getcwd(), 'full_xcodebuild_log.txt')
    full_log = open(full_log_path, 'w')
    now = datetime.datetime.now()
    full_log.write('Build started ' + now.isoformat() + '\n\n\n')
    print 'NOTE: xcodebuild output filtered, full log at: "%s"' % full_log_path
    xcodebuild_filter = XcodebuildFilter(full_log)

  try:
    os.makedirs(options.build_dir)
  except OSError, e:
    if e.errno != errno.EEXIST:
      raise
def main_ninja(options, args):
    """Interprets options, clobbers object files, and calls ninja."""

    # Prepare environment.
    env = EchoDict(os.environ)
    goma_ready, goma_cloudtail = goma_setup(options, env)
    exit_status = -1
    try:
        if not goma_ready:
            assert options.compiler not in ('goma', 'goma-clang')
            assert options.goma_dir is None

        # ninja is different from all the other build systems in that it requires
        # most configuration to be done at gyp time. This is why this function does
        # less than the other comparable functions in this file.
        print 'chdir to %s' % options.src_dir
        os.chdir(options.src_dir)

        command = [
            options.ninja_path, '-w', 'dupbuild=err', '-C',
            options.target_output_dir
        ]

        # HACK(yyanagisawa): update environment files on |env| update.
        # For compiling on Windows, environment in environment files are used.
        # It means even if enviroment such as GOMA_DISABLED is updated in
        # compile.py, the update will be ignored.
        # We need to update environment files to reflect the update.
        if chromium_utils.IsWindows() and NeedEnvFileUpdateOnWin(env):
            print 'Updating environment.{x86,x64} files.'
            UpdateWindowsEnvironment(options.target_output_dir, env)

        if options.clobber:
            print 'Removing %s' % options.target_output_dir
            # Deleting output_dir would also delete all the .ninja files necessary to
            # build. Clobbering should run before runhooks (which creates .ninja
            # files). For now, only delete all non-.ninja files.
            # TODO(thakis): Make "clobber" a step that runs before "runhooks".
            # Once the master has been restarted, remove all clobber handling
            # from compile.py, https://crbug.com/574557
            build_directory.RmtreeExceptNinjaOrGomaFiles(
                options.target_output_dir)

        command.extend(options.build_args)
        command.extend(args)

        maybe_set_official_build_envvars(options, env)

        if options.compiler:
            print 'using', options.compiler

        if options.compiler in ('goma', 'goma-clang'):
            assert options.goma_dir

            def determine_goma_jobs():
                # We would like to speed up build on Windows a bit, since it is slowest.
                number_of_processors = 0
                try:
                    number_of_processors = multiprocessing.cpu_count()
                except NotImplementedError:
                    print 'cpu_count() is not implemented, using default value 50.'
                    return 50

                assert number_of_processors > 0

                # When goma is used, 10 * number_of_processors is basically good in
                # various situations according to our measurement. Build speed won't
                # be improved if -j is larger than that.
                #
                # Since Mac had process number limitation before, we had to set
                # the upper limit to 50. Now that the process number limitation is 2000,
                # so we would be able to use 10 * number_of_processors.
                # For the safety, we'd like to set the upper limit to 200.
                #
                # Note that currently most try-bot build slaves have 8 processors.
                if chromium_utils.IsMac() or chromium_utils.IsWindows():
                    return min(10 * number_of_processors, 200)

                # For Linux, we also would like to use 10 * cpu. However, not sure
                # backend resource is enough, so let me set Linux and Linux x64 builder
                # only for now.
                hostname = goma_utils.GetShortHostname()
                if hostname in (
                    ['build14-m1', 'build48-m1'] +
                        # Also increasing cpus for v8/blink trybots.
                    ['build%d-m4' % x for x in xrange(45, 48)] +
                        # Also increasing cpus for LTO buildbots.
                    ['slave%d-c1' % x for x in [20, 33] + range(78, 108)]):
                    return min(10 * number_of_processors, 200)

                return 50

            goma_jobs = determine_goma_jobs()
            command.append('-j%d' % goma_jobs)

        # Run the build.
        env.print_overrides()
        exit_status = chromium_utils.RunCommand(command, env=env)
        if exit_status == 0 and options.ninja_ensure_up_to_date:
            # Run the build again if we want to check that the no-op build is clean.
            filter_obj = EnsureUpToDateFilter()
            # Append `-d explain` to help diagnose in the failure case.
            command += ['-d', 'explain']
            chromium_utils.RunCommand(command, env=env, filter_obj=filter_obj)
            if not filter_obj.was_up_to_date:
                print 'Failing build because ninja reported work to do.'
                print 'This means that after completing a compile, another was run and'
                print 'it resulted in still having work to do (that is, a no-op build'
                print 'wasn\'t a no-op). Consult the first "ninja explain:" line for a'
                print 'likely culprit.'
                return 1
        return exit_status
    finally:
        goma_teardown(options, env, exit_status, goma_cloudtail)

        override_gsutil = None
        if options.gsutil_py_path:
            override_gsutil = [sys.executable, options.gsutil_py_path]

        goma_utils.UploadNinjaLog(options.target_output_dir,
                                  options.compiler,
                                  command,
                                  exit_status,
                                  override_gsutil=override_gsutil)
Esempio n. 3
0
def main_ninja(options, args, env):
  """This function calls ninja.

  Args:
      options (Option): options for ninja command.
      args (str): extra args for ninja command.
      env (dict): Used when ninja command executes.

  Returns:
      int: ninja command exit status.

  """

  exit_status = -1

  try:
    print 'chdir to %s' % options.src_dir
    os.chdir(options.src_dir)

    command = [options.ninja_path, '-w', 'dupbuild=err',
                                   '-C', options.target_output_dir]

    # HACK(yyanagisawa): update environment files on |env| update.
    # For compiling on Windows, environment in environment files are used.
    # It means even if enviroment such as GOMA_DISABLED is updated in
    # compile.py, the update will be ignored.
    # We need to update environment files to reflect the update.
    if (chromium_utils.IsWindows() and
        update_windows_env.NeedEnvFileUpdateOnWin(env.overrides)):
      print 'Updating environment.{x86,x64} files.'
      update_windows_env.UpdateWindowsEnvironment(
          options.target_output_dir, env, env.overrides)

    if options.clobber:
      print 'Removing %s' % options.target_output_dir
      # Deleting output_dir would also delete all the .ninja files necessary to
      # build. Clobbering should run before runhooks (which creates .ninja
      # files). For now, only delete all non-.ninja files.
      # TODO(thakis): Make "clobber" a step that runs before "runhooks".
      # Once the master has been restarted, remove all clobber handling
      # from compile.py, https://crbug.com/574557
      build_directory.RmtreeExceptNinjaOrGomaFiles(options.target_output_dir)

    command.extend(options.build_args)
    command.extend(args)

    maybe_set_official_build_envvars(options, env)

    if options.compiler:
      print 'using', options.compiler

    if options.compiler in ('goma', 'goma-clang'):
      assert options.goma_dir
      assert options.goma_jobs
      command.append('-j%d' % options.goma_jobs)

    # Run the build.
    env.print_overrides()
    exit_status = chromium_utils.RunCommand(command, env=env)
    if exit_status == 0:
      # Run the build again if we want to check that the no-op build is clean.
      filter_obj = EnsureUpToDateFilter()
      # Append `-d explain` to help diagnose in the failure case.
      command += ['-d', 'explain', '-n']
      chromium_utils.RunCommand(command, env=env, filter_obj=filter_obj)
      if not filter_obj.was_up_to_date and options.ninja_ensure_up_to_date:
        print 'Failing build because ninja reported work to do.'
        print 'This means that after completing a compile, another was run and'
        print 'it resulted in still having work to do (that is, a no-op build'
        print 'wasn\'t a no-op). Consult the first "ninja explain:" line for a'
        print 'likely culprit.'
        return 1
    return exit_status
  finally:
    override_gsutil = None
    if options.gsutil_py_path:
      # Needs to add '--', otherwise gsutil options will be passed to gsutil.py.
      override_gsutil = [sys.executable, options.gsutil_py_path, '--']

    goma_utils.UploadNinjaLog(
        options.target_output_dir, options.compiler, command, exit_status,
        override_gsutil=override_gsutil)