Skip to content
Snippets Groups Projects
Commit 445828b2 authored by Elizabeth's avatar Elizabeth
Browse files

Added code to handle relative paths in original sources

parent 896fc139
No related branches found
No related tags found
No related merge requests found
......@@ -29,16 +29,67 @@ def generate_cmakelists_setup(cmakelists_file):
Assumption: All setup instructions are being any add_executable instructions
'''
BASE_CMAKELISTS_PATH = "/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/CMakeLists.txt"
base_cmakelists_file = open(BASE_CMAKELISTS_PATH, "r")
BASE_CMAKELISTS_PATH = "/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt"
base_cmakelists_file = open(os.path.join(BASE_CMAKELISTS_PATH, "CMakeLists.txt"), "r")
find_lib_line = ""
for line in base_cmakelists_file:
if line.startswith("#"):
continue
if line.find("add_executable") != -1:
break
elif line.startswith("#"):
continue
elif line.find("/") != -1: #line.find("../") != -1 or line.find("./") != -1:
dot_dot_slash_ind = line.find("../")
dot_slash_ind = line.find("./")
if dot_dot_slash_ind != -1:
start_ind = dot_dot_slash_ind
elif dot_slash_ind != -1:
start_ind = dot_slash_ind
else:
slash_ind = line.find("/")
prev_space_ind = line[:slash_ind].rfind(" ")
start_ind = prev_space_ind + 1
old_rel_path = []
while start_ind < len(line):
if line[start_ind] == ")" or line[start_ind].isspace():
break
old_rel_path.append(line[start_ind])
start_ind += 1
old_rel_path = ''.join(old_rel_path)
if os.path.isabs(old_rel_path):
cmakelists_file.write(line)
else:
new_path = os.path.join(BASE_CMAKELISTS_PATH, old_rel_path)
cmakelists_file.write(line.replace(old_rel_path, new_path))
continue
'''
elif line.startswith("include_directories"):
old_rel_path = line[line.find("(") + 1: line.find(")")]
# Not actually a rel path
if old_rel_path.find(".") == -1 and old_rel_path.find("..") == -1:
cmakelists_file.write(line)
else:
new_path = os.path.join(BASE_CMAKELISTS_PATH, old_rel_path)
cmakelists_file.write(line.replace(old_rel_path, new_path))
continue
elif line.startswith("find_library"):
find_lib_line += line
if line.endswith(")"):
find_lib_line = ""
else:
continue
'''
cmakelists_file.write(line)
base_cmakelists_file.close()
# include_directoryes
# find_library
def generate_cmakelists_file(cmakelists_file, source_file_dirs):
generate_cmakelists_setup(cmakelists_file)
......@@ -61,6 +112,7 @@ def generate_cmakelists_file(cmakelists_file, source_file_dirs):
cmake_instrs.append("\n")
cmakelists_file.write('\n'.join(cmake_instrs))
if __name__ == "__main__":
num_args = len(sys.argv)
......
......@@ -40,11 +40,12 @@ def get_new_path(old_path, orig_source_code_dir):
Args:
old_path: Original path of file that's being included
orig_source_code_dir: Path to original source code dir wrt the generated dir
orig_source_code_dir: Path to original source code dir wrt the current dir
'''
if os.path.isabs(old_path): # Old path works
return old_path
return os.path.join(orig_source_code_dir, old_path)
# Adding an extra .. because the path should be wrt the generated directory
return os.path.join("..", orig_source_code_dir, old_path)
def generate_source_code(table, dir_name, filename, source_name):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment