• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import 'dart:async';
6
7import 'package:platform/platform.dart';
8
9import 'context.dart';
10import 'file_system.dart';
11
12export 'package:platform/platform.dart';
13
14const Platform _kLocalPlatform = LocalPlatform();
15const String _kRecordingType = 'platform';
16
17Platform get platform => context.get<Platform>() ?? _kLocalPlatform;
18
19/// Serializes the current [platform] to the specified base recording
20/// [location].
21///
22/// Platform metadata will be recorded in a subdirectory of [location] named
23/// `"platform"`. It is permissible for [location] to represent an existing
24/// non-empty directory as long as there is no collision with the `"platform"`
25/// subdirectory.
26///
27/// Returns the existing platform.
28Future<Platform> getRecordingPlatform(String location) async {
29  final Directory dir = getRecordingSink(location, _kRecordingType);
30  final File file = _getPlatformManifest(dir);
31  await file.writeAsString(platform.toJson(), flush: true);
32  return platform;
33}
34
35Future<FakePlatform> getReplayPlatform(String location) async {
36  final Directory dir = getReplaySource(location, _kRecordingType);
37  final File file = _getPlatformManifest(dir);
38  final String json = await file.readAsString();
39  return FakePlatform.fromJson(json);
40}
41
42File _getPlatformManifest(Directory dir) {
43  final String path = dir.fileSystem.path.join(dir.path, 'MANIFEST.txt');
44  return dir.fileSystem.file(path);
45}
46