1// Copyright 2014 The Flutter 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:io' show Directory, File;
6
7import 'package:file/file.dart' as fs;
8import 'package:file/local.dart';
9import 'package:path/path.dart' as path;
10
11import '../run_command.dart';
12import '../utils.dart';
13
14/// Executes the test suite for the flutter/packages repo.
15Future<void> flutterPackagesRunner() async {
16
17 Future<void> runAnalyze() async {
18 printProgress('${green}Running analysis for flutter/packages$reset');
19 final Directory checkout = Directory.systemTemp.createTempSync('flutter_packages.');
20 await runCommand(
21 'git',
22 const <String>[
23 '-c',
24 'core.longPaths=true',
25 'clone',
26 'https://github.com/flutter/packages.git',
27 '.',
28 ],
29 workingDirectory: checkout.path,
30 );
31 final String packagesCommit = await getFlutterPackagesVersion(flutterRoot: flutterRoot);
32 await runCommand(
33 'git',
34 <String>[
35 '-c',
36 'core.longPaths=true',
37 'checkout',
38 packagesCommit,
39 ],
40 workingDirectory: checkout.path,
41 );
42 // Prep the repository tooling.
43 // This test does not use tool_runner.sh because in this context the test
44 // should always run on the entire packages repo, while tool_runner.sh
45 // is designed for flutter/packages CI and only analyzes changed repository
46 // files when run for anything but master.
47 final String toolDir = path.join(checkout.path, 'script', 'tool');
48 await runCommand(
49 'dart',
50 const <String>[
51 'pub',
52 'get',
53 ],
54 workingDirectory: toolDir,
55 );
56 final String toolScript = path.join(toolDir, 'bin', 'flutter_plugin_tools.dart');
57 await runCommand(
58 'dart',
59 <String>[
60 'run',
61 toolScript,
62 'analyze',
63 // Fetch the oldest possible dependencies, rather than the newest, to
64 // insulate flutter/flutter from out-of-band failures when new versions
65 // of dependencies are published. This compensates for the fact that
66 // flutter/packages doesn't use pinned dependencies, and for the
67 // purposes of this test using old dependencies is fine. See
68 // https://github.com/flutter/flutter/issues/129633
69 '--downgrade',
70 '--custom-analysis=script/configs/custom_analysis.yaml',
71 ],
72 workingDirectory: checkout.path,
73 );
74 }
75 await selectSubshard(<String, ShardRunner>{
76 'analyze': runAnalyze,
77 });
78}
79
80/// Returns the commit hash of the flutter/packages repository that's rolled in.
81///
82/// The flutter/packages repository is a downstream dependency, it is only used
83/// by flutter/flutter for testing purposes, to assure stable tests for a given
84/// flutter commit the flutter/packages commit hash to test against is coded in
85/// the bin/internal/flutter_packages.version file.
86///
87/// The `filesystem` parameter specified filesystem to read the packages version file from.
88/// The `packagesVersionFile` parameter allows specifying an alternative path for the
89/// packages version file, when null [flutterPackagesVersionFile] is used.
90Future<String> getFlutterPackagesVersion({
91 fs.FileSystem fileSystem = const LocalFileSystem(),
92 String? packagesVersionFile,
93 required String flutterRoot,
94}) async {
95 final String flutterPackagesVersionFile = path.join(flutterRoot, 'bin', 'internal', 'flutter_packages.version');
96
97 final File versionFile = fileSystem.file(packagesVersionFile ?? flutterPackagesVersionFile);
98 final String versionFileContents = await versionFile.readAsString();
99 return versionFileContents.trim();
100}
101

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com