Carmelo Cascone | 9d16ad8 | 2019-02-07 16:07:43 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python2.7 |
| 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__)) |
| 34 | out = subprocess.check_output([ |
| 35 | "bazel", "query", "kind(\"java_library\", //...:all)"], cwd=this_dir) |
| 36 | return out.strip().split("\n") |
| 37 | |
| 38 | |
| 39 | def gen_project(): |
| 40 | all_targets = get_library_targets() |
| 41 | all_targets.sort() |
| 42 | data = { |
| 43 | "script_name": os.path.basename(__file__), |
| 44 | "language_level": JAVA_LANGUAGE_LEVEL, |
| 45 | "exclude_dirs": "\n".join( |
| 46 | map(lambda x: " -" + x, EXCLUDE_DIRECTORIES)), |
| 47 | "targets": "\n".join(map(lambda x: " " + x, all_targets)), |
| 48 | "test_sources": "\n".join(map(lambda x: " " + x, TEST_SOURCES)), |
| 49 | } |
| 50 | return TEMPLATE.format(**data) |
| 51 | |
| 52 | |
| 53 | if __name__ == "__main__": |
| 54 | print gen_project() |