blob: 355193a39be413614e4198faa455351da6bd315b [file] [log] [blame]
Carmelo Cascone9d16ad82019-02-07 16:07:43 -08001#!/usr/bin/env python2.7
2import os
3
4import subprocess
5
Carmelo Cascone21eb0422019-06-17 12:00:33 -07006JAVA_LANGUAGE_LEVEL = 11
Carmelo Cascone9d16ad82019-02-07 16:07:43 -08007
8EXCLUDE_DIRECTORIES = (
9 "target",
10)
11
12TEST_SOURCES = (
13 "*/src/test/*",
14)
15
16TEMPLATE = """# Autogenerated with {script_name}
17workspace_type: java
18java_language_level: {language_level}
Carmelo Cascone9d16ad82019-02-07 16:07:43 -080019
20directories:
21 .
22{exclude_dirs}
23
24targets:
25{targets}
26
27test_sources:
28{test_sources}
29"""
30
31
32def 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
39def 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
53if __name__ == "__main__":
54 print gen_project()