blob: 91fffa0fdd954990c1ffebf1fca24f05ea66ed09 [file] [log] [blame]
Søren Gjessed393be22025-02-24 13:24:09 +01001#!/usr/bin/env python3
2# Copyright (c) 2025, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6import argparse
7import os
8import shutil
9import sys
10import utils
11
12
13KOTLIN_EXTENSION = '.kt'
14# Extension used by androidx KMP libraries for Kotlin files with code
15# targeting the JVM.
16JVM_KOTLIN_EXTENSION = '.jvm.kt'
17
18
19def parse_options():
20 parser = argparse.ArgumentParser(description='Update androidx keep annotations')
21 parser.add_argument('--androidx',
22 metavar=('<path>'),
23 required=True,
24 help='Path to the androidx checkout')
25 return parser.parse_args()
26
27
28def main():
29 args = parse_options()
30
31 source_dir = os.path.join(
32 utils.REPO_ROOT,
33 'src',
34 'keepanno',
35 'java',
36 'androidx',
37 'annotation',
38 'keep')
39 dest_dir = os.path.join(
40 args.androidx,
41 'frameworks',
42 'support',
43 'annotation',
44 'annotation-keep',
45 'src',
46 'jvmMain',
47 'kotlin',
48 'androidx',
49 'annotation',
50 'keep')
51
52 for root, dirnames, filenames in os.walk(source_dir):
53 if root != source_dir:
54 print('Unexpected subdirectory under {source_dir}.'
55 .format(source_dir=source_dir))
56 if len(dirnames) > 0:
57 print('Unexpected subdirectories under {dirnames}.'
58 .format(dirnames=dirnames))
59 for filename in filenames:
60 if not filename.endswith(KOTLIN_EXTENSION):
61 print('Unexpected non Kotlin file {filename}.'
62 .format(filename=os.path.join(root, filename)))
63 sys.exit(1)
64 new_filename = filename[0:len(filename) - len(KOTLIN_EXTENSION)] + JVM_KOTLIN_EXTENSION
65
66 shutil.copyfile(
67 os.path.join(root, filename),
68 os.path.join(dest_dir, new_filename))
69
70
71if __name__ == '__main__':
72 sys.exit(main())