host_agent.dart 1.29 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// Copyright 2014 The Flutter 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:file/file.dart';
import 'package:file/local.dart';
import 'package:meta/meta.dart';
import 'package:platform/platform.dart';

/// The current host machine running the tests.
HostAgent get hostAgent => HostAgent(platform: const LocalPlatform(), fileSystem: const LocalFileSystem());

/// Host machine running the tests.
class HostAgent {
15
  HostAgent({required Platform platform, required FileSystem fileSystem})
16 17 18 19 20 21 22
      : _platform = platform,
        _fileSystem = fileSystem;

  final Platform _platform;
  final FileSystem _fileSystem;

  /// Creates a directory to dump file artifacts.
23
  Directory? get dumpDirectory {
24 25
    if (_dumpDirectory == null) {
      // Set in LUCI recipe.
26
      final String? directoryPath = _platform.environment['FLUTTER_LOGS_DIR'];
27
      if (directoryPath != null) {
28
        _dumpDirectory = _fileSystem.directory(directoryPath)..createSync(recursive: true);
29
        print('Found FLUTTER_LOGS_DIR dump directory ${_dumpDirectory?.path}');
30 31 32 33 34
      }
    }
    return _dumpDirectory;
  }

35
  static Directory? _dumpDirectory;
36 37 38 39 40 41

  @visibleForTesting
  void resetDumpDirectory() {
    _dumpDirectory = null;
  }
}