Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

scripts: fix compile_thrift.py; remove useless file #100

Merged
merged 2 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions compile_thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"file_move": {
".types.h _types.h": "include/dsn/cpp/serialization_helper",
"_types.cpp": "src/dev/cpp"
"_types.cpp": "src/core/core"
}
},
{
Expand Down Expand Up @@ -73,7 +73,8 @@
"add": ["<dsn/dist/replication/replication_types.h>"],
"remove": ["\"replication_types.h\""]
}
}
},
"add_end_newline": ["replication.types.h"]
},
{
"name": "simple_kv",
Expand Down Expand Up @@ -193,6 +194,29 @@ def replace_struct_usage(cpp_file, enum_class):
sed_exp = "sed -i " + " ".join(["-e \'s/%s::type/%s/\'"%(i,i) for i in enum_class]) + " " + cpp_file
os.system(sed_exp)

def add_end_newline_file(filename):
tmp_result = filename + ".swapfile"
from_fd, to_fd = open(filename, "r"), open(tmp_result, "w")

for line in from_fd:
to_fd.write(line)
to_fd.write("\n");

from_fd.close()
to_fd.close()

os.remove(filename)
os.rename(tmp_result, filename)

def add_end_newline(thrift_name, add_end_newline_list):
# current dir is thrift file dir
os.chdir("output")

for filename in add_end_newline_list:
add_end_newline_file(filename)

os.chdir("..")

def fix_include_file(filename, fix_commands):
tmp_result = filename + ".swapfile"
from_fd, to_fd = open(filename, "r"), open(tmp_result, "w")
Expand Down Expand Up @@ -270,6 +294,9 @@ def compile_thrift_file(thrift_info):
os.system("cp build/%s_types.cpp output"%(thrift_name))
os.system("rm -rf build")

if "add_end_newline" in thrift_info:
add_end_newline(thrift_name, thrift_info["add_end_newline"])

if "include_fix" in thrift_info:
fix_include(thrift_name, thrift_info["include_fix"])

Expand Down
Loading