2929import 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
5252if __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 )
0 commit comments