pierventre | 69db90c | 2022-05-06 23:06:20 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 2 | import os |
| 3 | |
| 4 | import subprocess |
| 5 | |
Carmelo Cascone | 21eb042 | 2019-06-17 12:00:33 -0700 | [diff] [blame] | 6 | JAVA_LANGUAGE_LEVEL = 11 |
Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 7 | |
| 8 | EXCLUDE_DIRECTORIES = ( |
| 9 | "target", |
| 10 | ) |
| 11 | |
| 12 | TEST_SOURCES = ( |
| 13 | "*/src/test/*", |
| 14 | ) |
| 15 | |
| 16 | TEMPLATE = """# Autogenerated with {script_name} |
| 17 | workspace_type: java |
| 18 | java_language_level: {language_level} |
Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 19 | |
| 20 | directories: |
| 21 | . |
| 22 | {exclude_dirs} |
| 23 | |
| 24 | targets: |
| 25 | {targets} |
| 26 | |
| 27 | test_sources: |
| 28 | {test_sources} |
| 29 | """ |
| 30 | |
| 31 | |
| 32 | def get_library_targets(): |
| 33 | this_dir = os.path.dirname(os.path.realpath(__file__)) |
pierventre | 69db90c | 2022-05-06 23:06:20 +0200 | [diff] [blame] | 34 | # NOTE that here we depends on bazel generating utf-8 bytes |
Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 35 | out = subprocess.check_output([ |
pierventre | 69db90c | 2022-05-06 23:06:20 +0200 | [diff] [blame] | 36 | "bazel", "query", "kind(\"java_library\", //...:all)"], cwd=this_dir, encoding='UTF-8') |
Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 37 | return out.strip().split("\n") |
| 38 | |
| 39 | |
| 40 | def gen_project(): |
| 41 | all_targets = get_library_targets() |
| 42 | all_targets.sort() |
| 43 | data = { |
| 44 | "script_name": os.path.basename(__file__), |
| 45 | "language_level": JAVA_LANGUAGE_LEVEL, |
| 46 | "exclude_dirs": "\n".join( |
pierventre | 69db90c | 2022-05-06 23:06:20 +0200 | [diff] [blame] | 47 | [" -" + x for x in EXCLUDE_DIRECTORIES]), |
| 48 | "targets": "\n".join([" " + x for x in all_targets]), |
| 49 | "test_sources": "\n".join([" " + x for x in TEST_SOURCES]), |
Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 50 | } |
| 51 | return TEMPLATE.format(**data) |
| 52 | |
| 53 | |
| 54 | if __name__ == "__main__": |
pierventre | 69db90c | 2022-05-06 23:06:20 +0200 | [diff] [blame] | 55 | print(gen_project()) |