예제 #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--out',
                        help='Path to the output file',
                        required=True)
    parser.add_argument('--deps',
                        help='List of manifest paths for the included elements',
                        nargs='*')
    parser.add_argument('--category',
                        help='Minimum publication level',
                        required=False)
    args = parser.parse_args()

    (direct_deps, atoms) = gather_dependencies(args.deps)
    if detect_collisions(atoms):
        print('Name collisions detected!')
        return 1
    if args.category:
        if detect_category_violations(args.category, atoms):
            print('Publication level violations detected!')
            return 1
    manifest = {
        'ids': [],
        'atoms': map(lambda a: a.json, sorted(list(atoms))),
    }
    with open(os.path.abspath(args.out), 'w') as out:
        json.dump(manifest, out, indent=2, sort_keys=True,
                  separators=(',', ': '))
예제 #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--id', help='The atom\'s identifier', required=True)
    parser.add_argument('--out', help='Path to the output file', required=True)
    parser.add_argument('--deps',
                        help='List of manifest paths for dependencies',
                        nargs='*')
    parser.add_argument('--file',
                        help='A (destination <-- source) mapping',
                        action='append',
                        nargs=2)
    parser.add_argument('--gn-label',
                        help='GN label of the atom',
                        required=True)
    parser.add_argument('--category', help='Publication level', required=True)
    parser.add_argument('--meta',
                        help="Path to the atom's metadata file in the SDK",
                        default='',
                        required=False)
    args = parser.parse_args()

    # Gather the definitions of other atoms this atom depends on.
    (deps, atoms) = gather_dependencies(args.deps)

    # Build the list of files making up this atom.
    files = []
    for destination, source in args.file:
        files.append({
            'source': source,
            'destination': destination,
        })

    atoms.update([
        Atom({
            'id': args.id,
            'meta': args.meta,
            'gn-label': args.gn_label,
            'category': args.category,
            'deps': sorted(list(deps)),
            'files': files,
        })
    ])

    if detect_collisions(atoms):
        print('Name collisions detected!')
        return 1
    if detect_category_violations(args.category, atoms):
        print('Publication level violations detected!')
        return 1

    manifest = {
        'ids': [args.id],
        'atoms': map(lambda a: a.json, sorted(list(atoms))),
    }

    with open(os.path.abspath(args.out), 'w') as out:
        json.dump(manifest, out, indent=2, sort_keys=True)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--out', help='Path to the output file', required=True)
    parser.add_argument(
        '--deps',
        help='List of manifest paths for the included elements',
        nargs='*')
    parser.add_argument('--is-group',
                        help='True if the molecule is a grouping of its deps',
                        action='store_true')
    parser.add_argument('--metadata',
                        help='Metadata to attach to the manifest',
                        action='append',
                        default=[])
    parser.add_argument('--category',
                        help='Minimum publication level',
                        required=False)
    args = parser.parse_args()

    (direct_deps, atoms) = gather_dependencies(args.deps)
    if detect_collisions(atoms):
        print('Name collisions detected!')
        return 1
    if args.category:
        if detect_category_violations(args.category, atoms):
            print('Publication level violations detected!')
            return 1
    ids = []
    if args.is_group:
        ids = map(lambda i: i.json, sorted(list(direct_deps)))
    manifest = {
        'ids': ids,
        'atoms': map(lambda a: a.json, sorted(list(atoms))),
    }
    if args.metadata:
        manifest['meta'] = dict(map(lambda m: m.split('=', 1), args.metadata))
    with open(os.path.abspath(args.out), 'w') as out:
        json.dump(manifest, out, indent=2, sort_keys=True)
예제 #4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--id', help='The atom\'s identifier', required=True)
    parser.add_argument('--out', help='Path to the output file', required=True)
    parser.add_argument('--depfile', help='Path to the depfile', required=True)
    parser.add_argument(
        '--deps', help='List of manifest paths for dependencies', nargs='*')
    parser.add_argument(
        '--file',
        help='A (destination <-- source) mapping',
        action='append',
        nargs=2)
    parser.add_argument(
        '--file-list', help='A file containing destination=source mappings')
    parser.add_argument(
        '--gn-label', help='GN label of the atom', required=True)
    parser.add_argument('--category', help='Publication level', required=True)
    parser.add_argument(
        '--meta',
        help='Path to the atom\'s metadata file in the SDK',
        required=True)
    parser.add_argument('--type', help='Type of the atom', required=True)
    args = parser.parse_args()

    # Gather the definitions of other atoms this atom depends on.
    (deps, atoms) = gather_dependencies(args.deps)

    # Build the list of files making up this atom.
    extra_files = []
    if args.file_list:
        with open(args.file_list, 'r') as file_list_file:
            extra_files = [
                line.strip().split('=', 1)
                for line in file_list_file.readlines()
            ]
    files = dict(itertools.chain(args.file, extra_files))

    atoms.update(
        [
            Atom(
                {
                    'id': args.id,
                    'meta': args.meta,
                    'gn-label': args.gn_label,
                    'category': args.category,
                    'deps': sorted(list(deps)),
                    'files':
                        [
                            {
                                'source': source,
                                'destination': destination
                            } for destination, source in files.items()
                        ],
                    'type': args.type,
                })
        ])

    if detect_collisions(atoms):
        print('Name collisions detected!')
        return 1
    if detect_category_violations(args.category, atoms):
        print('Publication level violations detected!')
        return 1

    manifest = {
        'ids': [args.id],
        'atoms': [a.json for a in sorted(list(atoms))],
    }

    with open(os.path.abspath(args.out), 'w') as out:
        json.dump(
            manifest, out, indent=2, sort_keys=True, separators=(',', ': '))

    with open(args.depfile, 'w') as dep_file:
        dep_file.write(args.out + ': ')
        for destination, source in extra_files:
            dep_file.write(source + ' ')
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--id',
                        help='The atom\'s identifier',
                        required=True)
    parser.add_argument('--domain',
                        help='Name of the domain the element belongs to',
                        required=True)
    name_group = parser.add_mutually_exclusive_group(required=True)
    name_group.add_argument('--name',
                            help='Name of the element')
    name_group.add_argument('--name-file',
                            help='Path to the file containing the name of the element')
    parser.add_argument('--out',
                        help='Path to the output file',
                        required=True)
    parser.add_argument('--base',
                        help='Path to the element\'s source directory',
                        required=True)
    parser.add_argument('--deps',
                        help='List of manifest paths for dependencies',
                        nargs='*')
    parser.add_argument('--package-deps',
                        help='List of manifest paths for runtime dependencies',
                        nargs='*')
    parser.add_argument('--files',
                        help='A source=destination mapping',
                        nargs='*')
    parser.add_argument('--tags',
                        help='List of tags for the included elements',
                        nargs='*')
    parser.add_argument('--tags-file',
                        help='A file containing tags',
                        required=False)
    parser.add_argument('--gn-label',
                        help='GN label of the atom',
                        required=True)
    parser.add_argument('--category',
                        help='Publication level',
                        required=True)
    parser.add_argument('--meta',
                        help="Path to the atom's metadata file in the SDK",
                        default='',
                        required=False)
    args = parser.parse_args()

    if args.name:
        name = args.name
    else:
        with open(args.name_file, 'r') as name_file:
            name = name_file.read()

    # Gather the definitions of other atoms this atom depends on.
    (deps, atoms) = gather_dependencies(args.deps)
    (_, package_atoms) = gather_dependencies(args.package_deps)
    all_atoms = atoms
    all_atoms.update(package_atoms)

    # Build the list of files making up this atom.
    files = []
    has_packaged_files = False
    base = os.path.realpath(args.base)
    for mapping in args.files:
        mode, pair = mapping.split(':', 1)
        is_packaged = (mode == 'packaged')
        destination, source = pair.split('=', 1)
        real_source = os.path.realpath(source)
        if not os.path.exists(real_source):
            raise Exception('Missing source file: %s' % real_source)
        if destination:
            if destination.find('..') != -1:
                raise Exception('Destination for %s cannot contain "..": %s.' %
                                (source, destination))
        else:
            if not real_source.startswith(base):
                raise Exception('Destination for %s must be given as it is not'
                                ' under source directory %s' % (source, base))
            destination = os.path.relpath(real_source, base)
        if os.path.isabs(destination):
            raise Exception('Destination cannot be absolute: %s' % destination)
        files.append({
            'source': real_source,
            'destination': destination,
            'packaged': is_packaged
        })
        has_packaged_files = has_packaged_files or is_packaged

    id = {
        'domain': args.domain,
        'name': name,
    }

    all_package_deps = set()
    if has_packaged_files:
        all_package_deps.add(AtomId(id))
    for atom in all_atoms:
        all_package_deps.update(atom.package_deps)

    tags = dict(map(lambda t: t.split(':', 1), args.tags))
    if args.tags_file:
        with open(args.tags_file, 'r') as tags_file:
            data = json.load(tags_file)
            assert isinstance(data, dict)
            tags.update(data)
    tags['domain'] = args.domain

    all_atoms.update([Atom({
        'id': id,
        # TODO(DX-340): rename this to "id" once domain/name are gone.
        'identifier': args.id,
        'meta': args.meta,
        'gn-label': args.gn_label,
        'category': args.category,
        'tags': tags,
        'deps': map(lambda i: i.json, sorted(list(deps))),
        'package-deps': map(lambda i: i.json, sorted(list(all_package_deps))),
        'files': files,
    })])
    if detect_collisions(all_atoms):
        print('Name collisions detected!')
        return 1
    if detect_category_violations(args.category, all_atoms):
        print('Publication level violations detected!')
        return 1

    manifest = {
        'ids': [id],
        'atoms': map(lambda a: a.json, sorted(list(all_atoms))),
    }

    with open(os.path.abspath(args.out), 'w') as out:
        json.dump(manifest, out, indent=2, sort_keys=True)
예제 #6
0
 def test_categories_failure(self):
     atoms = [_atom('hello', 'internal'), _atom('world', 'public')]
     self.assertTrue(detect_category_violations('partner', atoms))
예제 #7
0
 def test_categories(self):
     atoms = [_atom('hello', 'internal'), _atom('world', 'public')]
     self.assertFalse(detect_category_violations('internal', atoms))
예제 #8
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--id', help='The atom\'s identifier', required=True)
    parser.add_argument('--out', help='Path to the output file', required=True)
    parser.add_argument('--depfile', help='Path to the depfile', required=True)
    parser.add_argument(
        '--deps', help='List of manifest paths for dependencies', nargs='*')
    parser.add_argument(
        '--file',
        help='A (destination <-- source) mapping',
        action='append',
        nargs=2)
    parser.add_argument(
        '--file-list', help='A file containing destination=source mappings')
    parser.add_argument(
        '--gn-label', help='GN label of the atom', required=True)
    parser.add_argument('--category', help='Publication level', required=True)
    parser.add_argument(
        '--meta',
        help=
        'Path to the atom\'s metadata file in the SDK. Required by default unless --noop-atom is set to True.'
    )
    parser.add_argument(
        '--noop-atom',
        action='store_true',
        help=
        'Whether the atom is a sdk_noop_atom. Sets the atom\'s meta to be empty. Defaults to False.'
    )
    parser.add_argument('--type', help='Type of the atom', required=True)
    parser.add_argument('--plasa', help='Path to the plasa metadata, optional')
    args = parser.parse_args()

    if args.meta is None and not args.noop_atom:
        parser.error("--meta is required.")

    # Gather the definitions of other atoms this atom depends on.
    (deps, atoms) = gather_dependencies(args.deps)

    # Build the list of files making up this atom.
    extra_files = []
    if args.file_list:
        with open(args.file_list, 'r') as file_list_file:
            extra_files = [
                line.strip().split('=', 1)
                for line in file_list_file.readlines()
            ]

    files = dict(itertools.chain(
        args.file, extra_files)) if args.file else dict(extra_files)

    plasa_fragments = []
    if args.plasa:
        with open(args.plasa, 'r') as plasa_file:
            data = json.load(plasa_file)
            for d in data:
                files[d['dest']] = d['path']
                plasa_fragments += [d['dest']]

    atoms.update(
        [
            Atom(
                {
                    'id': args.id,
                    'meta': args.meta or '',
                    'gn-label': args.gn_label,
                    'category': args.category,
                    'deps': sorted(list(deps)),
                    'files':
                        [
                            {
                                'source': os.path.normpath(source),
                                'destination': os.path.normpath(destination)
                            } for destination, source in files.items()
                        ],
                    'type': args.type,
                    'plasa': plasa_fragments,
                })
        ])

    if detect_collisions(atoms):
        print('Name collisions detected!')
        return 1
    if detect_category_violations(args.category, atoms):
        print('Publication level violations detected!')
        return 1

    manifest = {
        'ids': [args.id],
        'atoms': [a.json for a in sorted(list(atoms))],
    }

    with open(os.path.abspath(args.out), 'w') as out:
        json.dump(
            manifest, out, indent=2, sort_keys=True, separators=(',', ': '))

    with open(args.depfile, 'w') as dep_file:
        dep_file.write(
            '{}: {}\n'.format(
                args.out,
                # Always write relative paths to depfiles. See more information
                # from https://fxbug.dev/75451.
                ' '.join(os.path.relpath(source) for _, source in extra_files),
            ),
        )