forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pub_get_offline.py
101 lines (86 loc) · 3.28 KB
/
pub_get_offline.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Copyright 2013 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.
# This python script uses `pub get --offline` to fill in
# .dart_tool/package_config.json files for Dart packages in the tree whose
# dependencies should be entirely resolved without requesting data from pub.dev.
# This allows us to be certain that the Dart code we are pulling for these
# packages is explicitly fetched by `gclient sync` rather than implicitly
# fetched by pub version solving, and pub fetching transitive dependencies.
import json
import os
import subprocess
import sys
SRC_ROOT = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
ENGINE_DIR = os.path.join(SRC_ROOT, 'flutter')
ALL_PACKAGES = [
os.path.join(ENGINE_DIR, "ci"),
os.path.join(ENGINE_DIR, "flutter_frontend_server"),
os.path.join(ENGINE_DIR, "shell", "vmservice"),
os.path.join(ENGINE_DIR, "testing", "benchmark"),
os.path.join(ENGINE_DIR, "testing", "dart"),
os.path.join(ENGINE_DIR, "testing", "litetest"),
os.path.join(ENGINE_DIR, "testing", "android_background_image"),
os.path.join(ENGINE_DIR, "testing", "scenario_app"),
os.path.join(ENGINE_DIR, "testing", "smoke_test_failure"),
os.path.join(ENGINE_DIR, "testing", "symbols"),
os.path.join(ENGINE_DIR, "tools", "api_check"),
os.path.join(ENGINE_DIR, "tools", "android_lint"),
os.path.join(ENGINE_DIR, "tools", "clang_tidy"),
os.path.join(ENGINE_DIR, "tools", "const_finder"),
os.path.join(ENGINE_DIR, "tools", "githooks"),
os.path.join(ENGINE_DIR, "tools", "licenses"),
os.path.join(ENGINE_DIR, "tools", "path_ops", "dart")
]
def FetchPackage(pub, package):
try:
subprocess.check_output(pub, cwd=package, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as err:
print(
"'%s' failed in '%s' with status %d:\n%s" %
(' '.join(pub), package, err.returncode, err.output)
)
return 1
return 0
def CheckPackage(package):
package_config = os.path.join(package, ".dart_tool", "package_config.json")
pub_count = 0
with open(package_config) as f:
data_dict = json.load(f)
packages_data = data_dict["packages"]
for package_data in packages_data:
package_uri = package_data["rootUri"]
package_name = package_data["name"]
if ".pub-cache" in package_uri and "pub.dartlang.org" in package_uri:
print("Error: package '%s' was fetched from pub" % package_name)
pub_count = pub_count + 1
if pub_count > 0:
print(
"Error: %d packages were fetched from pub for %s" %
(pub_count, package)
)
print(
"Please fix the pubspec.yaml for %s "
"so that all dependencies are path dependencies" % package
)
return pub_count
def Main():
dart_sdk_bin = os.path.join(
SRC_ROOT, "third_party", "dart", "tools", "sdks", "dart-sdk", "bin"
)
dart = "dart"
if os.name == "nt":
dart = "dart.exe"
pubcmd = [os.path.join(dart_sdk_bin, dart), "pub", "get", "--offline"]
pub_count = 0
for package in ALL_PACKAGES:
if FetchPackage(pubcmd, package) != 0:
return 1
pub_count = pub_count + CheckPackage(package)
if pub_count > 0:
return 1
return 0
if __name__ == '__main__':
sys.exit(Main())