This is an archive of the discontinued LLVM Phabricator instance.

Add target and host platform enums so we're not using strings everywhere
ClosedPublic

Authored by zturner on Feb 10 2016, 11:56 AM.

Details

Summary

The original motivation for this came when I tried to combine two decorators:

@expectedFailureDarwin
@expectedFailureLinux

into a single decorator:

@expectedFailureAll(oslist=...)

This results in a really ugly syntax, because @expectedFailureDarwin calls getDarwinOsTriples() which is itself a list. So you would have to do something like this:

@expectedFailureAll(oslist=getDarwinOsTriples()+["linux"])

Not the end of the world, but not ideal either. Then I remembered that we've all had this ugliness surrounding the translation of python api calls such as sys.name, os.platform, and target names and host names into something consistent, so it occurred to me that many things would become cleaner and more elegant if we had actual enums for everything, and a centralized place where we can convert between enums and strings or whatever else we need.

So this patch introduces two enums. target and host, updates the common decorator to support these values from these enums, and changes two decorators to using these new values as a proof of concept.

One nice thing about these enums is that we can make standardized enum values for "combinations" of targets or hosts where it makes sense (such as is the case of with darwin, which is why the getDarwinOsTriples() function existed in the first place. So in that sense it works similarly to a flags enum in C / C++.

Eventually it would be nice if we could start using these enums all over the codebase instead of using strings everywhere, but this patch does not attempt to solve that problem.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 47498.Feb 10 2016, 11:56 AM
zturner retitled this revision from to Add target and host platform enums so we're not using strings everywhere.
zturner updated this object.
zturner added reviewers: tfiala, labath, tberghammer.
zturner added a subscriber: lldb-commits.
labath edited edge metadata.Feb 11 2016, 1:22 AM

I like the idea. I think this could help us with the linux vs. android dilemma we've been having recently: currently, we consider android to be a flavour of linux, which means it's not possible to XFAIL tests passing on android but failing on linux. This should make expressing something like that easier.

I wonder, however, whether you need separate enums for host and target. I mean, any system can be used as one or the other, right? (Granted, nobody has tried bringing up lldb client on e.g., android, but I actually don't expect it would be so hard, and I don't see a reason to not support it here). What would you say to merging the two enums and calling it simply os, platform or something?

I think technically there are some platforms that cannot be both a host and a target. ios and anything involving a simulator comes to mind. But, if the only "gotcha" to having both of them be in the same enum is that it's up to the programmer to make sure he's using the right value in the context, then perhaps it's not the end of the world.

BTW, there were some things I wasn't sure whether to add to the enum here. android, remote_android, ios-simulator, etc. Should I add them, or should I leave it as is for now and let other people fix up their own platforms?

I think technically there are some platforms that cannot be both a host and a target. ios and anything involving a simulator comes to mind. But, if the only "gotcha" to having both of them be in the same enum is that it's up to the programmer to make sure he's using the right value in the context, then perhaps it's not the end of the world.

Although unlikely, I don't think there is an inherent reason lldb could not run there, so yeah, I think one list is better.

BTW, there were some things I wasn't sure whether to add to the enum here. android, remote_android, ios-simulator, etc. Should I add them, or should I leave it as is for now and let other people fix up their own platforms?

I think we should let people add targets when they need to, so let's leave these out for now. As I said, right now we treat android as a flavour of linux. When we change that we can add android and linux_all (or something like that) to the list.

zturner updated this revision to Diff 47684.Feb 11 2016, 10:51 AM
zturner edited edge metadata.

Merged into one list. Also moved code into a new module lldbplatform.

labath accepted this revision.Feb 12 2016, 3:58 AM
labath edited edge metadata.

looks good.

This revision is now accepted and ready to land.Feb 12 2016, 3:58 AM
tfiala accepted this revision.Feb 15 2016, 11:52 AM
tfiala edited edge metadata.

LGTM. Having the single list to cover host and target is a good way to go here, too.

This revision was automatically updated to reflect the committed changes.