Skip to content

Commit a8513a5

Browse files
author
Paul Johnston
committed
Cleanup unused code
1 parent c2b6f38 commit a8513a5

3 files changed

Lines changed: 7 additions & 50 deletions

File tree

compdb/postprocess.py

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"""Generates a compile_commands.json file at $(bazel info workspace) for
1818
libclang based tools.
1919
20-
This is modified from
20+
Derived from
2121
https://github.com/grailbio/bazel-compilation-database/blob/08d706d3cf7daf3d529a26ca76d75da1a3eae6c0/generate.py
2222
"""
2323

@@ -29,26 +29,6 @@
2929
import tempfile
3030

3131

32-
# _BAZEL = os.getenv("BAZEL_COMPDB_BAZEL_PATH") or "bazel"
33-
34-
# def bazel_info():
35-
# """Returns a dict containing key values from bazel info."""
36-
37-
# bazel_info_dict = dict()
38-
# try:
39-
# out = subprocess.check_output([_BAZEL, 'info', 'execution_root', 'workspace', 'bazel-bin']).decode('utf-8').strip().split('\n')
40-
# except subprocess.CalledProcessError as err:
41-
# # This exit code is returned when this command is run outside of a bazel workspace.
42-
# if err.returncode == 2:
43-
# sys.exit(0)
44-
# sys.exit(err.returncode)
45-
46-
# for line in out:
47-
# key_val = line.strip().partition(": ")
48-
# bazel_info_dict[key_val[0]] = key_val[2]
49-
50-
# return bazel_info_dict
51-
5232
if __name__ == "__main__":
5333
##
5434
## Setup Args
@@ -60,45 +40,27 @@
6040
help="build events json file from the compilation aspect")
6141
args = parser.parse_args()
6242

63-
##
64-
## Setup Bazel Metadata
65-
##
66-
# print("Gathering bazel info...")
67-
# bazel_info_dict = bazel_info()
68-
# bazel_exec_root = bazel_info_dict['execution_root']
69-
# bazel_workspace = bazel_info_dict['workspace']
70-
71-
# want 'bazel-out/darwin-fastbuild/bin'
72-
# bazel_bin = bazel_info_dict['bazel-bin']
73-
# if bazel_bin.startswith(bazel_exec_root):
74-
# bazel_bin = bazel_bin[len(bazel_exec_root)+1:]
75-
7643
##
7744
## Parse Build Events
7845
##
7946
print("Gathering output files...")
47+
8048
local_exec_root = '__EXEC_ROOT__'
8149
workspace_directory = '__WORKSPACE__'
82-
build_events = []
8350
bazel_stderr = []
8451
with open(args.build_events_json_file, 'r') as f:
8552
for line in f:
86-
# print(line)
8753
event = json.loads(line)
8854
if 'started' in event:
8955
workspace_directory = event['started']['workspaceDirectory']
9056
print("Workspace Directory:", workspace_directory)
9157
elif 'progress' in event:
9258
if 'stderr' in event['progress']:
93-
# print(event['progress']['stderr'])
9459
bazel_stderr.extend(event['progress']['stderr'].splitlines())
95-
9660
elif 'workspaceInfo' in event:
9761
local_exec_root = event['workspaceInfo']['localExecRoot']
9862
print('Execution Root:', local_exec_root)
9963

100-
build_events.append(event)
101-
10264
compile_command_json_db_files = []
10365
for line in bazel_stderr:
10466
if line.endswith('.compile_commands.json'):
@@ -107,31 +69,31 @@
10769
##
10870
## Collect/Fix/Merge Compilation Databases
10971
##
110-
print("Collecting target databases...")
72+
print("Preparing compilation database...")
73+
11174
db_entries = []
11275
for db in compile_command_json_db_files:
11376
with open(db, 'r') as f:
11477
db_entries.extend(json.load(f))
11578

116-
print("Fixing up commands...")
11779
def fix_db_entry(db_entry):
11880
if 'directory' in db_entry and db_entry['directory'] == '__EXEC_ROOT__':
11981
db_entry['directory'] = bazel_workspace if args.source_dir else local_exec_root
82+
# TODO: research better if this is advantageous
12083
# if 'file' in db_entry and db_entry['file'].startswith(bazel_bin):
12184
# db_entry['file'] = db_entry['file'][len(bazel_bin)+1:]
12285
if 'command' in db_entry:
12386
command = db_entry['command']
12487
if command:
12588
command = command.replace('-isysroot __BAZEL_XCODE_SDKROOT__', '')
89+
# -iquote seems to misbehave with vscode
12690
command = command.replace('-iquote', '-I')
12791
db_entry['command'] = command
12892
return db_entry
12993
db_entries = list(map(fix_db_entry, db_entries))
13094

13195
compdb_file = os.path.join(workspace_directory, "compile_commands.json")
13296

133-
# os.chdir(bazel_workspace)
134-
13597
with open(compdb_file, 'w') as outdb:
13698
json.dump(db_entries, outdb, indent=2)
13799

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"Other"
2727
],
2828
"activationEvents": [
29-
"onView:bsv.bzl.bep",
3029
"onCommand:bsv.cc.compdb.generate"
3130
],
3231
"extensionDependencies": [

src/compilation_database.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class CompilationDatabase implements vscode.Disposable {
2525
vscode.window.showInformationMessage('Building clang compilation database for ' + JSON.stringify(targets));
2626

2727
const execution = await vscode.tasks.executeTask(new GenerateCompilationDatabaseCommand(
28-
"bazel-vscode-compdb",
28+
"bazel-compdb",
2929
bazel,
3030
Container.file("compdb/"),
3131
targets,
@@ -99,10 +99,6 @@ class GenerateCompilationDatabaseCommand {
9999
env: this.env,
100100
cwd: this.cwd,
101101
});
102-
// const execution = new vscode.ProcessExecution(this.bazel, this.makeCommand(), {
103-
// env: this.env,
104-
// cwd: this.cwd,
105-
// });
106102
const task = new vscode.Task(taskDefinition, scope, this.name, source, execution);
107103
task.presentationOptions = {
108104
clear: true,

0 commit comments

Comments
 (0)