Example #1
0
 def create_project_descriptor_file(self, options):
     filesystem.create_file(
         f"{options.directory}/project.yaml",
         f"name: '{options.project_name}'\n"
         f"version: {options.project_name}\n"
         f"build:\n"
         f"  packages:\n"
         f"  bits:\n"
         f"test:\n"
         f"targets:\n"
         f"  default:\n"
         f"    main: 'main.cpp'\n")
Example #2
0
 def add_test(self, file_name, fails=False):
     if not filesystem.directory_exists('tests'):
         filesystem.create_directory('tests')
     expect = 'false' if fails else 'true'
     filesystem.create_file(
         f'tests/{file_name}', '#include <cest/cest.h>\n'
         'using namespace cest;\n'
         'describe("Test Case", []() {\n'
         '    it("passes", []() {\n'
         f'        expect(true).toBe({expect});\n'
         '    });\n'
         '});\n')
Example #3
0
 def __build_inside_container(self, client, project, image_name, goals, post_build):
     filesystem.create_file(
         f'{constants.BUILD_DIRECTORY}/build.sh',
         f'{constants.CMAKE_COMMAND} -G Ninja /{project.name} && {constants.NINJA_COMMAND} {" ".join(goals)}\n'
         f'{post_build}'
     )
     container = client.containers.run(
         image_name,
         command=f'bash /{project.name}/build/build.sh',
         working_dir=f'/{project.name}/build',
         volumes={f'{os.getcwd()}': {'bind': f'/{project.name}', 'mode': 'rw'}},
         user=f'{os.getuid()}:{os.getgid()}',
         environment=[f'PROJECT_NAME={project.name}', f'PROJECT_VERSION={project.version}'],
         detach=True
     )
     print(f'cpm: building inside {container.short_id}')
     for log in container.logs(stream=True):
         sys.stdout.write(log.decode())
     exit_code = container.wait()
     if exit_code['StatusCode'] != 0:
         raise BuildError
     container.remove()
Example #4
0
 def add_main_with_user_include(self):
     filesystem.create_file(
         f'main.cpp', '#include <user_include.h>\n'
         'int main(int argc, char *argv[]) {\n'
         '    return 0;\n'
         '}\n')
Example #5
0
 def generate_sample_code(self, project):
     project.build.add_sources(['main.cpp'])
     filesystem.create_file(f'{project.name}/main.cpp', CPP_HELLO_WORLD)