Skip to content

Commit

Permalink
Allow writing include files to a different dir
Browse files Browse the repository at this point in the history
  • Loading branch information
giannitedesco committed Jul 17, 2023
1 parent 59b4896 commit eb3b6f7
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions xpdt/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class BackendDef:
suffix: ClassVar[str]
incl: ClassVar[bool] = False

__slots__ = (
'_p',
Expand All @@ -29,12 +30,18 @@ class BackendDef:
def _name(self, base: Path, name: str) -> Path:
return base / (name + self.suffix)

def __init__(self, ns: NameSpace, base: Path,
def __init__(self,
ns: NameSpace,
base: Path,
inc_base: Optional[Path],
inc_prefix: Optional[str] = None) -> None:
self._ns = ns
name = ns.name
assert name is not None
self._p = self._name(base, name)
if self.incl and inc_base is not None:
self._p = self._name(inc_base, name)
else:
self._p = self._name(base, name)
self._inc_prefix = inc_prefix

def _gen(self, f: TextIO) -> None:
Expand All @@ -48,6 +55,7 @@ def gen(self) -> None:

class OutputC(BackendDef):
suffix = '_impl.h'
incl = True
__slots__ = ()

def _gen(self, f: TextIO) -> None:
Expand All @@ -64,6 +72,7 @@ def _gen(self, f: TextIO) -> None:

class OutputCHdr(BackendDef):
suffix = '_api.h'
incl = True
__slots__ = ()

def _gen(self, f: TextIO) -> None:
Expand Down Expand Up @@ -110,6 +119,9 @@ def main() -> None:
default=Path(),
type=Path,
help='Output dir')
opts.add_argument('--inc-dir', '-i',
type=Path,
help='Output dir to write includes')
opts.add_argument('-I',
dest='inc_prefix',
help='Include path (for C headers)')
Expand Down Expand Up @@ -141,7 +153,7 @@ def main() -> None:

args.out.mkdir(exist_ok=True)
for cls in file_generators:
backend = cls(ns, args.out, args.inc_prefix)
backend = cls(ns, args.out, args.inc_dir, args.inc_prefix)
backend.gen()


Expand Down

0 comments on commit eb3b6f7

Please sign in to comment.