Skip to content
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

Implement autoconf.h generation #35

Merged
merged 1 commit into from
Jan 5, 2018
Merged

Conversation

carlescufi
Copy link
Contributor

Implement the generation of the C header file that mirrors the .config
files, commonly named autoconf.h.

Signed-off-by: Carles Cufi [email protected]

kconfiglib.py Outdated
item = node.item
if isinstance(item, Symbol):
if not item._written:
if item._write_to_conf:
Copy link
Owner

Choose a reason for hiding this comment

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

There's a subtlety here that causes this to break unless all the symbol values have already been calculated: _write_to_conf is calculated when the symbol value is calculated.

If you do val = item.str_value before checking _write_to_conf and use that, it will work fine. .str_value is actually a hidden function call (that uses Python @property magic).

There's a related note in a comment in config_string, but it might be hard to spot unless you already know that that's a hidden function call too. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did read that, but I wrongly assumed that one always calls write_config before write_autoconf

kconfiglib.py Outdated
elif item.orig_type == STRING:
write('#define {}{} "{}"\n'
.format(self.config_prefix, item.name,
item.str_value))
Copy link
Owner

@ulfalizer ulfalizer Jan 4, 2018

Choose a reason for hiding this comment

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

Could make this escape(item.str_value). Then string values containing " and \ will be properly escaped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed thanks!

kconfiglib.py Outdated
elif item.orig_type in (INT, HEX):
write("#define {}{} {}\n"
.format(self.config_prefix, item.name,
item.str_value))
Copy link
Owner

@ulfalizer ulfalizer Jan 4, 2018

Choose a reason for hiding this comment

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

Could do this, just to match the C implementation:

if item.orig_type == HEX and not val.startswith(("0x", "0X")):
    val = "0x" + val

Looks fine other than that!

I'm used to Gerrit. Think you might have to force push the branch or something to address review comments. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I do it all the time with GitHub :)
Addressed but I couldn't keep it within the 80-char width limit, Python was throwing me errors.

Copy link
Owner

Choose a reason for hiding this comment

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

No worries.

If you want to split something that's not enclosed in brackets over multiple lines in Python, you need to add a \ at the end of the line.

Implement the generation of the C header file that mirrors the .config
files, commonly named autoconf.h.

Signed-off-by: Carles Cufi <[email protected]>
@ulfalizer ulfalizer merged commit 5e2103c into ulfalizer:master Jan 5, 2018
@carlescufi
Copy link
Contributor Author

Thanks!

@ulfalizer
Copy link
Owner

Going to bed soon (my sleep schedule's a bit wonky atm :)), but I'll push out a new release to PyPI later on today as well.

@carlescufi
Copy link
Contributor Author

Thank you, although there is no rush yet with PyPI since we will need to keep 2 patches (globbing and prefer later defaults) out of tree until I have fixed our Kconfig files.

@carlescufi carlescufi deleted the autoconf branch January 5, 2018 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants