Commit 3a23a510 authored by Emmanuele Bassi's avatar Emmanuele Bassi
Browse files

Fix the repository dependencies parsing

parent eeec912e
......@@ -7,7 +7,6 @@ import toml
from . import log
class GIDocConfig:
"""Load and represent the configuration for gidocgen"""
def __init__(self, config_file = None):
......@@ -78,7 +77,7 @@ class GIDocConfig:
res['description'] = dep.get('description', 'No description provided')
res['docs_url'] = dep.get('docs_url', '#')
retval[gir_name] = res
log.info(f"Found dependency {gir_name}: {res}")
log.debug(f"Found dependency {gir_name}: {res}")
return retval
......
......@@ -940,7 +940,7 @@ def gen_reference(config, options, repository, templates_dir, theme_config, cont
fs_loader = jinja2.FileSystemLoader(theme_dir)
jinja_env = jinja2.Environment(loader=fs_loader, autoescape=jinja2.select_autoescape(['html']))
namespace = repository.get_namespace()
namespace = repository.namespace
symbols = {
"aliases": sorted(namespace.get_aliases(), key=lambda alias: alias.name.lower()),
......@@ -983,7 +983,7 @@ def gen_reference(config, options, repository, templates_dir, theme_config, cont
}))
if options.sections == [] or options.sections == ["all"]:
gen_indices = all_indices.keys()
gen_indices = list(all_indices.keys())
else:
gen_indices = options.sections
......@@ -1070,9 +1070,10 @@ def run(options):
theme_name = conf.get_theme_name(default=options.theme_name)
theme_conf = config.GITemplateConfig(templates_dir, theme_name)
log.info(f"Search paths: {paths}")
log.info(f"Templates directory: {templates_dir}")
log.debug(f"Search paths: {paths}")
log.debug(f"Templates directory: {templates_dir}")
log.info(f"Theme name: {theme_conf.name}")
log.info(f"Output directory: {output_dir}")
log.info("Parsing GIR file")
parser = GirParser(search_paths=paths)
......
......@@ -247,7 +247,7 @@ def gen_indices(repository, options, output_dir):
If @output_dir is None, the current directory will be used.
"""
namespace = repository.get_namespace()
namespace = repository.namespace
symbols = {
"aliases": sorted(namespace.get_aliases(), key=lambda alias: alias.name.lower()),
......@@ -275,7 +275,7 @@ def gen_indices(repository, options, output_dir):
}
if options.sections == [] or options.sections == ["all"]:
gen_indices = all_indices.keys()
gen_indices = list(all_indices.keys())
else:
gen_indices = options.sections
......
......@@ -339,9 +339,9 @@ def _print_class_functions(cls, sections=[], is_last_class=False):
def gen_tree(repository):
includes = ', '.join([ str(x) for x in repository.get_includes() ])
c_includes = ', '.join(repository.get_c_includes())
packages = ', '.join(repository.get_packages())
includes = ', '.join([ str(r.namespace) for r in repository.includes ])
c_includes = ', '.join(repository.c_includes)
packages = ', '.join(repository.packages)
title = str(log.color('Repository', 12))
log.log(f'{title}')
......@@ -349,7 +349,7 @@ def gen_tree(repository):
log.log(f'├── C headers: {c_includes}')
log.log(f'├── Packages: {packages}')
namespace = repository.get_namespace()
namespace = repository.namespace
shlibs = ', '.join(namespace.get_shared_libraries())
aliases = sorted(namespace.get_aliases(), key=lambda alias: alias.name.lower())
......
......@@ -177,7 +177,7 @@ class VoidType(Type):
class VarArgs(Type):
def __init__(self):
super().__init__(name='none', ctype='args')
super().__init__(name='none', ctype='')
def __str__(self):
return "..."
......@@ -505,6 +505,16 @@ class Record(Type):
self.functions = []
self.fields = []
@property
def type_struct(self) -> str:
return self.ctype
@property
def type_func(self) -> T.Optional[str]:
if self.gtype is not None:
return self.gtype.type_func
return None
def set_constructors(self, ctors: T.List[Function]) -> None:
self.constructors.extend(ctors)
......@@ -669,28 +679,11 @@ class Repository:
self.includes = []
self.packages = []
self.c_includes = []
self.namespaces = []
def add_include(self, name: str, version: str) -> None:
self.includes.append(Include(name, version))
def add_package(self, name: str) -> None:
self.package.append(Package(name))
def set_c_include(self, name: str) -> None:
self.c_includes.append(CInclude(name))
self._namespaces = []
def add_namespace(self, ns: Namespace) -> None:
self.namespaces.append(ns)
def get_includes(self) -> T.List[Include]:
return self.includes
self._namespaces.append(ns)
def get_c_includes(self) -> T.List[CInclude]:
return self.c_includes
def get_packages(self) -> T.List[Package]:
return self.packages
def get_namespace(self) -> Namespace:
return self.namespaces[0]
@property
def namespace(self) -> Namespace:
return self._namespaces[0]
......@@ -29,7 +29,8 @@ def _cns(tag):
class GirParser:
def __init__(self, search_paths=[]):
self._search_paths = search_paths
self._repositories = {}
self._repository = None
self._dependencies = {}
def append_search_path(self, path: str) -> None:
"""Append a path to the list of search paths"""
......@@ -39,19 +40,41 @@ class GirParser:
"""Prepend a path to the list of search paths"""
self._search_paths = [path] + self._search_paths
def parse(self, girfile: str) -> None:
def parse(self, girfile) -> None:
"""Parse @girfile"""
log.debug(f"Loading GIR for dependency {girfile}")
log.debug(f"Loading GIR for {girfile}")
tree = ET.parse(girfile)
self._parse_tree(tree.getroot())
repository = self._parse_tree(tree.getroot())
if repository is None:
log.error(f"Could not parse GIR {girfile}")
else:
self._repository = repository
def get_repository(self, name: str = None) -> T.Optional[ast.Repository]:
def get_repository(self, name: T.Optional[str] = None) -> T.Optional[ast.Repository]:
if name is None:
return list(self._repositories.keys())[0]
return self._repository
else:
return self._repositories.get(name)
return self._dependencies[name]
def _parse_tree(self, root):
def _parse_dependency(self, include) -> None:
if self._dependencies.get(str(include), None) is not None:
log.debug(f"Dependency {include} already parsed")
return
repository = None
for base_path in self._search_paths:
girfile = os.path.join(base_path, f"{include}.gir")
if os.path.exists(girfile) and os.path.isfile(girfile):
log.debug(f"Loading GIR for dependency {include} at {girfile}")
tree = ET.parse(girfile)
repository = self._parse_tree(tree.getroot())
break
if repository is None:
log.error(f"Could not find GIR dependency in the search paths: {include}")
else:
ns = repository.namespace
self._dependencies[str(ns)] = repository
def _parse_tree(self, root) -> ast.Repository:
assert root.tag == _corens('repository')
includes = []
......@@ -69,22 +92,6 @@ class GirParser:
package = self._parse_package(node)
packages.append(package)
for include in includes:
include_basename = f"{include.name}-{include.version}"
if self._repositories.get(include_basename, None) is not None:
continue
found = False
for base_path in self._search_paths:
include_file = os.path.join(base_path, f"{include_basename}.gir")
if os.path.exists(include_file) and os.path.isfile(include_file):
found = True
self.parse(include_file)
break
if not found:
log.error(f"Could not find GIR dependency: {include_basename}")
ns = root.find(_corens('namespace'))
assert ns is not None
......@@ -105,8 +112,10 @@ class GirParser:
repository.packages = packages
for include in includes:
include_basename = f"{include.name}-{include.version}"
repository.includes.append(self._repositories[include_basename])
log.debug(f"Parsing dependency {include}")
self._parse_dependency(include)
repository.includes.extend(self._dependencies.values())
repository.add_namespace(namespace)
......@@ -129,8 +138,7 @@ class GirParser:
if parse_method:
parse_method(node, namespace)
log.info(f"Added repository for {namespace.name}-{namespace.version}")
self._repositories[f"{namespace.name}-{namespace.version}"] = repository
return repository
def _parse_include(self, node: ET.Element) -> ast.Include:
return ast.Include(node.attrib['name'], node.attrib['version'])
......
......@@ -179,7 +179,7 @@
{% endif %}
{% if class.class_name %}
<div class="class toggle-wrapper">
<div class="class toggle-wrapper default-hide">
<h4 id="class">Class structure</a></h4>
<pre><code>struct {{ namespace.name}}.{{ class.class_name }} {
......
......@@ -87,7 +87,7 @@
<div class="docblock">
{% for method in interface.methods %}
<div class="toggle-wrapper">
<div class="toggle-wrapper default-hide">
<h6><a href="method.{{ interface.name}}.{{ method.name }}.html">{{ method.identifier }}</a> ();</h6>
<div class="docblock">
......@@ -106,7 +106,7 @@
<div class="docblock">
{% for property in interface.properties %}
<div class="toggle-wrapper">
<div class="toggle-wrapper default-hide">
<h6><a href="property.{{ interface.name }}.{{ property.name }}.html">{{ namespace.name }}.{{ interface.name }}:{{ property.name }}</a></h6>
<div class="docblock">
......@@ -125,7 +125,7 @@
<div class="docblock">
{% for signal in interface.signals %}
<div class="toggle-wrapper">
<div class="toggle-wrapper default-hide">
<h6><a href="signal.{{ interface.name }}.{{ signal.name }}.html">{{ namespace.name }}.{{ interface.name }}::{{ signal.name }}</a></h6>
<div class="docblock">
......@@ -148,7 +148,7 @@
}</code></pre>
{% if interface.class_fields %}
<div class="docblock">
<div class="docblock default-hide">
<h6>Interface members</h6>
<table>
......@@ -169,7 +169,7 @@
<div class="docblock">
{% for method in interface.class_methods %}
<div class="toggle-wrapper">
<div class="toggle-wrapper default-hide">
<h6><a href="class_method.{{ interface.class_name }}.{{ method.name }}.html">{{ method.identifier }}</a> ();</h6>
<div class="docblock">
......@@ -187,7 +187,7 @@
<div class="docblock">
{% for func in interface.type_funcs %}
<div class="toggle-wrapper">
<div class="toggle-wrapper default-hide">
<h6><a href="type_func.{{ interface.name }}.{{ func.name }}.html">{{ func.identifier }}</a> ();</h6>
<div class="docblock">
......
Markdown is supported
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