|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 |
|
3 | 3 | #
|
4 |
| -# author : Michael Brockus. |
5 |
| -# contact: <mailto:[email protected]> |
6 |
| -# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0 |
| 4 | +# author : Michael Brockus. |
| 5 | +# contact: <mailto:[email protected]> |
| 6 | +# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0 |
7 | 7 | #
|
8 | 8 | # copyright 2020 The Meson-UI development team
|
9 | 9 | #
|
|
27 | 27 |
|
28 | 28 | class CodeBlocksBackend(BackendImplementionApi):
|
29 | 29 | def __init__(self, meson_api: MesonAPI):
|
30 |
| - self.backend: str = '\'codeblocks\'' |
| 30 | + self.backend: str = "'codeblocks'" |
31 | 31 | self.projectinfo = ProjectInfo(meson_api=meson_api)
|
32 | 32 | self.mesoninfo = MesonInfo(meson_api=meson_api)
|
33 |
| - self.buildsystem_files = meson_api.get_object(group='buildsystem-files', extract_method='loader') |
34 |
| - self.targetsinfo: any = meson_api.get_object(group='targets', extract_method='loader') |
| 33 | + self.buildsystem_files = meson_api.get_object( |
| 34 | + group="buildsystem-files", extract_method="loader" |
| 35 | + ) |
| 36 | + self.targetsinfo: any = meson_api.get_object( |
| 37 | + group="targets", extract_method="loader" |
| 38 | + ) |
35 | 39 | self.ninja = Ninja(self.mesoninfo.sourcedir, self.mesoninfo.builddir)
|
36 |
| - self.compiler = self.targetsinfo[0]['target_sources'][0]['compiler'][0] |
| 40 | + self.compiler = self.targetsinfo[0]["target_sources"][0]["compiler"][0] |
37 | 41 |
|
38 | 42 | def generator(self):
|
39 |
| - logging.info(f'Generating {self.backend} project') |
| 43 | + logging.info(f"Generating {self.backend} project") |
40 | 44 | self.generate_project()
|
41 | 45 |
|
42 | 46 | def generate_project(self):
|
43 |
| - xml: Builder = Builder(version='1.0', encoding='UTF-8') |
44 |
| - with xml.CodeBlocks_project_file(Name=self.projectinfo.descriptive_name, Version='0.1', InternalType='Console'): |
45 |
| - xml.FileVersion(major=f'{CBP_VERSION_MAJOR}', minor=f'{CBP_VERSION_MINOR}') |
| 47 | + xml: Builder = Builder(version="1.0", encoding="UTF-8") |
| 48 | + with xml.CodeBlocks_project_file( |
| 49 | + Name=self.projectinfo.descriptive_name, |
| 50 | + Version="0.1", |
| 51 | + InternalType="Console", |
| 52 | + ): |
| 53 | + xml.FileVersion(major=f"{CBP_VERSION_MAJOR}", minor=f"{CBP_VERSION_MINOR}") |
46 | 54 | with xml.Project:
|
47 | 55 | xml.Option(title=self.projectinfo.descriptive_name)
|
48 | 56 | xml.Option(compiler=self.compiler)
|
49 |
| - xml.Option(virtualFolders='Meson Files') |
50 |
| - xml.Option(makefile_is_custom='1') |
| 57 | + xml.Option(virtualFolders="Meson Files") |
| 58 | + xml.Option(makefile_is_custom="1") |
51 | 59 |
|
52 | 60 | with xml.Build:
|
53 | 61 | for targets in self.targetsinfo:
|
54 |
| - output = join_paths(self.mesoninfo.builddir, targets['id']) |
55 |
| - with xml.Target(title=targets['name']): |
| 62 | + output = join_paths(self.mesoninfo.builddir, targets["id"]) |
| 63 | + with xml.Target(title=targets["name"]): |
56 | 64 | xml.Option(output=output)
|
57 | 65 | xml.Option(working_dir=os.path.split(output)[0])
|
58 |
| - xml.Option(object_output=join_paths(os.path.split(output)[0], targets['id'])) |
| 66 | + xml.Option( |
| 67 | + object_output=join_paths( |
| 68 | + os.path.split(output)[0], targets["id"] |
| 69 | + ) |
| 70 | + ) |
59 | 71 | ty = {
|
60 |
| - 'executable': f'{BUILD_OPTION_EXECUTABLE}', |
61 |
| - 'static library': f'{BUILD_OPTION_STATIC_LIBRARY}', |
62 |
| - 'shared library': f'{BUILD_OPTION_SHARED_LIBRARY}', |
63 |
| - 'custom': f'{BUILD_OPTION_COMMANDS_ONLY}', |
64 |
| - 'run': f'{BUILD_OPTION_COMMANDS_ONLY}' |
65 |
| - }[targets['type']] |
| 72 | + "executable": f"{BUILD_OPTION_EXECUTABLE}", |
| 73 | + "static library": f"{BUILD_OPTION_STATIC_LIBRARY}", |
| 74 | + "shared library": f"{BUILD_OPTION_SHARED_LIBRARY}", |
| 75 | + "custom": f"{BUILD_OPTION_COMMANDS_ONLY}", |
| 76 | + "run": f"{BUILD_OPTION_COMMANDS_ONLY}", |
| 77 | + }[targets["type"]] |
66 | 78 | xml.Option(type=ty)
|
67 | 79 | compiler = targets
|
68 | 80 | if compiler:
|
69 | 81 | xml.Option(compiler=self.compiler)
|
70 | 82 | with xml.Compiler:
|
71 |
| - for target in targets['target_sources']: |
72 |
| - for defs in target['parameters']: |
73 |
| - if defs.startswith('-D'): |
74 |
| - logging.info(f'add def: {defs}') |
| 83 | + for target in targets["target_sources"]: |
| 84 | + for defs in target["parameters"]: |
| 85 | + if defs.startswith("-D"): |
| 86 | + logging.info(f"add def: {defs}") |
75 | 87 | xml.Add(option=defs)
|
76 | 88 |
|
77 |
| - for dirs in target['parameters']: |
78 |
| - if dirs.startswith('-I') or dirs.startswith('/I'): |
79 |
| - logging.info(f'add include: {dirs}') |
| 89 | + for dirs in target["parameters"]: |
| 90 | + if dirs.startswith("-I") or dirs.startswith("/I"): |
| 91 | + logging.info(f"add include: {dirs}") |
80 | 92 | xml.Add(option=dirs)
|
81 | 93 |
|
82 | 94 | with xml.MakeCommands:
|
83 | 95 | xml.Build(command=f'{self.ninja.exe} -v {targets["name"]}')
|
84 |
| - xml.CompileFile(command=f'{self.ninja.exe} -v {targets["name"]}') |
85 |
| - xml.Clean(command=f'{self.ninja.exe} -v clean') |
86 |
| - xml.DistClean(command=f'{self.ninja.exe} -v clean') |
| 96 | + xml.CompileFile( |
| 97 | + command=f'{self.ninja.exe} -v {targets["name"]}' |
| 98 | + ) |
| 99 | + xml.Clean(command=f"{self.ninja.exe} -v clean") |
| 100 | + xml.DistClean(command=f"{self.ninja.exe} -v clean") |
87 | 101 |
|
88 | 102 | for targets in self.targetsinfo:
|
89 |
| - for target in targets['target_sources']: |
90 |
| - for file in target['sources']: |
91 |
| - with xml.Unit(filename=join_paths(self.mesoninfo.sourcedir, file)): |
92 |
| - xml.Option(target=targets['name']) |
| 103 | + for target in targets["target_sources"]: |
| 104 | + for file in target["sources"]: |
| 105 | + with xml.Unit( |
| 106 | + filename=join_paths(self.mesoninfo.sourcedir, file) |
| 107 | + ): |
| 108 | + xml.Option(target=targets["name"]) |
93 | 109 |
|
94 | 110 | base = os.path.splitext(os.path.basename(file))[0]
|
95 |
| - header_exts = ('h', 'hpp') |
| 111 | + header_exts = ("h", "hpp") |
96 | 112 | for ext in header_exts:
|
97 | 113 | header_file = os.path.abspath(
|
98 |
| - join_paths(self.mesoninfo.sourcedir, os.path.dirname(file), f'{base}.{ext}')) |
| 114 | + join_paths( |
| 115 | + self.mesoninfo.sourcedir, |
| 116 | + os.path.dirname(file), |
| 117 | + f"{base}.{ext}", |
| 118 | + ) |
| 119 | + ) |
99 | 120 | if os.path.exists(header_file):
|
100 | 121 | with xml.Unit(filename=header_file):
|
101 |
| - xml.Option(target=targets['name']) |
| 122 | + xml.Option(target=targets["name"]) |
102 | 123 | for file in self.buildsystem_files:
|
103 | 124 | with xml.Unit(filename=join_paths(self.mesoninfo.sourcedir, file)):
|
104 |
| - xml.Option(target=join_paths('Meson Files', os.path.dirname(file))) |
| 125 | + xml.Option(target=join_paths("Meson Files", os.path.dirname(file))) |
105 | 126 |
|
106 |
| - with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.cbp'), 'w') as ide_file: |
| 127 | + with open( |
| 128 | + join_paths( |
| 129 | + self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.cbp" |
| 130 | + ), |
| 131 | + "w", |
| 132 | + ) as ide_file: |
107 | 133 | ide_file.write(str(xml))
|
0 commit comments