blob: 007a13a95ee84481cb00cc06cdba6c3852d32d8e [file] [log] [blame]
pierventre69db90c2022-05-06 23:06:20 +02001#!/usr/bin/env python3
Carmelo Cascone9d16ad82019-02-07 16:07:43 -08002import 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__))
pierventre69db90c2022-05-06 23:06:20 +020034 # NOTE that here we depends on bazel generating utf-8 bytes
Carmelo Cascone9d16ad82019-02-07 16:07:43 -080035 out = subprocess.check_output([
pierventre69db90c2022-05-06 23:06:20 +020036 "bazel", "query", "kind(\"java_library\", //...:all)"], cwd=this_dir, encoding='UTF-8')
Carmelo Cascone9d16ad82019-02-07 16:07:43 -080037 return out.strip().split("\n")
38
39
40def 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(
pierventre69db90c2022-05-06 23:06:20 +020047 [" -" + 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 Cascone9d16ad82019-02-07 16:07:43 -080050 }
51 return TEMPLATE.format(**data)
52
53
54if __name__ == "__main__":
pierventre69db90c2022-05-06 23:06:20 +020055 print(gen_project())