Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
gen_dart_package_config Namespace Reference

Classes

class  PackageConfig
 

Functions

 language_version_from_pubspec (pubspec)
 
 collect_packages (items, relative_to)
 
 main ()
 

Variables

 THIS_DIR = os.path.abspath(os.path.dirname(__file__))
 
str DEFAULT_LANGUAGE_VERSION = '2.8'
 
 Package = collections.namedtuple('Package', ['name', 'rootUri', 'languageVersion', 'packageUri'])
 

Detailed Description

Reads the contents of a package config file generated by the build and
  converts it to a real package_config.json file

Function Documentation

◆ collect_packages()

gen_dart_package_config.collect_packages (   items,
  relative_to 
)
Reads metadata produced by GN to create lists of packages and pubspecs.
      - items: a list of objects collected from gn
      - relative_to: The directory which the packages are relative to. This is
        the location that contains the package_config.json file

  Returns None if there was a problem parsing packages

Definition at line 64 of file gen_dart_package_config.py.

64def collect_packages(items, relative_to):
65 """Reads metadata produced by GN to create lists of packages and pubspecs.
66 - items: a list of objects collected from gn
67 - relative_to: The directory which the packages are relative to. This is
68 the location that contains the package_config.json file
69
70 Returns None if there was a problem parsing packages
71 """
72 packages = []
73 pubspec_paths = []
74 for item in items:
75 if 'language_version' in item:
76 language_version = item['language_version']
77 elif 'pubspec_path' in item:
78 pubspec_paths.append(item['pubspec_path'])
79 language_version = language_version_from_pubspec(item['pubspec_path'])
80 else:
81 language_version = DEFAULT_LANGUAGE_VERSION
82
83 package = Package(
84 name=item['name'],
85 rootUri=os.path.relpath(item['root_uri'], relative_to),
86 languageVersion=language_version,
87 packageUri=item['package_uri']
88 )
89
90 # TODO(fxbug.dev/56428): enable once we sort out our duplicate packages
91 # for p in packages:
92 # if p.rootUri == package.rootUri:
93 # print('Failed to create package_config.json file')
94 # print('The following packages contain the same package root ' + p.rootUri)
95 # print(' - ' + p.rootUri)
96 # print(' - ' + package.rootUri)
97 # return None
98
99 packages.append(package)
100
101 return packages, pubspec_paths
102
103

◆ language_version_from_pubspec()

gen_dart_package_config.language_version_from_pubspec (   pubspec)
Parse the content of a pubspec.yaml

Definition at line 45 of file gen_dart_package_config.py.

45def language_version_from_pubspec(pubspec):
46 """Parse the content of a pubspec.yaml"""
47 with open(pubspec) as pubspec:
48 parsed = yaml.safe_load(pubspec)
49 if not parsed:
50 return DEFAULT_LANGUAGE_VERSION
51
52 # If a format like sdk: '>=a.b' or sdk: 'a.b' is found, we'll use a.b.
53 # In all other cases we default to "2.8"
54 env_sdk = parsed.get('environment', {}).get('sdk', 'any')
55 match = re.search(r'^(>=)?((0|[1-9]\d*)\.(0|[1-9]\d*))', env_sdk)
56 if match:
57 min_sdk_version = match.group(2)
58 else:
59 min_sdk_version = DEFAULT_LANGUAGE_VERSION
60
61 return min_sdk_version
62
63

◆ main()

gen_dart_package_config.main ( )

Definition at line 104 of file gen_dart_package_config.py.

104def main():
105 parser = argparse.ArgumentParser(description=__doc__)
106 parser.add_argument('--input', help='Path to original package_config', required=True)
107 parser.add_argument('--output', help='Path to the updated package_config', required=True)
108 parser.add_argument('--root', help='Path to fuchsia root', required=True)
109 parser.add_argument('--depfile', help='Path to the depfile', required=True)
110 args = parser.parse_args()
111
112 with open(args.input, 'r') as input_file:
113 contents = json.load(input_file)
114
115 output_dir = os.path.dirname(os.path.abspath(args.output))
116 packages, pubspec_paths = collect_packages(contents, output_dir)
117 if packages is None:
118 return 1
119
120 with open(args.depfile, 'w') as depfile:
121 depfile.write('%s: %s' % (args.output, ' '.join(pubspec_paths)))
122
123 with open(args.output, 'w') as output_file:
124 package_config = PackageConfig(packages)
125 json.dump(
126 package_config.asdict(), output_file, indent=2, sort_keys=True, separators=(',', ': ')
127 )
128
129 return 0
130
131
Definition main.py:1

Variable Documentation

◆ DEFAULT_LANGUAGE_VERSION

str gen_dart_package_config.DEFAULT_LANGUAGE_VERSION = '2.8'

Definition at line 21 of file gen_dart_package_config.py.

◆ Package

gen_dart_package_config.Package = collections.namedtuple('Package', ['name', 'rootUri', 'languageVersion', 'packageUri'])

Definition at line 23 of file gen_dart_package_config.py.

◆ THIS_DIR

gen_dart_package_config.THIS_DIR = os.path.abspath(os.path.dirname(__file__))

Definition at line 17 of file gen_dart_package_config.py.