Page MenuHomePhabricator

Introduce a mechanism for sharing code across lldb/test and lldb/scripts

Authored by zturner on Oct 20 2015, 10:34 AM.



We have a lot of Python code in test and scripts that in theory could be reused amongst the two. Until now there is no mechanism to support this because Python's module / packaging system imposes some limitations on how and where your code must be in order to be re-used.

This patch addresses this by creating a new module lldb_shared which searches up the tree until it finds an lldb.root file. Then, it dynamically imports lldb_shared_base from that folder. lldb_shared_base is a module that exists only as a means to modify sys.path to add all of the shared module locations ot the path.

In order to make use of this, you need to copy the file into the root of each project that you wish to make use of this shared code.

The end result of this is that if you have a directory structure like this:

\__ test
\__ scripts
\__ common
\__ third_party
     \__ six

All you need to do is add to the root of lldb/test and lldb/scripts and then you can write

import lldb_shared
import useful_utility
import six

This patch is dependent on D13880

Diff Detail

Event Timeline

zturner updated this revision to Diff 37894.Oct 20 2015, 10:34 AM
zturner retitled this revision from to Introduce a mechanism for sharing code across lldb/test and lldb/scripts.
zturner updated this object.
zturner added a reviewer: tfiala.
zturner updated this object.
zturner added a subscriber: lldb-commits.
tfiala accepted this revision.Oct 20 2015, 1:57 PM
tfiala edited edge metadata.

Yep, like it.

This revision is now accepted and ready to land.Oct 20 2015, 1:57 PM
zturner closed this revision.Oct 20 2015, 2:11 PM