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

Client generation #15

Merged
merged 34 commits into from
Mar 27, 2018
Merged

Client generation #15

merged 34 commits into from
Mar 27, 2018

Conversation

colonelpanic8
Copy link
Contributor

@colonelpanic8 colonelpanic8 commented Mar 7, 2018

This builds on #12 with support for client generation

Fixes #3, #14

@colonelpanic8
Copy link
Contributor Author

hlint error is due to ndmitchell/hlint#332

@colonelpanic8 colonelpanic8 force-pushed the clientGeneration branch 2 times, most recently from 35c2acb to 6eeecf7 Compare March 8, 2018 04:22
@colonelpanic8
Copy link
Contributor Author

@rblaze
Copy link
Owner

rblaze commented Mar 9, 2018

Ivan, first, thanks again for your contribution! But I feel we need to get a bit more organized here: with 40 commits this becomes longest email thread in my inbox this year. And it is quite hard to review, I don't even know when to start.

Could you please make all the intermediate changes in the forked repo, squash changes and send one-diff pull requests, self-contained and ready to merge? It would also help a lot if each pull request will have complete, but relatively small scope: it is much easier to review three 50-line diffs than one 150-line.

By the way, feel free to drop support for ghc versions before 7.10.3, just remove them from travis config.

@colonelpanic8
Copy link
Contributor Author

colonelpanic8 commented Mar 9, 2018

Could you please make all the intermediate changes in the forked repo, squash changes and send one-diff pull requests, self-contained and ready to merge? It would also help a lot if each pull request will have complete, but relatively small scope: it is much easier to review three 50-line diffs than one 150-line.

I can squash the commits, but this change depends on the new properties functions in #12 so its scope really can't be made much smaller, unfortunately.

The diff from the tip of #12 (This is what the diff would look like if #12 were merged) is actually not SO bad:
https://github.com/rblaze/haskell-dbus/pull/15/files/5d8e670161cbdb943242313ddd7a41d87a795888..74d94a000937da3d9960c0e2bdbe3ded956ec39c

You'll notice that almost all of the diff is the addition of a new file: lib/DBus/Generation.hs, and that there are actually only 3 lines that are deleted (changed) which should make this change very safe.

Basically, what this change does is add facilities to generate clients and signal/emission/registration functions. I would recommend that you not even try to review lib/DBus/Generation.hs, as reading template haskell code can be very difficult. I did add a test in tests/DBusTests/Client.hs that should give you some confidence that the code actually works. The new files tests/DBusTests/Generation.hs and tests/DBusTests/TH.hs are simply to support that test. They have to be in separate files becuase of annoying limitations of template haskell.

You may also want to check out
https://github.com/IvanMalison/status-notifier-item which is using all of the new generations facilities quite a lot.

In https://github.com/IvanMalison/status-notifier-item/blob/master/src/StatusNotifier/Item/Constants.hs we load an xml file from which bindings for the client are created in
https://github.com/IvanMalison/status-notifier-item/blob/master/src/StatusNotifier/Item/Client.hs

I've included gists of the output that is produced by the generations calls here. Looking at these might help give you a sense of what generation is doing.

Client: https://gist.github.com/2df87d651b3f78da87e3198b457054fc
Signals: https://gist.github.com/a49868a2eff677ac42b3751a4098a7c2
(Tip: The raw versions are easier to read)

@colonelpanic8
Copy link
Contributor Author

Also, if it would be helpful, I would be happy to get on a skype call or something like that to walk you through the changes.

@colonelpanic8
Copy link
Contributor Author

@rblaze This should be a bit easier to review now that #12 is merged :)

The template haskell parts are all completely new, so shouldn't affect any existing stuff anyway.

@colonelpanic8
Copy link
Contributor Author

@rblaze Is there anything I can do to help out here? I'd really like to get this merged so that I can make new releases of several projects.

Copy link
Owner

@rblaze rblaze left a comment

Choose a reason for hiding this comment

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

Looks good, but I have a few style issues.

, genInterfaceName = fromString ""
, getTHType = defaultGetTHType
, genObjectPath = Nothing
, genTakeSignalErrorHandler = False
Copy link
Owner

Choose a reason for hiding this comment

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

/home/travis/build/rblaze/haskell-dbus/lib/DBus/Generation.hs:96:3: warning: [-Wmissing-fields]
• Fields of ‘GenerationParams’ not initialised: useDBusR
• In the expression:
GenerationParams
{genBusName = Nothing, genInterfaceName = fromString "",
getTHType = defaultGetTHType, genObjectPath = Nothing,
genTakeSignalErrorHandler = False}

|]
getFunctionBody = [|
do
let $( varP methodCallN ) = $( setMethodCallParamsE )
Copy link
Owner

Choose a reason for hiding this comment

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

There are multiple warnings like this:
This pattern-binding binds no variables:
$(varP methodCallN) = $setMethodCallParamsE

I'm not familiar with template haskell, is this compiler misunderstanding something or a genuine issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lib/DBus/TH.hs Outdated

import DBus.Client
import DBus.Generation
import qualified DBus.Introspection as I
Copy link
Owner

Choose a reason for hiding this comment

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

The qualified import of ‘DBus.Introspection’ is redundant
  except perhaps to import instances from ‘DBus.Introspection’
To import instances alone, use: import DBus.Introspection()

lib/DBus/TH.hs Outdated
import System.FilePath


generateSignalsFromInterface defaultGenerationParams $
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like generated code isn't very clean:
Top-level binding with no type signature: signalForPropertiesChanged :: DBus.Internal.Message.Signal
Top-level binding with no type signature: methodCallForInterfaces :: DBus.Internal.Message.MethodCall
Defined but not used: ‘replySuccess’
etc...

Can you make sure it compiles without warnings? It is very annoying when library adds a lot of warning noise.

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 got rid of all of these except for the replySuccess not being used. That one only comes up when there are no return values for a method. Getting rid of it would require a lot more code.

import qualified Control.Exception
import Control.Exception (SomeException, throwIO)
import Control.Lens
import Control.Monad
import Control.Monad.Reader
Copy link
Owner

Choose a reason for hiding this comment

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

Can't we use Reader from transformers? Using mtl and transformers in the same library looks counterintuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep. good catch.

@colonelpanic8
Copy link
Contributor Author

Not sure why the build errored.

If you take a look at the output of the build here:

https://travis-ci.org/rblaze/haskell-dbus/jobs/357683407

the only thing there is the no bindings for pattern and the (existing) orphan instance issues.

@rblaze
Copy link
Owner

rblaze commented Mar 27, 2018

It timed out. It happens sometimes, restarting build helps usually (you need to login to travis with github account for this). I'll do it now.

@rblaze rblaze merged commit 34cf8ff into rblaze:master Mar 27, 2018
@rblaze
Copy link
Owner

rblaze commented Mar 27, 2018

I'm looking into changing library license from GPL to Apache, to make it easier to use in non-GPL projects. Are you okay with releasing your changes under Apache license?

@colonelpanic8
Copy link
Contributor Author

sure

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