toolchain.dart 1.6 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 14

class Compiler {
15
  Compiler(this._path);
16

17
  String _path;
18 19 20 21 22 23

  Future<int> compile({
    String mainPath,
    String snapshotPath
  }) {
    return runCommandAndStreamOutput([
24
      _path,
25 26 27 28 29 30 31
      mainPath,
      '--package-root=${ArtifactStore.packageRoot}',
      '--snapshot=$snapshotPath'
    ]);
  }
}

32
Future<String> _getCompilerPath(BuildConfiguration config) async {
33 34
  if (config.type != BuildType.prebuilt) {
    String compilerPath = path.join(config.buildDir, 'clang_x64', 'sky_snapshot');
35 36 37
    if (FileSystemEntity.isFileSync(compilerPath))
      return compilerPath;
    compilerPath = path.join(config.buildDir, 'sky_snapshot');
38 39 40 41
    if (FileSystemEntity.isFileSync(compilerPath))
      return compilerPath;
    return null;
  }
42 43 44 45 46
  Artifact artifact = ArtifactStore.getArtifact(
    type: ArtifactType.snapshot, hostPlatform: config.hostPlatform);
  return await ArtifactStore.getPath(artifact);
}

47 48 49 50 51 52
class Toolchain {
  Toolchain({ this.compiler });

  final Compiler compiler;

  static Future<Toolchain> forConfigs(List<BuildConfiguration> configs) async {
53 54 55 56 57 58
    for (BuildConfiguration config in configs) {
      String compilerPath = await _getCompilerPath(config);
      if (compilerPath != null)
        return new Toolchain(compiler: new Compiler(compilerPath));
    }
    return null;
59 60
  }
}