abseil-cpp icon indicating copy to clipboard operation
abseil-cpp copied to clipboard

How to deal with duplicated ABSL_FLAG in dependence project?

Open zihaoli-cn opened this issue 2 years ago • 5 comments

I am committing code to a project which heavily uses Abseil's API.

When I tried to use an external Google's open-source project as its dependence, it turned out that they have many flags with the same names, such as minloglevel, vmodule, log_prefix.

I am not supposed to change the current project's names of flags, and I think it's not a good idea to change the names of flags in the external dependent project.

What is the best practice to deal with this scenario?

zihaoli-cn avatar May 19 '22 06:05 zihaoli-cn

Unfortunately, there's not a good general answer here as far as I know. It's generally discouraged for libraries to have command line flags. It's certainly discouraged for binaries to have multiple commandline flag APIs (how do you even parse those?). And when flags collide even with a single flag system, it's very manual and bug-prone to resolve.

In practice, the flags you mention are all logging related, which might allow for some options. Are all of the colliding flags related to logging, or just the ones you listed?

On Thu, May 19, 2022 at 2:42 AM Zihao li @.***> wrote:

I am committing code to a project which heavily uses Abseil's API.

When I tried to use an external Google's open-source project as its dependence, it turned out that they have many flags with the same names, such as minloglevel, vmodule, log_prefix.

I am not supposed to change the current project's names of flags, and I think it's not a good idea to change the names of flags in the external dependent project.

What is the best practice to deal with this scenario?

— Reply to this email directly, view it on GitHub https://github.com/abseil/abseil-cpp/issues/1180, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC7CRXZI4A42A24KPX36SILVKXPFZANCNFSM5WLDUWEQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- *If you get an email from me outside of the 9-5 it is not because I'm always on or expect an immediate response from you; it is because of work flexibility http://www.inc.com/john-boitnott/how-flexible-hours-can-create-a-better-work-life-balance.html . Evening and weekend emails are a sign I allocated some regular working hours for other things (such as family, gym, friends,...). And I encourage you to feel free to do the same.

tituswinters avatar May 19 '22 13:05 tituswinters

@tituswinters Thanks for replying,

Yeah, they are all logging-related. In this case, what do you think is best for me?

zihaoli-cn avatar May 19 '22 15:05 zihaoli-cn

If it's two different libraries that are configuring the same logging API with identical flags - can you remove the flags from one of them, or add a configuration where one of them optionally skips having those flags?

If it's actually configuring two different logging libraries, then you've got a worse set of problems. Libraries really shouldn't be defining flags nor configuring their own logging, in the general case.

(There's still not a trivial fix here, but those are the types of things that might work.)

tituswinters avatar May 19 '22 15:05 tituswinters

Thanks a lot for your suggestion!

I guess I should just remove those duplicated flags to make it work right now.

zihaoli-cn avatar May 20 '22 04:05 zihaoli-cn

I saw a clever way to deal with the duplicated flags. I can modify the dependence project on a specific commit and use "git diff" to generate a patch.

Here is an example, link, which is a commit to deal with the dependence problem.

It is a good reference for those who encountered the same problem as I did.

zihaoli-cn avatar Jun 09 '22 08:06 zihaoli-cn