| #!/usr/bin/env python3 |
| import os |
| |
| import subprocess |
| |
| JAVA_LANGUAGE_LEVEL = 11 |
| |
| EXCLUDE_DIRECTORIES = ( |
| "target", |
| ) |
| |
| TEST_SOURCES = ( |
| "*/src/test/*", |
| ) |
| |
| TEMPLATE = """# Autogenerated with {script_name} |
| workspace_type: java |
| java_language_level: {language_level} |
| |
| directories: |
| . |
| {exclude_dirs} |
| |
| targets: |
| {targets} |
| |
| test_sources: |
| {test_sources} |
| """ |
| |
| |
| def get_library_targets(): |
| this_dir = os.path.dirname(os.path.realpath(__file__)) |
| # NOTE that here we depends on bazel generating utf-8 bytes |
| out = subprocess.check_output([ |
| "bazel", "query", "kind(\"java_library\", //...:all)"], cwd=this_dir, encoding='UTF-8') |
| return out.strip().split("\n") |
| |
| |
| def gen_project(): |
| all_targets = get_library_targets() |
| all_targets.sort() |
| data = { |
| "script_name": os.path.basename(__file__), |
| "language_level": JAVA_LANGUAGE_LEVEL, |
| "exclude_dirs": "\n".join( |
| [" -" + x for x in EXCLUDE_DIRECTORIES]), |
| "targets": "\n".join([" " + x for x in all_targets]), |
| "test_sources": "\n".join([" " + x for x in TEST_SOURCES]), |
| } |
| return TEMPLATE.format(**data) |
| |
| |
| if __name__ == "__main__": |
| print(gen_project()) |