71 lines
1.9 KiB
Python
71 lines
1.9 KiB
Python
import json
|
|
import os
|
|
import sys
|
|
import time
|
|
|
|
def main(flag_file:str,target:str):
|
|
make_flags=flag_file
|
|
current_path=os.path.abspath('.')
|
|
if(make_flags!='clear'):
|
|
with open(make_flags,encoding='utf-8') as f:
|
|
flags=f.read()
|
|
print(time.strftime("%Y-%m-%d %H:%M:%S"),"append vscode setting.")
|
|
print('\ttarget: ',target)
|
|
else:
|
|
flags=""
|
|
print(time.strftime("%Y-%m-%d %H:%M:%S"),"clear vscode setting.")
|
|
cfgs_file_path='/mnt/disk/work/kunlun/.vscode/c_cpp_properties.json'
|
|
with open(cfgs_file_path,encoding='utf-8') as f:
|
|
cfgs=f.read()
|
|
|
|
flags_list=flags.split()
|
|
flags_list=list(set(flags_list))
|
|
inc_list=[]
|
|
def_list=[]
|
|
for item in flags_list:
|
|
if(item[:2]=='-D'):
|
|
def_list.append(item[2:])
|
|
elif(item[:2]=='-I'):
|
|
p=item[2:]
|
|
if(p[0]!='/'):
|
|
p=os.path.join(current_path,p)
|
|
if(os.path.exists(p)):
|
|
inc_list.append(p)
|
|
else:
|
|
print("\tinvalid inc path: ",p)
|
|
|
|
|
|
cfg=json.loads(cfgs)
|
|
predef_info=cfg["configurations"][0]
|
|
if(make_flags!='clear'):
|
|
predef_info["name"]="myname"
|
|
for item in inc_list:
|
|
if(item not in predef_info["includePath"]):
|
|
predef_info["includePath"].append(item)
|
|
for item in def_list:
|
|
if(item not in predef_info["defines"]):
|
|
predef_info["defines"].append(item)
|
|
else:
|
|
predef_info["includePath"]=[]
|
|
predef_info["defines"]=[]
|
|
|
|
with open(cfgs_file_path,mode='w+', encoding='utf-8') as f:
|
|
f.write(json.dumps(cfg,sort_keys=True, indent=2, separators=(',', ': ')))
|
|
|
|
|
|
if __name__=="__main__":
|
|
if(len(sys.argv)>=2):
|
|
if(len(sys.argv)>=3):
|
|
target=sys.argv[2]
|
|
else:
|
|
target="null"
|
|
main(sys.argv[1],target)
|
|
else:
|
|
print("kill me.")
|
|
|
|
|
|
|
|
|
|
|
|
|