toolchain.dart 1.87 KB
Newer Older
1 2 3 4 5
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
6
import 'dart:io';
7 8 9 10

import 'package:path/path.dart' as path;

import 'artifacts.dart';
11
import 'base/process.dart';
Devon Carew's avatar
Devon Carew committed
12
import 'build_configuration.dart';
13
import 'package_map.dart';
14

15 16
class SnapshotCompiler {
  SnapshotCompiler(this._path);
17

18
  final String _path;
19

20
  Future<int> createSnapshot({
21
    String mainPath,
22 23 24
    String snapshotPath,
    String depfilePath,
    String buildOutputPath
25
  }) {
26
    final List<String> args = [
27
      _path,
28
      mainPath,
29
      '--packages=${PackageMap.instance.packagesPath}',
30
      '--snapshot=$snapshotPath'
31
    ];
32
    if (depfilePath != null)
33
      args.add('--depfile=$depfilePath');
34
    if (buildOutputPath != null)
35 36
      args.add('--build-output=$buildOutputPath');
    return runCommandAndStreamOutput(args);
37 38 39
  }
}

Devon Carew's avatar
Devon Carew committed
40
String _getCompilerPath(BuildConfiguration config) {
41 42
  if (config.type != BuildType.prebuilt) {
    String compilerPath = path.join(config.buildDir, 'clang_x64', 'sky_snapshot');
43 44 45
    if (FileSystemEntity.isFileSync(compilerPath))
      return compilerPath;
    compilerPath = path.join(config.buildDir, 'sky_snapshot');
46 47 48 49
    if (FileSystemEntity.isFileSync(compilerPath))
      return compilerPath;
    return null;
  }
50 51
  Artifact artifact = ArtifactStore.getArtifact(
    type: ArtifactType.snapshot, hostPlatform: config.hostPlatform);
Devon Carew's avatar
Devon Carew committed
52
  return ArtifactStore.getPath(artifact);
53 54
}

55 56 57
class Toolchain {
  Toolchain({ this.compiler });

58
  final SnapshotCompiler compiler;
59

Devon Carew's avatar
Devon Carew committed
60
  static Toolchain forConfigs(List<BuildConfiguration> configs) {
61
    for (BuildConfiguration config in configs) {
Devon Carew's avatar
Devon Carew committed
62
      String compilerPath = _getCompilerPath(config);
63
      if (compilerPath != null)
64
        return new Toolchain(compiler: new SnapshotCompiler(compilerPath));
65 66
    }
    return null;
67 68
  }
}