Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
pub_get_offline.py
Go to the documentation of this file.
1# Copyright 2013 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
5# This python script uses `pub get --offline` to fill in
6# .dart_tool/package_config.json files for Dart packages in the tree whose
7# dependencies should be entirely resolved without requesting data from pub.dev.
8# This allows us to be certain that the Dart code we are pulling for these
9# packages is explicitly fetched by `gclient sync` rather than implicitly
10# fetched by pub version solving, and pub fetching transitive dependencies.
11
12import json
13import os
14import subprocess
15import sys
16
17SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
18ENGINE_DIR = os.path.join(SRC_ROOT, 'flutter')
19
20ALL_PACKAGES = [
21 os.path.join(ENGINE_DIR, 'ci'),
22 os.path.join(ENGINE_DIR, 'flutter_frontend_server'),
23 os.path.join(ENGINE_DIR, 'impeller', 'tessellator', 'dart'),
24 os.path.join(ENGINE_DIR, 'shell', 'vmservice'),
25 os.path.join(ENGINE_DIR, 'testing', 'benchmark'),
26 os.path.join(ENGINE_DIR, 'testing', 'dart'),
27 os.path.join(ENGINE_DIR, 'testing', 'litetest'),
28 os.path.join(ENGINE_DIR, 'testing', 'pkg_test_demo'),
29 os.path.join(ENGINE_DIR, 'testing', 'scenario_app'),
30 os.path.join(ENGINE_DIR, 'testing', 'skia_gold_client'),
31 os.path.join(ENGINE_DIR, 'testing', 'smoke_test_failure'),
32 os.path.join(ENGINE_DIR, 'testing', 'symbols'),
33 os.path.join(ENGINE_DIR, 'tools', 'android_lint'),
34 os.path.join(ENGINE_DIR, 'tools', 'api_check'),
35 os.path.join(ENGINE_DIR, 'tools', 'build_bucket_golden_scraper'),
36 os.path.join(ENGINE_DIR, 'tools', 'clang_tidy'),
37 os.path.join(ENGINE_DIR, 'tools', 'clangd_check'),
38 os.path.join(ENGINE_DIR, 'tools', 'compare_goldens'),
39 os.path.join(ENGINE_DIR, 'tools', 'const_finder'),
40 os.path.join(ENGINE_DIR, 'tools', 'dir_contents_diff'),
41 os.path.join(ENGINE_DIR, 'tools', 'engine_tool'),
42 os.path.join(ENGINE_DIR, 'tools', 'gen_web_locale_keymap'),
43 os.path.join(ENGINE_DIR, 'tools', 'githooks'),
44 os.path.join(ENGINE_DIR, 'tools', 'golden_tests_harvester'),
45 os.path.join(ENGINE_DIR, 'tools', 'header_guard_check'),
46 os.path.join(ENGINE_DIR, 'tools', 'licenses'),
47 os.path.join(ENGINE_DIR, 'tools', 'path_ops', 'dart'),
48 os.path.join(ENGINE_DIR, 'tools', 'pkg', 'engine_build_configs'),
49 os.path.join(ENGINE_DIR, 'tools', 'pkg', 'engine_repo_tools'),
50 os.path.join(ENGINE_DIR, 'tools', 'pkg', 'git_repo_tools'),
51 os.path.join(ENGINE_DIR, 'tools', 'pkg', 'process_fakes'),
52]
53
54
55def fetch_package(pub, package):
56 try:
57 subprocess.check_output(pub, cwd=package, stderr=subprocess.STDOUT)
58 except subprocess.CalledProcessError as err:
59 print(
60 '"%s" failed in "%s" with status %d:\n%s' %
61 (' '.join(pub), package, err.returncode, err.output)
62 )
63 return 1
64 return 0
65
66
67def check_package(package):
68 package_config = os.path.join(package, '.dart_tool', 'package_config.json')
69 pub_count = 0
70 with open(package_config) as config_file:
71 data_dict = json.load(config_file)
72 packages_data = data_dict['packages']
73 for package_data in packages_data:
74 package_uri = package_data['rootUri']
75 package_name = package_data['name']
76 if '.pub-cache' in package_uri and ('pub.dartlang.org' in package_uri or
77 'pub.dev' in package_uri):
78 print('Error: package "%s" was fetched from pub' % package_name)
79 pub_count = pub_count + 1
80 if pub_count > 0:
81 print('Error: %d packages were fetched from pub for %s' % (pub_count, package))
82 print(
83 'Please fix the pubspec.yaml for %s '
84 'so that all dependencies are path dependencies' % package
85 )
86 return pub_count
87
88
89EXCLUDED_DIRS = [
90 os.path.join(ENGINE_DIR, 'lib'),
91 os.path.join(ENGINE_DIR, 'prebuilts'),
92 os.path.join(ENGINE_DIR, 'shell', 'platform', 'fuchsia'),
93 os.path.join(ENGINE_DIR, 'shell', 'vmservice'),
94 os.path.join(ENGINE_DIR, 'sky', 'packages'),
95 os.path.join(ENGINE_DIR, 'testing', 'pkg_test_demo'),
96 os.path.join(ENGINE_DIR, 'third_party'),
97 os.path.join(ENGINE_DIR, 'web_sdk'),
98]
99
100
101# Returns a list of paths to directories containing pubspec.yaml files that
102# are not listed in ALL_PACKAGES. Directory trees under the paths in
103# EXCLUDED_DIRS are skipped.
105 unlisted = []
106 for root, dirs, files in os.walk(ENGINE_DIR):
107 excluded = []
108 for dirname in dirs:
109 full_dirname = os.path.join(root, dirname)
110 if full_dirname in EXCLUDED_DIRS:
111 excluded.append(dirname)
112 for exclude in excluded:
113 dirs.remove(exclude)
114 for filename in files:
115 if filename == 'pubspec.yaml':
116 if root not in ALL_PACKAGES:
117 unlisted.append(root)
118 return unlisted
119
120
121def main():
122 dart_sdk_bin = os.path.join(
123 SRC_ROOT, 'flutter', 'third_party', 'dart', 'tools', 'sdks', 'dart-sdk', 'bin'
124 )
125
126 # Ensure all relevant packages are listed in ALL_PACKAGES.
127 unlisted = find_unlisted_packages()
128 if len(unlisted) > 0:
129 for pkg in unlisted:
130 print('The Dart package "%s" must be checked in flutter/tools/pub_get_offline.py' % pkg)
131 return 1
132
133 dart = 'dart'
134 if os.name == 'nt':
135 dart = 'dart.exe'
136 pubcmd = [os.path.join(dart_sdk_bin, dart), 'pub', '--suppress-analytics', 'get', '--offline']
137
138 pub_count = 0
139 for package in ALL_PACKAGES:
140 if fetch_package(pubcmd, package) != 0:
141 return 1
142 pub_count = pub_count + check_package(package)
143
144 if pub_count > 0:
145 return 1
146
147 return 0
148
149
150if __name__ == '__main__':
151 sys.exit(main())
void print(void *str)
Definition bridge.cpp:126
Definition main.py:1
fetch_package(pub, package)