Skip to content

Can't import from sibling modules #73

@ptwales

Description

@ptwales

Currently there is no clean way for a template to import types from another template that isn't a child

proj/
├── mod1
│   └── Foo.tmpl
└── mod2
    └── Bar.tmpl

Bar.tmpl should be able to reference types from Foo.tmpl with import mod1.Foo. However,

codegen -m scala -o output proj/mod1/Foo.tmpl proj/mod2/Bar.tmpl

would fail with mod1.Foo not found since there is no mod1 folder in mod2 which is where codegen would look. We could resolve this two ways. One would be to compile Bar.tmpl separately from Foo.tmpl and include the mod1 folder.

codegen -m scala -o output -I proj/mod1 proj/mod2/Bar.tmpl

But that would only work if Bar.tmpl had import Foo not import mod1.Foo. And that what would we do if mod2.Foo existed?

The best solution is also a silly one:

codegen -m scala -o output -I proj/ proj/mod1/Foo.tmpl proj/mod2/Bar.tmpl

Including the source files which we are compiling as though they were external sources is silly. We should just have a flag to say "compile all templates in this folder and include them all in each others scope."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions