toolchain.dart 2.98 KB
Newer Older
1 2 3 4 5 6
// 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 'package:path/path.dart' as path;

7
import 'base/context.dart';
8
import 'base/file_system.dart';
9
import 'build_info.dart';
10 11
import 'cache.dart';
import 'globals.dart';
12

13 14
enum HostTool {
  SkySnapshot,
15
  SkyShell,
16
}
17

18 19 20 21 22
const Map<HostTool, String> _kHostToolFileName = const <HostTool, String>{
  HostTool.SkySnapshot: 'sky_snapshot',
  HostTool.SkyShell: 'sky_shell',
};

23 24 25 26
/// A ToolConfiguration can return the tools directory for the current host platform
/// and the engine artifact directory for a given target platform. It is configurable
/// via command-line arguments in order to support local engine builds.
class ToolConfiguration {
27
  ToolConfiguration();
28

29
  Cache get cache => context[Cache];
30

31
  static ToolConfiguration get instance => context[ToolConfiguration];
32 33 34 35

  /// Override using the artifacts from the cache directory (--engine-src-path).
  String engineSrcPath;

36 37 38
  /// Path to a local engine build acting as a source for artifacts (--local-engine).
  String engineBuildPath;

39
  bool get isLocalEngine => engineSrcPath != null;
40 41 42

  /// Return the directory that contains engine artifacts for the given targets.
  /// This directory might contain artifacts like `libsky_shell.so`.
43 44
  Directory getEngineArtifactsDirectory(TargetPlatform platform, BuildMode mode) {
    Directory dir = _getEngineArtifactsDirectory(platform, mode);
45 46 47 48 49
    if (dir != null)
      printTrace('Using engine artifacts dir: ${dir.path}');
    return dir;
  }

50
  Directory _getEngineArtifactsDirectory(TargetPlatform platform, BuildMode mode) {
51
    if (engineBuildPath != null) {
52
      return fs.directory(engineBuildPath);
53
    } else {
54
      String suffix = mode != BuildMode.debug ? '-${getModeName(mode)}' : '';
55

56
      // Create something like `android-arm` or `android-arm-release`.
Devon Carew's avatar
Devon Carew committed
57
      String dirName = getNameForTargetPlatform(platform) + suffix;
58
      Directory engineDir = cache.getArtifactDirectory('engine');
59
      return fs.directory(path.join(engineDir.path, dirName));
60 61
    }
  }
62 63

  String getHostToolPath(HostTool tool) {
64
    if (engineBuildPath == null) {
65
      return path.join(cache.getArtifactDirectory('engine').path,
66
                       getNameForHostPlatform(getCurrentHostPlatform()),
67 68 69 70 71
                       _kHostToolFileName[tool]);
    }

    if (tool == HostTool.SkySnapshot) {
      String clangPath = path.join(engineBuildPath, 'clang_x64', 'sky_snapshot');
72
      if (fs.isFileSync(clangPath))
73 74 75 76 77 78 79 80
        return clangPath;
      return path.join(engineBuildPath, 'sky_snapshot');
    } else if (tool == HostTool.SkyShell) {
      if (getCurrentHostPlatform() == HostPlatform.linux_x64) {
        return path.join(engineBuildPath, 'sky_shell');
      } else if (getCurrentHostPlatform() == HostPlatform.darwin_x64) {
        return path.join(engineBuildPath, 'SkyShell.app', 'Contents', 'MacOS', 'SkyShell');
      }
81
    }
82 83

    throw 'Unexpected host tool: $tool';
84
  }
85
}