Skip to content

Commit

Permalink
popen app for samples in windows
Browse files Browse the repository at this point in the history
DocGen.py updated
  • Loading branch information
Foo committed Feb 10, 2024
1 parent 2e95113 commit 412b385
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 125 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ option(LIB_OPT "Compile shared libraries (ON) or static (OFF)" OFF)
option(BUILD_MT_RRT_TESTS "Build MT-RRT tests" OFF)
option(BUILD_MT_RRT_SAMPLES "Build MT-RRT samples" ON)

set(MT_RRT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})

add_subdirectory(extern)

Terraform(src)
Expand Down
145 changes: 110 additions & 35 deletions doc/DocGen.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,110 @@
from FileHandler import *
import os
import subprocess
import shutil

# clean up
shutil.rmtree("./latex", ignore_errors=True)
shutil.rmtree("./html", ignore_errors=True)

# run doxygen
os.system("\"C:\\Program Files\\doxygen\\bin\\doxygen\" doxy_config")

# modify latex src
texHandler = FileHandler("./latex/refman.tex")
texHandler.addAfter("\\renewcommand{\\numberline}[1]{#1~}" , FileHandler("./src/packages.tex").getContent(), 1)
texHandler.addAfter("%--- Begin generated contents ---" , FileHandler("./src/additional_Sections.tex").getContent(), 1)
texHandler.addBefore("\\end{document}", "\\bibliography{../src/ref}{}" + "\n" + "\\bibliographystyle{plain}", 1)
texHandler.reprint("./latex/refman.tex")

# modify compile latex script
docGenHandler = FileHandler("./latex/make.bat")
docGenHandler.addBefore("setlocal enabledelayedexpansion", "bibtex refman")
docGenHandler.replaceLine("set count=8", "set count=4")
docGenHandler.addBefore("cd /D %Dir_Old%", "COPY refman.pdf \"../MT-RRT.pdf\"")
docGenHandler.replaceLine("cd /D %Dir_Old%", "")
docGenHandler.replaceLine("set Dir_Old=", "")
docGenHandler.reprint("./latex/make.bat")

# generate pdf
subprocess.call([r'.\\latex\\make.bat'])

# clean up
shutil.rmtree("./latex", ignore_errors=True)
shutil.rmtree("./html", ignore_errors=True)
shutil.rmtree("__pycache__", ignore_errors=True)
import os, subprocess, shutil

class FileHandler:
def __init__(self, fileName=None):
self.src = fileName
with open(fileName, 'r') as stream:
self.contents = [line.strip() for line in stream.readlines()]

def getContent(self):
return '\n'.join(self.contents)

def reprint(self, fileName = None):
with open(self.src if fileName == None else fileName, 'w') as stream:
stream.write('\n'.join(self.contents))

def replace(self, toReplace, toPut):
self.contents = [line.replace(toReplace, toPut) for line in self.contents]
return self

def replaceLine(self, involvedLine, toPut, instances = None):
for index in self.findLines_(involvedLine, instances):
self.contents[index] = toPut
return self

def addBefore(self, involvedLine, toPut, instances = None):
added = 0
for index in self.findLines_(involvedLine, instances):
self.contents.insert(index + added, toPut)
added += 1
return self

def addAfter(self, involvedLine, toPut, instances = None):
added = 0
for index in self.findLines_(involvedLine, instances):
self.contents.insert(index + added + 1, toPut)
added += 1
return self

def findLines_(self, line, max_instances = None):
indices = []
k = 0
for content in self.contents:
if content == line:
indices.append(k)
if not max_instances == None and len(indices) == max_instances:
break
k += 1
return indices

class Paths:
THIS_FILE_PARENT = os.path.dirname(__file__)
ROOT = os.path.dirname(THIS_FILE_PARENT)

@staticmethod
def make(*args, fromRoot= False):
res = Paths.ROOT if fromRoot else Paths.THIS_FILE_PARENT
for piece in args:
res = os.path.join(res, piece)
return res

def run(cmd, show = False, cwd = None):
print('running {}'.format(' '.join(cmd)))
res = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=cwd, text=True)
if show:
print(res.stdout)
if len(res.stderr) != 0:
print(res.stderr)
res.check_returncode()

def forEachSubFolder(parent):
for name in os.listdir(parent):
name_abs = os.path.join(parent, name)
if os.path.isdir(name_abs):
yield name_abs

class BuildFolder:
def __init__(self):
self.root = Paths.make('build')
shutil.rmtree(self.root, ignore_errors=True) # clean up
os.makedirs(self.root)
self.latex = Paths.make('build', 'latex')
self.html = Paths.make('build', 'html')
self.doxy_config = os.path.join(self.root, 'doxy_config')
shutil.copy(Paths.make('doxy_config'), self.doxy_config)
shutil.copytree(Paths.make('src'), os.path.join(self.root, 'src'))
src = [os.path.join(folder, 'header', 'MT-RRT') for folder in forEachSubFolder(Paths.make('src', fromRoot=True)) ]
print('Identified sources:\n{}'.format('\n'.join(src)))
FileHandler(self.doxy_config).replace('$THE_SOURCES', ' '.join(src)).reprint()

def main():
build_folder = BuildFolder()

run(['doxygen', 'doxy_config'], cwd=build_folder.root)

# modify latex src
texHandler = FileHandler(os.path.join(build_folder.latex, 'refman.tex'))
texHandler.addAfter("\\renewcommand{\\numberline}[1]{#1~}" , FileHandler(Paths.make('src/packages.tex')).getContent(), 1)
texHandler.addAfter("%--- Begin generated contents ---" , FileHandler(Paths.make("src/additional_Sections.tex")).getContent(), 1)
texHandler.addBefore("\\end{document}", "\\bibliography{../src/ref}{}" + "\n" + "\\bibliographystyle{plain}", 1)
texHandler.reprint()

# compile
run(['pdflatex', 'refman'], cwd=build_folder.latex)
run(['bibtex', 'refman'], cwd=build_folder.latex)
for _ in range(0, 3):
run(['pdflatex', 'refman'], cwd=build_folder.latex)
shutil.copy(os.path.join(build_folder.latex, 'refman.pdf'), Paths.make('MT-RRT.pdf'))

if __name__ == '__main__':
main()
70 changes: 0 additions & 70 deletions doc/FileHandler.py

This file was deleted.

Binary file modified doc/MT-RRT.pdf
Binary file not shown.
4 changes: 1 addition & 3 deletions doc/doxy_config
Original file line number Diff line number Diff line change
Expand Up @@ -813,9 +813,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ../src/carpet/header/MT-RRT-carpet \
../src/carpet/header/MT-RRT-core \
../src/multi-threaded/header/MT-RRT-multi-threaded
INPUT = $THE_SOURCES

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
98 changes: 98 additions & 0 deletions launcher/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <stdio.h>
#include <stdlib.h>
#include <string>

#if _WIN64 || _WIN32
#include <windows.h>
#endif

void setUpEnv() {
std::stringstream ss(ENV);
std::string token;
while (ss >> token) {
std::size_t sep = token.find('=');
std::string key = std::string{token, 0, sep};
std::string val = std::string{token, sep + 1};
#if _WIN64 || _WIN32
SetEnvironmentVariable(key.c_str(), val.c_str());
#elif __linux__
setenv(key.c_str(), val.c_str(), 1);
#endif
}
}

struct Command {
template <typename Arg>
static void addArg_(std::stringstream &buff, Arg &&arg) {
buff << arg;
}

template <typename... Args>
Command(const std::string &executable, Args &&...args)
: executable_{executable} {
std::stringstream buff;
(this->addArg_<Args>(buff, std::forward<Args>(args)), ...);
args_ = buff.str();
}

std::string executable_;
std::string args_;

void run() const {
static const std::size_t BUFFER_SIZE = 128;

std::string cmd = executable_ + " " + args_;

std::cout << "running `" << cmd << '`' << std::endl << std::endl;

auto throw_exc = [&cmd]() {
std::stringstream msg;
msg << "Something went wrong running `" << cmd << '`';
throw std::runtime_error{msg.str()};
};

std::string buffer_str;
buffer_str.resize(BUFFER_SIZE);
FILE *fp =
#if _WIN64 || _WIN32
_popen(cmd.c_str(), "r")
#elif __linux__
popen(cmd.c_str(), "r")
#endif
;
if (fp == NULL) {
throw_exc();
}

while (fgets(buffer_str.data(), BUFFER_SIZE, fp) != NULL) {
//std::cout << buffer_str;
}

#if _WIN64 || _WIN32
feof(fp);
#endif

int return_code =
#if _WIN64 || _WIN32
_pclose(fp)
#elif __linux__
pclose(fp)
#endif
;
if (return_code != 0) {
throw_exc();
}
}
};

int main() {
setUpEnv();

Command{BIN_PATH, ARGS}.run();
Command{PYTHON_CMD, SCRIPT, ARGS_SCRIPT}.run();

return EXIT_SUCCESS;
}
4 changes: 2 additions & 2 deletions problems/misc/test/terraform.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
{
"name": "LoggerTests",
"script": "${CMAKE_CURRENT_SOURCE_DIR}/LoggerTests.py",
"args": "'--gtest_filter=*LoggerTest*'"
"args": "--gtest_filter=*LoggerTest*"
},
{
"name": "BoxTests",
"script": "${CMAKE_SOURCE_DIR}/script/common/Figure.py",
"args": "'--gtest_filter=*BoxTest*'"
"args": "--gtest_filter=*BoxTest*"
}
]
}
8 changes: 4 additions & 4 deletions problems/problem-navigation/test/terraform.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
{
"name": "cart_collision_checks",
"script": "${CMAKE_SOURCE_DIR}/problems/problem-navigation/NavigationProblem.py",
"args": "'--gtest_filter=*CartCollisionTest*'",
"args": "--gtest_filter=*CartCollisionTest*",
"args_script": ["--simplified"]
},
{
"name": "cart_traj_computation",
"script": "${CMAKE_SOURCE_DIR}/problems/problem-navigation/test/CartTrajectoryTests.py",
"args": "'--gtest_filter=*trivial_lines:*blended_arc_logic'",
"args": "--gtest_filter=*trivial_lines:*blended_arc_logic",
"args_script": ["--kind", "info"]
},
{
"name": "cart_traj_interpolation",
"script": "${CMAKE_SOURCE_DIR}/problems/problem-navigation/test/CartTrajectoryTests.py",
"args": "'--gtest_filter=*blended_arc_advance_interpolation'",
"args": "--gtest_filter=*blended_arc_advance_interpolation",
"args_script": ["--kind", "traj"]
},
{
"name": "real_problem",
"script": "${CMAKE_SOURCE_DIR}/problems/problem-navigation/NavigationProblem.py",
"args": "'--gtest_filter=RealProblemTest*'"
"args": "--gtest_filter=RealProblemTest*"
}
]
}
2 changes: 1 addition & 1 deletion problems/problem-planarRobots/test/terraform.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "three-dof",
"script": "${CMAKE_SOURCE_DIR}/problems/problem-planarRobots/PlanarRobotsProblem.py",
"args": "'--gtest_filter=*RealProblemTest*'"
"args": "--gtest_filter=*RealProblemTest*"
}
]
}
Loading

0 comments on commit 412b385

Please sign in to comment.