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

gnome: add mkenums_simple() #1800

Merged
merged 1 commit into from Aug 14, 2017
Merged

Conversation

tp-m
Copy link
Member

@tp-m tp-m commented May 14, 2017

99% of all mkenums uses in C libraries use the same basic template,
so add a mkenums_simple() function that takes care of everything for
us based on that template.

Features:

  • optional function declaration decorator such as GLIB_AVAILABLE
  • optional extra header prefix (e.g. for include needed for decorator)
  • optional function prefix (e.g. to add leading underscores)

Fixes issue #1384

static const G@Type@Value values[] = {''' % func_prefix

c_file_kwargs['vprod'] = \
' { C_@TYPE@(@VALUENAME@), "@VALUENAME@", "@valuenick@" },'
Copy link
Member

Choose a reason for hiding this comment

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

[flake8]

  • [E128] continuation line under-indented for visual indent

@TingPing
Copy link
Member

So what is the reason this has to be a new API?

@TingPing TingPing added the gnome label May 14, 2017
@tp-m
Copy link
Member Author

tp-m commented May 14, 2017

Well, it doesn't have to be new API, but squeezing it into the existing mkenums seemed to just make everything more horrible and confusing from a user point of view. It's already not very nice API because it's so overloaded IMHO.

How would you add this functionality to the existing mkenums? Maybe you can think of a nicer way :)

@tp-m
Copy link
Member Author

tp-m commented May 14, 2017

Actually, I would probably argue that they are different things. mkenums maps pretty much 1:1 to glib-mkenums, so is really just a way to call it from meson with the arguments it provides. The proposed mkenums_simple on the other hand is meant as a higher-level abstraction.

@TingPing
Copy link
Member

Well just glancing at the docs you wrote like 80% of them overlap. I just think it reflects upon Meson poorly that our API is so bad we already have a duplicate entry with _simple() shoved on the end.

@tp-m
Copy link
Member Author

tp-m commented May 14, 2017

Well, we can't undo the past, can we? I think we should always be guided by providing the best usability for our users going forward, irrespective of how this may or may not reflect on meson :)

@nirbheek
Copy link
Member

I don't think our API is bad, it's just that mkenums API is extremely flexible and we chose to expose that first. Later, based on the most-common usage, we've distilled 90% of the use-cases into one mkenums_simple call that everyone should be able to use without specifying templates or fhead, etc.

Copy link
Member

@nirbheek nirbheek left a comment

Choose a reason for hiding this comment

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

I've gone over the code, but I can't do a proper technical review of this since @TingPing is the expert here.

body_filename = args[0] + '.c'

# not really needed, just for sanity checking
forbidden_kwargs = ['c_template', 'h_template', 'eprod', 'fhead',
Copy link
Member

Choose a reason for hiding this comment

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

Maybe make this a whitelist instead of a blacklist? Similar to mkenums() itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

The main purpose of this was to catch old-api arguments from people who migrate from mkenums to mkenums_simple, to make sure there is no leakage. I can also remove this entirely. Our implementation calls the mkenums implementation in the end, so things will be checked there too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, what I wrote makes no sense because I only copy over specific fields via a whitelist already, so there can be no leakage. Just unused args in meson.build file.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but a whitelist will also protect against typos of kwargs that we do accept, that's all.

@tp-m
Copy link
Member Author

tp-m commented May 15, 2017

I don't think the code contains anything particularly technically challenging, since we re-use the existing mkenums implementation for all the important bits.

@nirbheek
Copy link
Member

Is there anything else we need to discuss or change here?

@tp-m
Copy link
Member Author

tp-m commented May 31, 2017

It needs to be used and tested with various modules to make sure it fulfils their needs and does everything we want it to.

I want to convert gst-plugins-base at least. I also tried to use it in pango but it caused some weird issue which I didn't have time to debug yet.

@tp-m
Copy link
Member Author

tp-m commented Jul 31, 2017

@alessandrod has successfully converted various GStreamer modules over to this (base+bad), so should be alright.

install: true)
```

*Added 0.41.0*
Copy link
Member

Choose a reason for hiding this comment

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

Bump version

Generates enum `.c` and `.h` files for GObject using the `glib-mkenums` tool
with the standard template used by most GObject-based C libraries. The first
argument is the base name of the output files.

Copy link
Member

Choose a reason for hiding this comment

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

In gnome.mkenums you should probably reference this function and explain why you might want to use this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review, updated.

@tp-m tp-m changed the title gnome: add mkenums_simple() (WIP DO NOT MERGE) gnome: add mkenums_simple() Aug 4, 2017
@tp-m tp-m added this to the 0.42.0 milestone Aug 4, 2017

Example:

```
Copy link
Member

Choose a reason for hiding this comment

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

Specify the meson language for syntax highlighting

@@ -93,6 +99,49 @@ Note that if you `#include` the generated header in any of the sources for a bui

Returns an array of two elements which are: `[c_source, header_file]`

### gnome.mkenums_simple()
Copy link
Member

Choose a reason for hiding this comment

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

Add notes about the new API in docs/markdown/Release-notes-for-0.42.0.md

fhead += '#include "%s"\n' % hdr_filename
for hdr in sources:
fhead += '#include "%s"\n' % hdr
fhead += '''
Copy link
Member

@TingPing TingPing Aug 4, 2017

Choose a reason for hiding this comment

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

All these empty newlines show up in the generated file.

EDIT: Actually this specific newline is fine, but before the includes is 4 empty lines.

@codecov-io
Copy link

codecov-io commented Aug 5, 2017

Codecov Report

Merging #1800 into master will increase coverage by 7.33%.
The diff coverage is 80.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1800      +/-   ##
==========================================
+ Coverage   56.47%   63.81%   +7.33%     
==========================================
  Files          74       74              
  Lines       18192    18238      +46     
  Branches     3787     3796       +9     
==========================================
+ Hits        10274    11638    +1364     
+ Misses       6727     5416    -1311     
+ Partials     1191     1184       -7
Impacted Files Coverage Δ
mesonbuild/modules/gnome.py 60.51% <80.43%> (+1.12%) ⬆️
mesonbuild/dependencies/ui.py 66.02% <0%> (+0.24%) ⬆️
mesonbuild/mesonlib.py 81.92% <0%> (+0.39%) ⬆️
mesonbuild/mtest.py 72.46% <0%> (+1.32%) ⬆️
mesonbuild/compilers/fortran.py 68.75% <0%> (+1.7%) ⬆️
mesonbuild/compilers/compilers.py 81.32% <0%> (+1.81%) ⬆️
mesonbuild/mintro.py 54.73% <0%> (+2.1%) ⬆️
mesonbuild/modules/__init__.py 90.14% <0%> (+2.81%) ⬆️
mesonbuild/coredata.py 72.76% <0%> (+3.82%) ⬆️
mesonbuild/backend/ninjabackend.py 88.1% <0%> (+3.85%) ⬆️
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55165ba...73e5047. Read the comment docs.

# instead, but that seems like much more work, nice as it would be.
fhead = ''
if body_prefix != '':
fhead += '%s\n' % body_prefix
Copy link
Member

Choose a reason for hiding this comment

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

[flake8]

  • [E111] indentation is not a multiple of four

@tp-m
Copy link
Member Author

tp-m commented Aug 5, 2017

Thanks, updated. I believe the remaining three newlines at the beginning of the generated files are glib-mkenum's fault?

@TingPing
Copy link
Member

TingPing commented Aug 5, 2017

I believe the remaining three newlines at the beginning of the generated files are glib-mkenum's fault?

It is possible; extra whitespace isn't a blocker but it would be nice to fix upstream. Anyway works well here 👍

@nirbheek
Copy link
Member

Conflicts, and the windows build needs to be re-triggered; something went weird with the Cygwin build.

99% of all mkenums uses in C libraries use the same basic template,
so add a mkenums_simple() function that takes care of everything for
us based on that template.

Features:
 - optional function declaration decorator such as GLIB_AVAILABLE
 - optional extra header prefix (e.g. for include needed for decorator)
 - optional extra body prefix (e.g. for additional includes)
 - optional function name prefix (e.g. to add leading underscores)

Fixes issue mesonbuild#1384
@tp-m
Copy link
Member Author

tp-m commented Aug 14, 2017

Fixed conflicts, and then again :)

@jpakkane
Copy link
Member

Everyone happy with this now?

@jpakkane jpakkane merged commit 4e476c8 into mesonbuild:master Aug 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants