Skip to content

Commit c2b6f38

Browse files
author
Paul Johnston
committed
Cleanup prosprocess.py
1 parent 56a4547 commit c2b6f38

5 files changed

Lines changed: 114 additions & 69 deletions

File tree

compdb/postprocess.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@
2929
import tempfile
3030

3131

32-
_BAZEL = os.getenv("BAZEL_COMPDB_BAZEL_PATH") or "bazel"
32+
# _BAZEL = os.getenv("BAZEL_COMPDB_BAZEL_PATH") or "bazel"
3333

34-
def bazel_info():
35-
"""Returns a dict containing key values from bazel info."""
34+
# def bazel_info():
35+
# """Returns a dict containing key values from bazel info."""
3636

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)
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)
4545

46-
for line in out:
47-
key_val = line.strip().partition(": ")
48-
bazel_info_dict[key_val[0]] = key_val[2]
46+
# for line in out:
47+
# key_val = line.strip().partition(": ")
48+
# bazel_info_dict[key_val[0]] = key_val[2]
4949

50-
return bazel_info_dict
50+
# return bazel_info_dict
5151

5252
if __name__ == "__main__":
5353
##
@@ -63,19 +63,15 @@ def bazel_info():
6363
##
6464
## Setup Bazel Metadata
6565
##
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']
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']
7070

7171
# 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-
76-
compdb_file = os.path.join(bazel_workspace, "compile_commands.json")
77-
78-
os.chdir(bazel_workspace)
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:]
7975

8076
##
8177
## Parse Build Events
@@ -107,7 +103,6 @@ def bazel_info():
107103
for line in bazel_stderr:
108104
if line.endswith('.compile_commands.json'):
109105
compile_command_json_db_files.append(line.strip())
110-
print("STDERR", line)
111106

112107
##
113108
## Collect/Fix/Merge Compilation Databases
@@ -121,9 +116,9 @@ def bazel_info():
121116
print("Fixing up commands...")
122117
def fix_db_entry(db_entry):
123118
if 'directory' in db_entry and db_entry['directory'] == '__EXEC_ROOT__':
124-
db_entry['directory'] = bazel_workspace if args.source_dir else bazel_exec_root
125-
if 'file' in db_entry and db_entry['file'].startswith(bazel_bin):
126-
db_entry['file'] = db_entry['file'][len(bazel_bin)+1:]
119+
db_entry['directory'] = bazel_workspace if args.source_dir else local_exec_root
120+
# if 'file' in db_entry and db_entry['file'].startswith(bazel_bin):
121+
# db_entry['file'] = db_entry['file'][len(bazel_bin)+1:]
127122
if 'command' in db_entry:
128123
command = db_entry['command']
129124
if command:
@@ -133,6 +128,10 @@ def fix_db_entry(db_entry):
133128
return db_entry
134129
db_entries = list(map(fix_db_entry, db_entries))
135130

131+
compdb_file = os.path.join(workspace_directory, "compile_commands.json")
132+
133+
# os.chdir(bazel_workspace)
134+
136135
with open(compdb_file, 'w') as outdb:
137136
json.dump(db_entries, outdb, indent=2)
138137

@@ -148,6 +147,6 @@ def fix_db_entry(db_entry):
148147
except FileNotFoundError:
149148
pass
150149
# This is for libclang to help find source files from external repositories.
151-
os.symlink(os.path.join(bazel_exec_root, 'external'),
150+
os.symlink(os.path.join(local_exec_root, 'external'),
152151
link_name,
153152
target_is_directory=True)

package-lock.json

Lines changed: 38 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"name": "bazel-stack-vscode-cc",
44
"displayName": "bazel-stack-vscode-cc",
55
"description": "C/C++ Support For Bazel Stack VSCode Extension",
6-
"version": "1.0.1",
6+
"version": "1.1.0",
77
"icon": "stackb-cc.png",
88
"engines": {
99
"vscode": "^1.45.0"
@@ -26,13 +26,36 @@
2626
"Other"
2727
],
2828
"activationEvents": [
29-
"onView:bsv.bzl.bep"
29+
"onView:bsv.bzl.bep",
30+
"onCommand:bsv.cc.compdb.generate"
3031
],
3132
"extensionDependencies": [
3233
"stackbuild.bazel-stack-vscode"
3334
],
3435
"main": "./out/extension.js",
3536
"contributes": {
37+
"configuration": {
38+
"type": "object",
39+
"title": "Bazel/C++",
40+
"properties": {
41+
"bsv.cc.compdb.targets": {
42+
"type": "array",
43+
"description": "List of targets to index when creating the compile_commands.json file.",
44+
"items": {
45+
"type": "string"
46+
},
47+
"default": []
48+
}
49+
}
50+
},
51+
"commands": [
52+
{
53+
"category": "Bzl",
54+
"command": "bsv.cc.compdb.generate",
55+
"title": "Bazel/C++: Generate Compilation Database",
56+
"icon": "$(gear)"
57+
}
58+
],
3659
"problemMatchers": [
3760
{
3861
"name": "CppCompile",
@@ -61,20 +84,22 @@
6184
"vscode-install": "vsce package --out ext.vsix && code --install-extension ext.vsix"
6285
},
6386
"devDependencies": {
64-
"@types/vscode": "^1.45.0",
6587
"@types/glob": "^7.1.1",
6688
"@types/mocha": "^7.0.2",
6789
"@types/node": "^13.11.0",
68-
"eslint": "^6.8.0",
69-
"@typescript-eslint/parser": "^2.30.0",
90+
"@types/tmp": "^0.2.1",
91+
"@types/vscode": "^1.45.0",
7092
"@typescript-eslint/eslint-plugin": "^2.30.0",
93+
"@typescript-eslint/parser": "^2.30.0",
94+
"eslint": "^6.8.0",
7195
"glob": "^7.1.6",
7296
"mocha": "^7.1.2",
7397
"typescript": "^3.8.3",
7498
"vscode-common": "1.49.0",
7599
"vscode-test": "^1.3.0"
76100
},
77101
"dependencies": {
78-
"bazel-stack-vscode-api": "^1.2.2"
102+
"bazel-stack-vscode-api": "^1.2.2",
103+
"tmp": "^0.2.1"
79104
}
80-
}
105+
}

src/compilation_database.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ export class CompilationDatabase implements vscode.Disposable {
1515
async generate() {
1616
const bazel = "bazel";
1717
const cwd = Container.workspaceFolderFsPath || ".";
18-
const targets = [
19-
"//absl/time:time",
20-
];
18+
const config = vscode.workspace.getConfiguration('bsv.cc.compdb');
19+
const targets = config.get<string[] | undefined>('targets', undefined);
20+
if (!targets || targets.length === 0) {
21+
vscode.window.showErrorMessage('The list of bazel targets to index for the compilation database is not configured. Please configure the "bsv.cc.compdb.targets" workspace setting to include a list of cc_library, cc_binary labels');
22+
return;
23+
}
2124

22-
vscode.window.showInformationMessage("Compilation database created!");
25+
vscode.window.showInformationMessage('Building clang compilation database for ' + JSON.stringify(targets));
2326

2427
const execution = await vscode.tasks.executeTask(new GenerateCompilationDatabaseCommand(
2528
"bazel-vscode-compdb",
@@ -30,7 +33,6 @@ export class CompilationDatabase implements vscode.Disposable {
3033
{},
3134
this.disposables,
3235
).newTask());
33-
3436
}
3537

3638
dispose() {
@@ -73,8 +75,8 @@ class GenerateCompilationDatabaseCommand {
7375
"--override_repository=bazel_vscode_compdb=" + this.repositoryPath.fsPath,
7476
"--aspects=@bazel_vscode_compdb//:aspects.bzl%compilation_database_aspect",
7577
"--color=no",
76-
"--show_progress",
77-
"--show_loading_progress",
78+
"--noshow_progress",
79+
"--noshow_loading_progress",
7880
"--output_groups=compdb_files,header_files",
7981
"--build_event_json_file=" + this.buildEventsJsonTempFile,
8082
...this.targets,

0 commit comments

Comments
 (0)