Skip to content

Commit

Permalink
update format for backends
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer-coding committed Jun 16, 2024
1 parent f49b86f commit 9ff0f67
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 75 deletions.
8 changes: 4 additions & 4 deletions mesonui/mesonuilib/backends/backendimpl.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

#
# author : Michael Brockus.  
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
# author : Michael Brockus.
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
#
# copyright 2020 The Meson-UI development team
#
Expand All @@ -15,7 +15,7 @@ def __init__(self, meson_api):

@property
def testinfo(self):
return self.meson_api.get_object(group='tests', extract_method='loader')
return self.meson_api.get_object(group="tests", extract_method="loader")

def generator(self):
raise NotImplementedError('IDE Backend "generate" method not iemented!')
Expand Down
108 changes: 67 additions & 41 deletions mesonui/mesonuilib/backends/codeblocks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

#
# author : Michael Brockus.  
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
# author : Michael Brockus.
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
#
# copyright 2020 The Meson-UI development team
#
Expand All @@ -27,81 +27,107 @@

class CodeBlocksBackend(BackendImplementionApi):
def __init__(self, meson_api: MesonAPI):
self.backend: str = '\'codeblocks\''
self.backend: str = "'codeblocks'"
self.projectinfo = ProjectInfo(meson_api=meson_api)
self.mesoninfo = MesonInfo(meson_api=meson_api)
self.buildsystem_files = meson_api.get_object(group='buildsystem-files', extract_method='loader')
self.targetsinfo: any = meson_api.get_object(group='targets', extract_method='loader')
self.buildsystem_files = meson_api.get_object(
group="buildsystem-files", extract_method="loader"
)
self.targetsinfo: any = meson_api.get_object(
group="targets", extract_method="loader"
)
self.ninja = Ninja(self.mesoninfo.sourcedir, self.mesoninfo.builddir)
self.compiler = self.targetsinfo[0]['target_sources'][0]['compiler'][0]
self.compiler = self.targetsinfo[0]["target_sources"][0]["compiler"][0]

def generator(self):
logging.info(f'Generating {self.backend} project')
logging.info(f"Generating {self.backend} project")
self.generate_project()

def generate_project(self):
xml: Builder = Builder(version='1.0', encoding='UTF-8')
with xml.CodeBlocks_project_file(Name=self.projectinfo.descriptive_name, Version='0.1', InternalType='Console'):
xml.FileVersion(major=f'{CBP_VERSION_MAJOR}', minor=f'{CBP_VERSION_MINOR}')
xml: Builder = Builder(version="1.0", encoding="UTF-8")
with xml.CodeBlocks_project_file(
Name=self.projectinfo.descriptive_name,
Version="0.1",
InternalType="Console",
):
xml.FileVersion(major=f"{CBP_VERSION_MAJOR}", minor=f"{CBP_VERSION_MINOR}")
with xml.Project:
xml.Option(title=self.projectinfo.descriptive_name)
xml.Option(compiler=self.compiler)
xml.Option(virtualFolders='Meson Files')
xml.Option(makefile_is_custom='1')
xml.Option(virtualFolders="Meson Files")
xml.Option(makefile_is_custom="1")

with xml.Build:
for targets in self.targetsinfo:
output = join_paths(self.mesoninfo.builddir, targets['id'])
with xml.Target(title=targets['name']):
output = join_paths(self.mesoninfo.builddir, targets["id"])
with xml.Target(title=targets["name"]):
xml.Option(output=output)
xml.Option(working_dir=os.path.split(output)[0])
xml.Option(object_output=join_paths(os.path.split(output)[0], targets['id']))
xml.Option(
object_output=join_paths(
os.path.split(output)[0], targets["id"]
)
)
ty = {
'executable': f'{BUILD_OPTION_EXECUTABLE}',
'static library': f'{BUILD_OPTION_STATIC_LIBRARY}',
'shared library': f'{BUILD_OPTION_SHARED_LIBRARY}',
'custom': f'{BUILD_OPTION_COMMANDS_ONLY}',
'run': f'{BUILD_OPTION_COMMANDS_ONLY}'
}[targets['type']]
"executable": f"{BUILD_OPTION_EXECUTABLE}",
"static library": f"{BUILD_OPTION_STATIC_LIBRARY}",
"shared library": f"{BUILD_OPTION_SHARED_LIBRARY}",
"custom": f"{BUILD_OPTION_COMMANDS_ONLY}",
"run": f"{BUILD_OPTION_COMMANDS_ONLY}",
}[targets["type"]]
xml.Option(type=ty)
compiler = targets
if compiler:
xml.Option(compiler=self.compiler)
with xml.Compiler:
for target in targets['target_sources']:
for defs in target['parameters']:
if defs.startswith('-D'):
logging.info(f'add def: {defs}')
for target in targets["target_sources"]:
for defs in target["parameters"]:
if defs.startswith("-D"):
logging.info(f"add def: {defs}")
xml.Add(option=defs)

for dirs in target['parameters']:
if dirs.startswith('-I') or dirs.startswith('/I'):
logging.info(f'add include: {dirs}')
for dirs in target["parameters"]:
if dirs.startswith("-I") or dirs.startswith("/I"):
logging.info(f"add include: {dirs}")
xml.Add(option=dirs)

with xml.MakeCommands:
xml.Build(command=f'{self.ninja.exe} -v {targets["name"]}')
xml.CompileFile(command=f'{self.ninja.exe} -v {targets["name"]}')
xml.Clean(command=f'{self.ninja.exe} -v clean')
xml.DistClean(command=f'{self.ninja.exe} -v clean')
xml.CompileFile(
command=f'{self.ninja.exe} -v {targets["name"]}'
)
xml.Clean(command=f"{self.ninja.exe} -v clean")
xml.DistClean(command=f"{self.ninja.exe} -v clean")

for targets in self.targetsinfo:
for target in targets['target_sources']:
for file in target['sources']:
with xml.Unit(filename=join_paths(self.mesoninfo.sourcedir, file)):
xml.Option(target=targets['name'])
for target in targets["target_sources"]:
for file in target["sources"]:
with xml.Unit(
filename=join_paths(self.mesoninfo.sourcedir, file)
):
xml.Option(target=targets["name"])

base = os.path.splitext(os.path.basename(file))[0]
header_exts = ('h', 'hpp')
header_exts = ("h", "hpp")
for ext in header_exts:
header_file = os.path.abspath(
join_paths(self.mesoninfo.sourcedir, os.path.dirname(file), f'{base}.{ext}'))
join_paths(
self.mesoninfo.sourcedir,
os.path.dirname(file),
f"{base}.{ext}",
)
)
if os.path.exists(header_file):
with xml.Unit(filename=header_file):
xml.Option(target=targets['name'])
xml.Option(target=targets["name"])
for file in self.buildsystem_files:
with xml.Unit(filename=join_paths(self.mesoninfo.sourcedir, file)):
xml.Option(target=join_paths('Meson Files', os.path.dirname(file)))
xml.Option(target=join_paths("Meson Files", os.path.dirname(file)))

with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.cbp'), 'w') as ide_file:
with open(
join_paths(
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.cbp"
),
"w",
) as ide_file:
ide_file.write(str(xml))
10 changes: 5 additions & 5 deletions mesonui/mesonuilib/backends/gnome.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

#
# author : Michael Brockus.  
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
# author : Michael Brockus.
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
#
# copyright 2020 The Meson-UI development team
#
Expand All @@ -15,10 +15,10 @@
class GNOMEBuilderBackend(BackendImplementionApi):
def __init__(self, meson_api: MesonAPI):
super(self.__class__, self).__init__(meson_api)
self.backend: str = '\'gnome\''
self.backend: str = "'gnome'"

def generator(self):
logging.info(f'Generating {self.backend} project')
logging.info(f"Generating {self.backend} project")
self.generate_project()

def generate_project(self):
Expand Down
76 changes: 51 additions & 25 deletions mesonui/mesonuilib/backends/qtcreator.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3

#
# author : Michael Brockus.  
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
# author : Michael Brockus.
# contact: <mailto:[email protected]>
# license: Apache 2.0 :http://www.apache.org/licenses/LICENSE-2.0
#
# copyright 2020 The Meson-UI development team
#
Expand All @@ -18,44 +18,70 @@

class QtCreatorBackend(BackendImplementionApi):
def __init__(self, meson_api: MesonAPI):
self.backend: str = '\'qtcreator\''
self.backend: str = "'qtcreator'"
self.projectinfo = ProjectInfo(meson_api=meson_api)
self.mesoninfo = MesonInfo(meson_api=meson_api)
self.buildsystem_files: list = meson_api.get_object(group='buildsystem-files', extract_method='loader')
self.targetsinfo: list = meson_api.get_object(group='targets', extract_method='loader')
self.buildsystem_files: list = meson_api.get_object(
group="buildsystem-files", extract_method="loader"
)
self.targetsinfo: list = meson_api.get_object(
group="targets", extract_method="loader"
)

def generator(self):
logging.info(f'Generating {self.backend} project')
logging.info(f"Generating {self.backend} project")
self.generate_project()

def generate_project(self):
# Generate the .creator file.
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.creator'), 'w') as file:
file.write('[General]')
with open(
join_paths(
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.creator"
),
"w",
) as file:
file.write("[General]")

# Generate the .config file.
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.config'), 'w') as file:
file.write('// Add predefined macros for your project here. For example:')
file.write('// #define THE_ANSWER 42')
with open(
join_paths(
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.config"
),
"w",
) as file:
file.write("// Add predefined macros for your project here. For example:")
file.write("// #define THE_ANSWER 42")
for targets in self.targetsinfo:
for item in targets['target_sources'][0]['parameters']:
if item.startswith('-D'):
logging.info(f'add def: {item}')
item = ' '.join(item.split('='))
file.write(f'#define {item}\n')
for item in targets["target_sources"][0]["parameters"]:
if item.startswith("-D"):
logging.info(f"add def: {item}")
item = " ".join(item.split("="))
file.write(f"#define {item}\n")

# Generate the .files file.
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.files'), 'w') as file:
with open(
join_paths(
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.files"
),
"w",
) as file:
for targets in self.targetsinfo:
for items in targets['target_sources'][0]['sources']:
file.write(os.path.relpath(item, self.mesoninfo.builddir) + '\n')
for items in targets["target_sources"][0]["sources"]:
file.write(os.path.relpath(item, self.mesoninfo.builddir) + "\n")

for item in self.buildsystem_files:
file.write(os.path.relpath(item, self.mesoninfo.builddir) + '\n')
file.write(os.path.relpath(item, self.mesoninfo.builddir) + "\n")

# Generate the .includes file.
with open(join_paths(self.mesoninfo.builddir, f'{self.projectinfo.descriptive_name}.includes'), 'w') as file:
with open(
join_paths(
self.mesoninfo.builddir, f"{self.projectinfo.descriptive_name}.includes"
),
"w",
) as file:
for targets in self.targetsinfo:
for item in targets['target_sources'][0]['parameters']:
if item.startswith('-I') or item.startswith('/I'):
file.write(os.path.relpath(item, self.mesoninfo.builddir) + '\n')
for item in targets["target_sources"][0]["parameters"]:
if item.startswith("-I") or item.startswith("/I"):
file.write(
os.path.relpath(item, self.mesoninfo.builddir) + "\n"
)

0 comments on commit 9ff0f67

Please sign in to comment.