Commit 6f46ab25 authored by Olivier Stasse's avatar Olivier Stasse
Browse files

[scripts/robotpkg_helpers] Documentation of

Add Dockerfile for the repo to be tested
Add image name when building robotpkg for the CI.
parent 68f6a9ea
......@@ -23,18 +23,32 @@ class RobotpkgGenerateDockerFile:
ROBOTPKG_ROOT_SRC: The path to robotpkg sources.
dst_dir: The path where the files should be generated
# Set debug mode (default set to 0)
# Set the path to the CMakeLists.txt of the repository to analyze.
self.CMakeLists_txt_path = CMakeLists_txt_path
# Set the path where generating the Dockerfiles and copy the robotpkg_helpers
self.dst_dir = dst_dir
# Create dst_dir if needed
# Create the object analyzing robotpkg
self.robotpkg_src_intro = RobotpkgSrcIntrospection(ROBOTPKG_ROOT_SRC)
# Analyzes the CMakeLists.txt file
# Check which packages are provided by robotpkg and which are provided by the OS
# This part is still very fragile and error prone.
# Display the packages found and split them into robotpkg and OS.
# Generates the python script to compile the necessary packages and their release version
# Generates the docker files
#if debug>3:
def init_colors(self):
......@@ -49,11 +63,15 @@ class RobotpkgGenerateDockerFile:
self.NC = '\033[0m'
def check_dst_dir(self):
""" This methods check if the destination directory exists and if not creates it
if not os.path.isdir(self.dst_dir):
def prepare_dst_dir(self):
""" This methods copy the robotpkg_helpers module necessary to create the docker image
current_py_file= (inspect.getfile(inspect.currentframe()) ) # script filename (usually with path)
# Find path where this current python script is located
src_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) # script director
......@@ -62,6 +80,9 @@ class RobotpkgGenerateDockerFile:
def jrl_cmake_module_analysis(self,cmake_content):
""" This methods extracts from the file CMakeLists.txt of the repository to analyze
useful informations
# Search for ADD_[REQUIRED|OPTIONAL]_DEPENDENCY and put it in the list of files
for project_name in re.findall(r'SET\s*\(\s*PROJECT\_NAME\s*([^\s>="\')]+)\s*\)',
cmake_content, re.I):
......@@ -151,8 +172,8 @@ class RobotpkgGenerateDockerFile:
os.chmod(filename,stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |stat.S_IROTH | stat.S_IXOTH )
def generate_docker_file(self):
""" This methods generates the dockerfile to compile robotpkg and the repository being analyzed.
def generate_docker_file_for_img(self):
""" This methods generates the dockerfile to compile robotpkg and test the the repository being analyzed.
filename = self.dst_dir + "/Dockerfile"
with open(filename,"w") as f:
......@@ -175,9 +196,23 @@ class RobotpkgGenerateDockerFile:
f.write("RUN /usr/bin/python3 ./\n")
def generate_docker_file_for_test(self):
""" This methods generates a file named Dockerfile to test the repository being analyzed.
It is done using the image created by the file Dockerfile created by generate_docker_file_for_img()
This Dockerfile assumes a clean repository.
filename = self.dst_dir + "/Dockerfile_" + self.project_name
with open(filename,"w") as f:
f.write("FROM "+ self.project_name + "_img")
f.write("COPY . /app")
f.write("RUN mkdir /app/build")
f.write("RUN cmake -DCMAKE_BUILD_TYPE=DEBUG --build /app/build /app")
f.write("RUN make --directory=/app/build")
def build_docker(self):
print("Build docker file")
self.env = os.environ.copy()
bash_cmd = "docker build -f " + self.dst_dir + "/Dockerfile "+self.dst_dir
bash_cmd = "docker build -f " + self.dst_dir + "/Dockerfile "+self.dst_dir + " --tag=" + self.project_name + "_img"
execute(bash_cmd, self.env,3)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment