def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        '--input', help='Path to original manifest', required=True)
    parser.add_argument(
        '--output', help='Path to the updated manifest', required=True)
    parser.add_argument(
        '--depfile', help='Path to GN style depfile', required=True)
    args = parser.parse_args()

    with open(args.input, 'r') as input_file:
        contents = json.load(input_file)

    opened_files = set()
    entries, error = distribution_manifest.expand_manifest(
        contents, opened_files)
    if error:
        print(error, file=sys.stderr)
        return 1

    with open(args.output, 'w') as output_file:
        json.dump(
            [e._asdict() for e in sorted(entries)],
            output_file,
            indent=2,
            sort_keys=True,
            separators=(',', ': '))

    with open(args.depfile, 'w+') as depfile:
        depfile.write('%s: %s\n' % (args.output, ' '.join(opened_files)))

    return 0
Example #2
0
    def test_duplicates_same_path(self):
        input = [
            {
                'source': 'some/file',
                'destination': 'bin/foo',
                'label': '//src/foo',
            },
            {
                'source': 'other/stuff',
                'destination': 'bin/bar',
                'label': '//src/bar',
            },
            {
                'source': 'some/file',
                'destination': 'bin/foo',
                'label': '//src/foo',
            },
        ]
        opened_files = set()
        result, error = dm.expand_manifest(input, opened_files)

        expected = [
            Entry(destination='bin/bar',
                  source='other/stuff',
                  label='//src/bar'),
            Entry(destination='bin/foo', source='some/file',
                  label='//src/foo'),
        ]

        self.assertListEqual(result, expected)
        self.assertEqual(opened_files, set())
        self.assertFalse(error)
Example #3
0
    def test_renamed_entries_with_copy(self):
        input = [
            {
                'destination': 'bin/foo',
                'source': 'some-variant/foo',
                'label': '//src/foo(variant)',
            },
            {
                'copy_from': 'some-variant/foo',
                'copy_to': 'foo',
                'label': '//src/foo',
            },
            {
                'destination': 'bin/foo_renamed',
                'renamed_source': 'foo',
            },
        ]
        opened_files = set()
        result, errors = dm.expand_manifest(input, opened_files)

        expected = [
            Entry(destination='bin/foo_renamed',
                  source='some-variant/foo',
                  label='//src/foo(variant)')
        ]
        self.assertListEqual(result, expected)
        self.assertEqual(opened_files, set())
        self.assertFalse(errors)
Example #4
0
    def test_renamed_entries_with_persistent_entry(self):
        input = [
            {
                'destination': 'bin/foo',
                'source': 'some/file',
                'label': '//src/foo',
            },
            {
                'destination': 'bin/bar',
                'renamed_source': 'some/file',
                'label': '//src/bar',
                'keep_original': True,
            },
        ]
        opened_files = set()
        result, error = dm.expand_manifest(input, opened_files)

        expected = [
            Entry(destination='bin/bar', source='some/file',
                  label='//src/bar'),
            Entry(destination='bin/foo', source='some/file',
                  label='//src/foo'),
        ]
        self.assertListEqual(result, expected)
        self.assertEqual(opened_files, set())
        self.assertFalse(error)
Example #5
0
    def test_duplicates_source_conflict(self):
        with tempfile.TemporaryDirectory() as tmpdirname:
            # Create two different files with different content.
            content = 'Some test data'
            file1_path = os.path.join(tmpdirname, 'file1')
            file2_path = os.path.join(tmpdirname, 'file2')
            with open(file1_path, 'w') as f:
                f.write(content)
            with open(file2_path, 'w') as f:
                f.write(content + '!')

            input = [
                {
                    'source': file1_path,
                    'destination': 'bin/foo',
                    'label': '//src/foo1',
                },
                {
                    'source': 'other/stuff',
                    'destination': 'bin/bar',
                    'label': '//src/bar',
                },
                {
                    'source': file2_path,
                    'destination': 'bin/foo',
                    'label': '//src/foo2',
                },
            ]
            opened_files = set()
            result, error = dm.expand_manifest(input, opened_files)

            expected = [
                Entry(
                    destination='bin/bar',
                    source='other/stuff',
                    label='//src/bar'),
                Entry(
                    destination='bin/foo',
                    source=file1_path,
                    label='//src/foo1'),
            ]

            self.assertListEqual(result, expected)
            self.assertEqual(opened_files, {file1_path, file2_path})
            expected_error = 'ERROR: Conflicting distribution entries!\n'
            expected_error += '  Conflicting source paths for destination path: bin/foo\n'
            expected_error += '   - source=%s label=//src/foo1\n' % file1_path
            expected_error += '   - source=%s label=//src/foo2\n' % file2_path

            self.assertEqual(error, expected_error)
Example #6
0
    def test_duplicates_same_content(self):
        with tempfile.TemporaryDirectory() as tmpdirname:
            # Create two different files with the same content.
            content = 'Some test data'
            file1_path = os.path.join(tmpdirname, 'file1')
            file2_path = os.path.join(tmpdirname, 'file2')
            with open(file1_path, 'w') as f:
                f.write(content)
            with open(file2_path, 'w') as f:
                f.write(content)

            input = [
                {
                    'source': file1_path,
                    'destination': 'bin/foo',
                    'label': '//src/foo',
                },
                {
                    'source': 'other/stuff',
                    'destination': 'bin/bar',
                    'label': '//src/bar',
                },
                {
                    'source': file2_path,
                    'destination': 'bin/foo',
                    'label': '//src/foo',
                },
            ]
            opened_files = set()
            result, error = dm.expand_manifest(input, opened_files)

            expected = [
                Entry(
                    destination='bin/bar',
                    source='other/stuff',
                    label='//src/bar'),
                Entry(
                    destination='bin/foo', source=file1_path,
                    label='//src/foo'),
            ]

            self.assertListEqual(result, expected)
            self.assertEqual(opened_files, {file1_path, file2_path})
            self.assertFalse(error)