Skip to content

Exporters: make jinja engine strict #3608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 26, 2017
Merged

Exporters: make jinja engine strict #3608

merged 4 commits into from
Jan 26, 2017

Conversation

ilg-ul
Copy link
Contributor

@ilg-ul ilg-ul commented Jan 18, 2017

  • configure the jinja Environment to raise exception when substitution
    variables are not defined
  • trim spaces and lines, to avoid empty lines in generated files

- configure the jinja Environment to raise exception when substitution
variables are not defined
- trim spaces and lines, to avoid empty lines in generated files
@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 18, 2017

I may tack on a few commits after your changes in that PR to ensure that all of the exporters will work afterwards.

in case they don't, you can make this an optional feature, and activate it only in the exporters that work.

similarly for the white space options, perhaps it would be better to set them in each exporter and pass them to the base class.

@theotherjimmy
Copy link
Contributor

Yeah, let me pull this down and test the exporters real quick.

@theotherjimmy
Copy link
Contributor

Also, The diff is great. Nice and simple.

@theotherjimmy
Copy link
Contributor

That IAR one is definitely a bug.

@theotherjimmy
Copy link
Contributor

CMSIS one also clearly a bug.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

it looks like you asked for some trouble with this patch... :-(

in my opinion this setting should have been a jinja default, I fail to identify cases when ignoring missing definitions is acceptable.

@theotherjimmy
Copy link
Contributor

it looks like you asked for some trouble with this patch... :-(

Yes I did. However, I think it's the good kind of trouble: it pointed out some bugs.

@theotherjimmy
Copy link
Contributor

And that's all of them! They all should export again without issue.

/morph export-build

@theotherjimmy
Copy link
Contributor

@ilg-ul We're almost ready to get this in. Just waiting on CI.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 19, 2017

+1, thanks for enabling StrictUndefined

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph export-build

Output

mbed Build Number: 91

Exporter Build failed!

@theotherjimmy
Copy link
Contributor

It looks like removing all blank lines is really bad for Makefiles.

@theotherjimmy
Copy link
Contributor

@ilg-ul Would you mind if I made the boolean for removing empty lines and spaces optional and changed the makefiles to disable them?

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

I would do the opposite, I would call gen_file() with additional optional arguments, and pass all to jinja.

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Jan 19, 2017

I'm confused, I thought that's what I was suggesting. I worded the original suggestion poorly. I am was thinking of making gen_file take optional arguments when I asked.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

sorry, I was cryptic.

I mean calling gen_file() like:

self.gen_file('gnuarmeclipse/.project.tmpl', ctx, '.project', trim_blocks=True, lstrip_blocks=True)

the gen_file() definition should use variable args, and pass everything to jinja, not only those two, in case more flags will be necessary.

@theotherjimmy
Copy link
Contributor

theotherjimmy commented Jan 19, 2017

Yes, with True being the default for both, and the Makefile exporter explicitly calling with False.

So:

def gen(teplate_file, context, output, **kwargs):
    ...
    template.render(... **kwargs)

or thereabouts.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

hmmm... it looks I have difficulties to explain.

only exporters that need additional jinga options pass them, all existing ones need pass nothing, as they do now, so jinja defaults will apply.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

as implementation, add **kwargs to gen_file().

@theotherjimmy
Copy link
Contributor

Also, Github is not the best way to do IRC... I edited by comment, probably while you were typing up a response to the old version 😆

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

ok, go ahead with the changes.

@theotherjimmy
Copy link
Contributor

/morph export-build

@theotherjimmy
Copy link
Contributor

@ilg-ul I made the changes, could you review them? I want to make sure that we understood each other correctly.

Copy link
Contributor Author

@ilg-ul ilg-ul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks ok, please don't forget to add the options to the GNU ARM Eclipse exporter later

@theotherjimmy
Copy link
Contributor

Yup! I have made a note.

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph export-build

Output

mbed Build Number: 92

All exports and builds passed!

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

Great!

What next now? Do we patiently wait for the planets to align in order for the PR to be merged? Or we better hum some incantations to hurry things up? ;-)

@theotherjimmy
Copy link
Contributor

The incantation is: @sg- could you take a look?

Copy link
Contributor

@sg- sg- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from 38k ft.

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

Thank you, @sg-!

FL 380 is pretty high. On the way to ISS? ;-)

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 19, 2017

The next incantation should address the magic Merge button...

@theotherjimmy
Copy link
Contributor

actually, I was hoping that @sg- would push the Merge button, but we could get @0xc0170 to do it instead.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 20, 2017

actually, I was hoping that @sg- would push the Merge button, but we could get @0xc0170 to do it instead.

Will be reviewed on Monday (=integrated)

@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 24, 2017

any progress?

@0xc0170 0xc0170 merged commit 57ec749 into ARMmbed:master Jan 26, 2017
@ilg-ul ilg-ul deleted the jinja branch January 26, 2017 08:34
@ilg-ul
Copy link
Contributor Author

ilg-ul commented Jan 26, 2017

thank you, Martin!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants