Skip to content

Creating your own generator

Demez edited this page Feb 16, 2020 · 2 revisions

To make a generator for qpc, all you need to do is make a single python script and place it in "project_generators/" in qpc's folder

In that scripts, add these lines:

from qpc_args import args  # so you can access the arguments if needed
from qpc_base import BaseProjectGenerator, Platform, PLATFORM_DICT
from qpc_project import Compiler, PrecompiledHeader, ConfigType, Language

these other ones are recommended to be used for type hinting, which i require if you want to pull request it

from qpc_project import Project, ProjectPass
from qpc_parser import BaseInfo

All Project Generators inherit a base class, called BaseProjectGenerator

Make a class that inherits BaseProjectGenerator, and it should look something like this:

class ExampleGenerator(BaseProjectGenerator):
    def __init__(self):
        super().__init__("Generator Name")

In the __init__ function, the input should be the display name of the generator

Next, you need to set the platforms your generator supports, by adding these to the init function

self._add_platform(Platform.WIN32)
self._add_platform(Platform.WIN64)

Choose the platforms from the Platform enum we imported earlier

Now, we need to override the function to check if the project file exists or not

def does_project_exist(self, project_path: str) -> bool:
    # your code here
    return False

Next, we need to override the function to create a project, like so:

def create_project(self, project: Project) -> None:
    print("Creating: [output file]")
    # your code here

If your project type has a "master file" (ex. Visual Studio solution file), then override another function:

def create_master_file(self, info: BaseInfo, master_file_path: str) -> None:
    print("Creating Master File: [output file]")
    # your code here

By the end, the python script should look similar to this

from qpc_args import args
from qpc_base import BaseProjectGenerator, Platform, PLATFORM_DICT
from qpc_project import Compiler, PrecompiledHeader, ConfigType, Language, Project, ProjectPass
from qpc_parser import BaseInfo

class ExampleGenerator(BaseProjectGenerator):
    def __init__(self):
        super().__init__("Generator Name")
        self._add_platform(Platform.WIN32)
        self._add_platform(Platform.WIN64)

    def does_project_exist(self, project_path: str) -> bool:
        # your code here
        return False

    def create_project(self, project: Project) -> None:
        print("Creating: [output file]")
        # your code here

    def create_master_file(self, info: BaseInfo, master_file_path: str) -> None:
        print("Creating Master File: [output file]")
        # your code here
Clone this wiki locally