blob: c12f10d790916d4c1dde8ed21e62fccf7e5d47a0 [file] [log] [blame]
Alex Light705ad492015-09-21 11:36:30 -07001#!/usr/bin/python3
2#
3# Copyright (C) 2015 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""
18Generate java test files for test 966.
19"""
20
21import generate_smali as base
22import os
23import sys
24from pathlib import Path
25
26BUILD_TOP = os.getenv("ANDROID_BUILD_TOP")
27if BUILD_TOP is None:
28 print("ANDROID_BUILD_TOP not set. Please run build/envsetup.sh", file=sys.stderr)
29 sys.exit(1)
30
31# Allow us to import mixins.
32sys.path.append(str(Path(BUILD_TOP)/"art"/"test"/"utils"/"python"))
33
34import testgen.mixins as mixins
35
36class JavaConverter(mixins.DumpMixin, mixins.Named, mixins.JavaFileMixin):
37 """
38 A class that can convert a SmaliFile to a JavaFile.
39 """
40 def __init__(self, inner):
41 self.inner = inner
42
43 def get_name(self):
44 return self.inner.get_name()
45
46 def __str__(self):
47 out = ""
48 for line in str(self.inner).splitlines(keepends = True):
49 if line.startswith("#"):
50 out += line[1:]
51 return out
52
53def main(argv):
54 final_java_dir = Path(argv[1])
55 if not final_java_dir.exists() or not final_java_dir.is_dir():
56 print("{} is not a valid java dir".format(final_java_dir), file=sys.stderr)
57 sys.exit(1)
58 initial_java_dir = Path(argv[2])
59 if not initial_java_dir.exists() or not initial_java_dir.is_dir():
60 print("{} is not a valid java dir".format(initial_java_dir), file=sys.stderr)
61 sys.exit(1)
62 expected_txt = Path(argv[3])
63 mainclass, all_files = base.create_all_test_files()
64 with expected_txt.open('w') as out:
65 print(mainclass.get_expected(), file=out)
66 for f in all_files:
67 if f.initial_build_different():
68 JavaConverter(f).dump(final_java_dir)
69 JavaConverter(f.get_initial_build_version()).dump(initial_java_dir)
70 else:
71 JavaConverter(f).dump(initial_java_dir)
72 if isinstance(f, base.TestInterface):
73 JavaConverter(f).dump(final_java_dir)
74
75
76if __name__ == '__main__':
77 main(sys.argv)