[proxysetting] Fix build with NM 1.4
ClosedPublic

Authored by wbauer on Dec 12 2018, 9:28 AM.

Details

Summary

The NMSettingProxyMethod enum only exists since NetworkManager 1.6.
So to make it compile with 1.4.x as well (which is the minimum supported version), use the corresponding numbers instead of the enum defines.

Test Plan

Builds fine now with NM 1.4.x, before there were compiler errors:

In file included from /home/abuild/rpmbuild/BUILD/networkmanager-qt-VERSIONgit.20181211T113515~4332597/src/settings/proxysetting.cpp:21:0:
/home/abuild/rpmbuild/BUILD/networkmanager-qt-VERSIONgit.20181211T113515~4332597/src/settings/proxysetting.h:43:16: error: 'NM_SETTING_PROXY_METHOD_NONE' was not declared in this scope
         None = NM_SETTING_PROXY_METHOD_NONE,
                ^
/home/abuild/rpmbuild/BUILD/networkmanager-qt-VERSIONgit.20181211T113515~4332597/src/settings/proxysetting.h:44:16: error: 'NM_SETTING_PROXY_METHOD_AUTO' was not declared in this scope
         Auto = NM_SETTING_PROXY_METHOD_AUTO
                ^

Still compiles with newer versions, tested with 1.6.0, 1.10.6, and 1.14.4.

Diff Detail

Repository
R282 NetworkManagerQt
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
wbauer created this revision.Dec 12 2018, 9:28 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptDec 12 2018, 9:28 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
wbauer requested review of this revision.Dec 12 2018, 9:28 AM
wbauer added a reviewer: jgrulich.

I think the easiest solution here is just to set 0 and 1 to the enum values, instead of NM defines. I'm not sure if adding/removing enum is ABI compatible change, because the enum will disapper once you build it against NM 1.6.0+.

I think the easiest solution here is just to set 0 and 1 to the enum values, instead of NM defines.

Sure, that would work as well.

But IMHO the version check would make it easier to remove this "hack" when the minimum NM version would be raised at some point in the future.

Whatever you prefer though.

I'm not sure if adding/removing enum is ABI compatible change, because the enum will disapper once you build it against NM 1.6.0+.

Hm, I see what you mean.

I don't think that really is a problem here though, as it is defined in libnm/nm-setting-proxy.h (in NM 1.6+) which is included by this file (via NetworkManager.h that's included by setting.h).
I.e. the enum will still be there when building against NM 1.6.0+ (otherwise the build would fail in the first place anyway, as it is used just a few lines below).

jgrulich accepted this revision.Dec 12 2018, 12:13 PM
This revision is now accepted and ready to land.Dec 12 2018, 12:13 PM

I don't think that really is a problem here though, as it is defined in libnm/nm-setting-proxy.h (in NM 1.6+) which is included by this file (via NetworkManager.h that's included by setting.h).
I.e. the enum will still be there when building against NM 1.6.0+ (otherwise the build would fail in the first place anyway, as it is used just a few lines below).

Sorry, I somehow read "API incompatible"...

TBH, I'm not sure about ABI either. But as this is outside of any class, it shouldn't be a problem? (as mentioned, it would be defined by another include file anyway when building against NM 1.6.0+)

Hm, maybe I should add extern "C" though?
This is inside G_BEGIN_DECLS/G_END_DECLS in nm-setting-proxy.h, which are defined as extern "C" { and } (according to the docs).

So maybe go with the easiest approach and just instead of defines use 0 and 1?

wbauer added a comment.EditedDec 12 2018, 1:16 PM

So maybe go with the easiest approach and just instead of defines use 0 and 1?

Fine with me.

Should I make that conditional depending on the NM version maybe, or just unconditionally use the numbers?

So maybe go with the easiest approach and just instead of defines use 0 and 1?

Fine with me.

Should I make that conditional depending on the NM version maybe, or just unconditionally use the numbers?

Unconditionally. It doesn't matter if it uses defines or numbers directly.

wbauer updated this revision to Diff 47446.Dec 12 2018, 1:33 PM
wbauer edited the summary of this revision. (Show Details)

Don't define the enum, rather use the numbers directly

wbauer requested review of this revision.Dec 12 2018, 1:35 PM
wbauer edited the summary of this revision. (Show Details)
jgrulich accepted this revision.Dec 12 2018, 1:38 PM
This revision is now accepted and ready to land.Dec 12 2018, 1:38 PM
This revision was automatically updated to reflect the committed changes.