Skip to content

Commit

Permalink
Merge pull request #325 from OZI-Project/patch/rewriter-fixes
Browse files Browse the repository at this point in the history
Patch/rewriter-fixes
  • Loading branch information
rjdbcm authored Nov 10, 2024
2 parents 2950a61 + c493822 commit 58da56c
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 105 deletions.
12 changes: 10 additions & 2 deletions ozi_core/data/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
source_child_data_files = [
source_data_files = [
'en.yml',
'zh.yml',
]
foreach file : files(source_child_data_files)
foreach file : files(source_data_files)
fs.copyfile(file)
if not meson.is_subproject() or get_option('install-subprojects').enabled()
python.install_sources(file, pure: true, subdir: 'ozi_core' / 'data')
endif
endforeach
source_data_children = []
foreach child: source_data_children
subdir(child)
endforeach
if false
executable('source_data_files', source_data_files)
executable('source_data_children', source_data_children)
endif
32 changes: 23 additions & 9 deletions ozi_core/fix/build_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""Build definition check utilities."""
from __future__ import annotations

import difflib
import os
from pathlib import Path
from typing import Generator
Expand Down Expand Up @@ -62,24 +63,37 @@
bound = Word(alphas, alphanums + '_')
assigned = Word(alphas, alphanums + '_')
array_assign = (
assigned + Literal('=') + Literal('[') + Optional(comma_separated_list, default='')
| quoted_string + Literal(']') + rest_of_line
assigned
+ Literal('=')
+ Literal('[')
+ Optional(comma_separated_list, default='')
+ Literal(']')
+ rest_of_line
).set_parse_action(
lambda t: [
' '.join(t[:3]) + t[-2] + t[-1], # type: ignore
*[f'subdir({i})' for i in t[3:-2] if len(i)],
*[f'subdir({i})' for i in t[3:-2] if len(i) and i.strip('\'"') != 'ozi.phony'],
' '.join(t[:3]) + "'ozi.phony'" + t[-2] + t[-1], # type: ignore
]
)
foreach_bind = (
Keyword('foreach') + bound + ':' + match_previous_literal(assigned) + rest_of_line
).set_parse_action(lambda t: ' '.join(t).strip())
bindvar = match_previous_literal(bound)
foreach_end = (Keyword('endforeach') + rest_of_line).set_parse_action(
lambda t: ' '.join(t).strip()
)
subdir_call = (
'subdir(' + match_previous_literal(bound) + ')' + rest_of_line
).set_parse_action(lambda t: ' ' + ''.join(t))
literal_subdir_loop = array_assign + foreach_bind + subdir_call + foreach_end
if_ozi_phony = (
Keyword('if') + bindvar + Literal('!=') + Literal("'ozi.phony'") + rest_of_line
).set_parse_action(lambda t: ' ' + ' '.join(t).strip())
endif = (Keyword('endif') + rest_of_line).set_parse_action(
lambda t: ' ' + ' '.join(t).strip()
)
subdir_call = ('subdir(' + bindvar + ')' + rest_of_line).set_parse_action(
lambda t: ' ' + ''.join(t)
)
literal_subdir_loop = (
array_assign + foreach_bind + if_ozi_phony + subdir_call + endif + foreach_end
)
unrollable_subdirs = (
ZeroOrMore(SkipTo(literal_subdir_loop, include=True))
+ SkipTo(StringEnd(), include=True).leave_whitespace()
Expand All @@ -92,7 +106,7 @@ def unroll_subdirs(target: Path, rel_path: Path) -> str: # pragma: defer to E2E
"""
with open(target / rel_path / 'meson.build', 'r') as f:
text = unrollable_subdirs.parse_file(f)
return '\n'.join(text)
return '\n'.join([i.strip('\n') for i in text])


def inspect_files(
Expand Down
11 changes: 8 additions & 3 deletions ozi_core/fix/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
config_files = [
source_fix_files = [
'__init__.py',
'__init__.pyi',
'build_definition.py',
Expand All @@ -15,12 +15,17 @@ config_files = [
'rewrite_command.py',
'rewrite_command.pyi',
]
foreach file: config_files
foreach file: source_fix_files
if not meson.is_subproject() or get_option('install-subprojects').enabled()
python.install_sources(file, subdir: 'ozi_core'/'fix')
endif
fs.copyfile(file)
endforeach
source_fix_children = []
foreach child: source_fix_children
subdir(child)
endforeach
if false
executable('source_child_fix', config_files)
executable('source_fix_files', source_fix_files)
executable('source_fix_children', source_fix_children)
endif
8 changes: 4 additions & 4 deletions ozi_core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ foreach file : files(source_files)
endif
endforeach

source_children = []
subdir('data')
subdir('vendor')
subdir('fix')
subdir('new')
subdir('ui')
source_children = ['data', 'ozi.phony', 'vendor']
foreach child : source_children
subdir(child)
if child != 'ozi.phony'
subdir(child)
endif
endforeach

if false
Expand Down
11 changes: 8 additions & 3 deletions ozi_core/new/interactive/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
config_files = [
source_new_interactive_files = [
'__init__.py',
'__init__.pyi',
'menu.py',
Expand All @@ -12,12 +12,17 @@ config_files = [
'validator.py',
'validator.pyi',
]
foreach file: config_files
foreach file: source_new_interactive_files
if not meson.is_subproject() or get_option('install-subprojects').enabled()
python.install_sources(file, subdir: 'ozi_core'/'new'/'interactive')
endif
fs.copyfile(file)
endforeach
source_new_interactive_children = []
foreach child: source_new_interactive_children
subdir(child)
endforeach
if false
executable('source_child_new', config_files)
executable('source_new_interactive_files', source_new_interactive_files)
executable('source_new_interactive_children', source_new_interactive_children)
endif
14 changes: 9 additions & 5 deletions ozi_core/new/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
config_files = [
source_new_files = [
'__init__.py',
'__init__.pyi',
'defaults.py',
Expand All @@ -12,15 +12,19 @@ config_files = [
'validate.py',
'validate.pyi',
]
foreach file: config_files
foreach file: source_new_files
if not meson.is_subproject() or get_option('install-subprojects').enabled()
python.install_sources(file, subdir: 'ozi_core'/'new')
endif
fs.copyfile(file)
endforeach
source_child_new_children = [
source_new_children = [
'interactive'
]
foreach child: source_child_new_children
foreach child: source_new_children
subdir(child)
endforeach
endforeach
if false
executable('source_new_files', source_new_files)
executable('source_new_children', source_new_children)
endif
2 changes: 1 addition & 1 deletion ozi_core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def build_child(env: Environment, parent: str, child: Path) -> None:
:param child: path to a new child directory
:type child: Path
"""
child.mkdir(parents=True)
child.mkdir(parents=True, exist_ok=True)
parent = parent.rstrip('/')
heirs = parent.split('/')
if len(heirs) > 1:
Expand Down
11 changes: 8 additions & 3 deletions ozi_core/ui/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
config_files = [
source_ui_files = [
'__init__.py',
'menu.py',
'menu.pyi',
Expand All @@ -11,12 +11,17 @@ config_files = [
'_style.py',
'_style.pyi',
]
foreach file: config_files
foreach file: source_ui_files
if not meson.is_subproject() or get_option('install-subprojects').enabled()
python.install_sources(file, subdir: 'ozi_core'/'ui')
endif
fs.copyfile(file)
endforeach
source_ui_children = []
foreach child: source_ui_children
subdir(child)
endforeach
if false
executable('source_child_new', config_files)
executable('source_ui_files', source_ui_files)
executable('source_ui_children', source_ui_children)
endif
15 changes: 8 additions & 7 deletions ozi_core/vendor/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
# Part of the OZI Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
python_files = [
source_vendor_files = [
'__init__.py',
]
foreach file : files(python_files)
foreach file : files(source_vendor_files)
fs.copyfile(file)
if not meson.is_subproject() or get_option('install-subprojects').enabled()
python.install_sources(file, pure: true, subdir: 'ozi_core' / 'vendor')
endif
endforeach
source_vendor_children = ['email_validator']
foreach child: source_vendor_children
subdir(child)
endforeach
if false
executable('source_child_vendor_files', python_files)
executable('source_vendor_files', source_vendor_files)
executable('source_vendor_children', source_vendor_children)
endif
source_child_vendor_children = ['email_validator']
foreach child: source_child_vendor_children
subdir(child)
endforeach
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
'idna>=2',
'meson[ninja]>=1.1.0',
'ozi-spec~=0.11.5',
'ozi-templates~=2.13.12',
'ozi-templates~=2.13.13',
'packaging~=24.1',
'prompt-toolkit',
'pyparsing~=3.1',
Expand Down
Loading

0 comments on commit 58da56c

Please sign in to comment.