6"""Reads the contents of a package config file generated by the build and
7 converts it to a real package_config.json file
17THIS_DIR = os.path.abspath(os.path.dirname(__file__))
18sys.path += [os.path.join(THIS_DIR, '..', '..', '..', 'third_party', 'pyyaml', 'lib3')]
21DEFAULT_LANGUAGE_VERSION = '2.8'
23Package = collections.namedtuple('Package', ['name', 'rootUri', 'languageVersion', 'packageUri'])
31 GENERATOR_NAME = os.path.basename(__file__)
37 """Converts the package config to a dictionary"""
40 'packages': [p._asdict()
for p
in sorted(self.
packages)],
46 """Parse the content of a pubspec.yaml"""
47 with open(pubspec)
as pubspec:
48 parsed = yaml.safe_load(pubspec)
50 return DEFAULT_LANGUAGE_VERSION
54 env_sdk = parsed.get(
'environment', {}).
get(
'sdk',
'any')
55 match = re.search(
r'^(>=)?((0|[1-9]\d*)\.(0|[1-9]\d*))', env_sdk)
57 min_sdk_version = match.group(2)
59 min_sdk_version = DEFAULT_LANGUAGE_VERSION
61 return min_sdk_version
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
70 Returns
None if there was a problem parsing packages
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'])
81 language_version = DEFAULT_LANGUAGE_VERSION
85 rootUri=os.path.relpath(item[
'root_uri'], relative_to),
86 languageVersion=language_version,
87 packageUri=item[
'package_uri']
99 packages.append(package)
101 return packages, pubspec_paths
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()
112 with open(args.input,
'r')
as input_file:
113 contents = json.load(input_file)
115 output_dir = os.path.dirname(os.path.abspath(args.output))
120 with open(args.depfile,
'w')
as depfile:
121 depfile.write(
'%s: %s' % (args.output,
' '.
join(pubspec_paths)))
123 with open(args.output,
'w')
as output_file:
126 package_config.asdict(), output_file, indent=2, sort_keys=
True, separators=(
',',
': ')
132if __name__ ==
'__main__':
def __init__(self, packages)
def collect_packages(items, relative_to)
def language_version_from_pubspec(pubspec)
const myers::Point & get(const myers::Segment &)
static SkString join(const CommandLineFlags::StringArray &)