Skip to content

Commit

Permalink
Teach build.py to handle relative paths
Browse files Browse the repository at this point in the history
Previously it was always necessary to be
in the top-level directory for build.py to
work properly. Now, if os.chdir is always
performed to the top-level, and if a build.xml
file is present in the current working dir
(before os.chdir) then it will be passed to
ant as "-f `pwd`/build.xml""

This allows:

  ../../../build.py test

and similar from OmeroPy etc.
  • Loading branch information
joshmoore committed Jan 4, 2013
1 parent 86a72a4 commit 30ebc84
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,46 @@ def choose_omero_version():
sys.exit(1)


def handle_tools(args):
additions = []
while len(args) > 0 and args[0] in ("-perf", "-py", "-cpp"):
if args[0] == "-perf":
args.pop(0)
A = "-listener net.sf.antcontrib.perf.AntPerformanceListener".split()
additions.extend(A)
elif args[0] == "-py":
args.pop(0)
F = os.path.sep.join(["components","tools","OmeroPy","build.xml"])
A = ["-f", F]
additions.extend(A)
elif args[0] == "-cpp":
args.pop(0)
F = os.path.sep.join(["components","tools","OmeroCpp","build.xml"])
A = ["-f", F]
additions.extend(A)
return additions + args


def handle_relative(args):
"""
If no other specific file has been requested,
then use whatever relative path is needed to
specify build.xml in the local directory.
Regardless, os.chdir is called to the top.
"""
additions = []
this = os.path.abspath(__file__)
this_dir = os.path.abspath(os.path.join(this, os.pardir))
cwd = os.path.abspath(os.getcwd())
os.chdir(this_dir)
if "-f" not in args:
build_xml = os.path.join(cwd, "build.xml")
if os.path.exists(build_xml):
additions.append("-f")
additions.append(build_xml)
return additions + args

if __name__ == "__main__":
#
# use java_omero which will specially configure the build system.
Expand All @@ -119,23 +159,8 @@ def choose_omero_version():
del os.environ['CLASSPATH']

try:
additions = []
while len(args) > 0 and args[0] in ("-perf", "-py", "-cpp"):
if args[0] == "-perf":
args.pop(0)
A = "-listener net.sf.antcontrib.perf.AntPerformanceListener".split()
additions.extend(A)
elif args[0] == "-py":
args.pop(0)
F = os.path.sep.join(["components","tools","OmeroPy","build.xml"])
A = ["-f", F]
additions.extend(A)
elif args[0] == "-cpp":
args.pop(0)
F = os.path.sep.join(["components","tools","OmeroCpp","build.xml"])
A = ["-f", F]
additions.extend(A)
args = additions + args
args = handle_tools(args)
args = handle_relative(args)
java_omero(args)
notification(""" Finished: %s """ % " ".join(args), 0)
except KeyboardInterrupt:
Expand Down

0 comments on commit 30ebc84

Please sign in to comment.