| #!/usr/bin/env python2.7 |
| 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__)) |
| out = subprocess.check_output([ |
| "bazel", "query", "kind(\"java_library\", //...:all)"], cwd=this_dir) |
| 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( |
| map(lambda x: " -" + x, EXCLUDE_DIRECTORIES)), |
| "targets": "\n".join(map(lambda x: " " + x, all_targets)), |
| "test_sources": "\n".join(map(lambda x: " " + x, TEST_SOURCES)), |
| } |
| return TEMPLATE.format(**data) |
| |
| |
| if __name__ == "__main__": |
| print gen_project() |