Beispiel #1
0
def ProcessOptions(options, args):
    # Fix broken boolean parsing in argparse, where False ends up being True.
    if (options.silent is not None) and (options.silent == "True"):
        options.silent = True
    elif (options.silent is None) or (options.silent == "False"):
        options.silent = False
    else:
        print "--silent expects 'True' or 'False' argument."
        return False

    if (options.sdk is not None) and (options.sdk == "True"):
        options.sdk = True
    elif (options.sdk is None) or (options.sdk == "False"):
        options.sdk = False
    else:
        print "--sdk expects 'True' or 'False' argument."
        return False

    with open(os.devnull, 'wb') as silent_sink:
        # Required options.
        if options.command is None or options.directory is None:
            return False

        # Set a default value for pub_snapshot.
        options.pub_snapshot = None

        # If we have a working pub executable, try and use that.
        # TODO(whesse): Drop the pub-executable option if it isn't used.
        if options.pub_executable is not None:
            try:
                if 0 == subprocess.call([options.pub_executable, '--version'],
                                        stdout=silent_sink,
                                        stderr=silent_sink):
                    return True
            except OSError as e:
                pass
        options.pub_executable = None

        if options.sdk and utils.CheckedInSdkCheckExecutable():
            # Use the checked in pub executable.
            options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(),
                                                'bin', 'snapshots',
                                                'pub.dart.snapshot')
            try:
                if 0 == subprocess.call([
                        utils.CheckedInSdkExecutable(), options.pub_snapshot,
                        '--version'
                ],
                                        stdout=silent_sink,
                                        stderr=silent_sink):
                    return True
            except OSError as e:
                pass
        options.pub_snapshot = None

        # We need a dart executable and a package root.
        return (options.package_root is not None
                and options.dart_executable is not None)
Beispiel #2
0
def GenerateSingleFile(library_path, output_dir, generated_output_dir=None):
    library_dir = os.path.dirname(library_path)
    library_filename = os.path.basename(library_path)
    copy_dart_script = os.path.relpath('../../copy_dart.py', library_dir)
    output_dir = os.path.relpath(output_dir, library_dir)
    command = ' '.join([
        'cd', library_dir, ';', copy_dart_script, output_dir, library_filename
    ])
    subprocess.call([command], shell=True)
    prebuilt_dartfmt = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dartfmt')
    sdk_file = os.path.join(library_dir, output_dir, library_filename)
    formatCommand = ' '.join([prebuilt_dartfmt, '-w', sdk_file])
    subprocess.call([formatCommand], shell=True)
Beispiel #3
0
def ProcessOptions(options, args):
  # Fix broken boolean parsing in argparse, where False ends up being True.
  if (options.silent is not None) and (options.silent == "True"):
    options.silent = True
  elif (options.silent is None) or (options.silent == "False"):
    options.silent = False
  else:
    print "--silent expects 'True' or 'False' argument."
    return False

  if (options.sdk is not None) and (options.sdk == "True"):
    options.sdk = True
  elif (options.sdk is None) or (options.sdk == "False"):
    options.sdk = False
  else:
    print "--sdk expects 'True' or 'False' argument."
    return False

  # Required options.
  if options.command is None or options.directory is None:
    return False

  # If a dart2js execuble was provided, try and use that.
  # TODO(whesse): Drop the dart2js-executable option if it isn't used.
  if options.dart2js_executable is not None:
    try:
      if 0 == RunCommand([options.dart2js_executable, '--version'],
                         always_silent=True):
        return True
    except OSError as e:
      pass
  options.dart2js_executable = None

  # Use the checked in dart2js executable.
  if options.sdk and utils.CheckedInSdkCheckExecutable():
    dart2js_binary = 'dart2js.bat' if utils.IsWindows() else 'dart2js'
    options.dart2js_executable = os.path.join(utils.CheckedInSdkPath(),
                                             'bin',
                                             dart2js_binary)
    try:
      if 0 == RunCommand([options.dart2js_executable, '--version'],
                         always_silent=True):
        return True
    except OSError as e:
      pass
  options.dart2js_executable = None

  # We need a dart executable and will run from source
  return (options.dart_executable is not None)
Beispiel #4
0
def GenerateSingleFile(library_path, output_dir, generated_output_dir=None, prefix=None):
    library_dir = os.path.dirname(library_path)
    library_filename = os.path.basename(library_path)
    copy_dart_script = os.path.relpath('../../copy_dart.py', library_dir)
    output_dir = os.path.relpath(output_dir, library_dir)
    if not os.path.exists(library_dir):
        os.makedirs(library_dir)
    prefix_arg = 'export DART_HTML_PREFIX="' + prefix + '";' if prefix else ""
    command = ' '.join([
        prefix_arg, 'cd', library_dir, ';', copy_dart_script, output_dir, library_filename
    ])
    subprocess.call([command], shell=True)
    prebuilt_dartfmt = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dartfmt')
    sdk_file = os.path.join(library_dir, output_dir, library_filename)
    formatCommand = ' '.join([prebuilt_dartfmt, '-w', sdk_file])
    subprocess.call([formatCommand], shell=True)
Beispiel #5
0
def ProcessOptions(options, args):
    with open(os.devnull, 'wb') as silent_sink:
        # Required options.
        if options.command is None or options.directory is None:
            return False

        # Set a default value for pub_snapshot.
        options.pub_snapshot = None

        # If we have a working pub executable, try and use that.
        # TODO(whesse): Drop the pub-executable option if it isn't used.
        if options.pub_executable is not None:
            try:
                if 0 == subprocess.call([options.pub_executable, '--version'],
                                        stdout=silent_sink,
                                        stderr=silent_sink):
                    return True
            except OSError as e:
                pass
        options.pub_executable = None

        if options.sdk is not None and utils.CheckedInSdkCheckExecutable():
            # Use the checked in pub executable.
            options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(),
                                                'bin', 'snapshots',
                                                'pub.dart.snapshot')
            try:
                if 0 == subprocess.call([
                        utils.CheckedInSdkExecutable(), options.pub_snapshot,
                        '--version'
                ],
                                        stdout=silent_sink,
                                        stderr=silent_sink):
                    return True
            except OSError as e:
                pass
        options.pub_snapshot = None

        # We need a dart executable and a package root.
        return (options.package_root is not None
                and options.dart_executable is not None)
Beispiel #6
0
def main():
    dart = os.path.join(utils.CheckedInSdkPath(), 'bin', 'dart')
    dart_file = os.path.join(os.path.dirname(__file__), 'patch_sdk.dart')
    subprocess.check_call([dart, dart_file] + sys.argv[1:])