desktop.dart 3.13 KB
Newer Older
1 2 3 4 5 6 7
// 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 '../../base/file_system.dart';
import '../depfile.dart';

8 9 10
/// Unpack the engine artifact list [artifacts] from [engineSourcePath], ICU
/// data (if provided), and [clientSourcePaths] (if provided) into a directory
/// [outputDirectory].
11 12 13 14 15
///
/// Returns a [Depfile] including all copied files.
///
/// Throws an [Exception] if [artifacts] includes missing files, directories,
/// or links.
16
Depfile unpackDesktopArtifacts({
17 18 19 20 21 22
  required FileSystem fileSystem,
  required List<String> artifacts,
  required Directory outputDirectory,
  required String engineSourcePath,
  List<String>? clientSourcePaths,
  String? icuDataPath,
23 24 25 26
}) {
  final List<File> inputs = <File>[];
  final List<File> outputs = <File>[];
  for (final String artifact in artifacts) {
27
    final String entityPath = fileSystem.path.join(engineSourcePath, artifact);
28 29 30
    final FileSystemEntityType entityType = fileSystem.typeSync(entityPath);

    if (entityType == FileSystemEntityType.notFound
31
     || entityType == FileSystemEntityType.directory
32
     || entityType == FileSystemEntityType.link) {
33
      throw Exception('Unsupported file type "$entityType" for $entityPath');
34
    }
35 36 37 38 39 40 41 42
    assert(entityType == FileSystemEntityType.file);
    final String outputPath = fileSystem.path.join(
      outputDirectory.path,
      fileSystem.path.relative(entityPath, from: engineSourcePath),
    );
    final File destinationFile = fileSystem.file(outputPath);
    if (!destinationFile.parent.existsSync()) {
      destinationFile.parent.createSync(recursive: true);
43
    }
44 45 46 47 48
    final File inputFile = fileSystem.file(entityPath);
    inputFile.copySync(destinationFile.path);
    inputs.add(inputFile);
    outputs.add(destinationFile);
  }
49 50 51 52 53 54 55
  if (icuDataPath != null) {
    final File inputFile = fileSystem.file(icuDataPath);
    final File outputFile = fileSystem.file(fileSystem.path.join(outputDirectory.path, inputFile.basename));
    inputFile.copySync(outputFile.path);
    inputs.add(inputFile);
    outputs.add(outputFile);
  }
56
  if (clientSourcePaths == null) {
57 58
    return Depfile(inputs, outputs);
  }
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  for (final String clientSourcePath in clientSourcePaths) {
    final Directory clientSourceDirectory = fileSystem.directory(clientSourcePath);
    if (!clientSourceDirectory.existsSync()) {
      throw Exception('Missing clientSourceDirectory: $clientSourcePath');
    }
    for (final File input in clientSourceDirectory
      .listSync(recursive: true)
      .whereType<File>()) {
      final String outputPath = fileSystem.path.join(
        outputDirectory.path,
        fileSystem.path.relative(input.path, from: clientSourceDirectory.parent.path),
      );
      final File destinationFile = fileSystem.file(outputPath);
      if (!destinationFile.parent.existsSync()) {
        destinationFile.parent.createSync(recursive: true);
      }
      final File inputFile = fileSystem.file(input);
      inputFile.copySync(destinationFile.path);
      inputs.add(inputFile);
      outputs.add(destinationFile);
79 80 81 82
    }
  }
  return Depfile(inputs, outputs);
}