From b75276af005e1108fec5645fa0e3669ba208e7eb Mon Sep 17 00:00:00 2001
From: Brian Warner <warner@lothar.com>
Date: Wed, 12 Sep 2007 16:48:45 -0700
Subject: [PATCH] packaging: add 'build-deps' target, to automatically build
 and install (locally, in ./support) necessary dependencies. All such
 installed files are used during tests.

---
 .darcs-boringfile     |  8 ++++----
 Makefile              | 13 +++++++++++++
 README                |  4 +++-
 misc/find-dep-eggs.py | 14 ++++++++++++++
 misc/pyver.py         |  4 ++++
 5 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 misc/find-dep-eggs.py
 create mode 100644 misc/pyver.py

diff --git a/.darcs-boringfile b/.darcs-boringfile
index ea5e78bc..77dcc7d3 100644
--- a/.darcs-boringfile
+++ b/.darcs-boringfile
@@ -74,10 +74,10 @@
 # this file is maintained by the buildbot
 ^\.buildbot-sourcedata$
 
-# these .eggs are downloaded by ez_setup.py when it doesn't like the version
-# that is currently installed (or it is missing).
-^src/simplejson/setuptools-.*\.egg$
-^src/zfec/setuptools-.*\.egg$
+# automatically-build dependencies (using the 'build-deps' target) go here
+^support
+# creating a tahoe egg puts files here
+^allmydata_tahoe.egg-info
 
 # generated crypto extension modules
 ^src/allmydata/Crypto/[^/]*/.*\.so$
diff --git a/Makefile b/Makefile
index 0459c84f..d687ffe5 100644
--- a/Makefile
+++ b/Makefile
@@ -64,6 +64,19 @@ make-version:
 build: make-version
 	$(PP) $(PYTHON) ./setup.py build_ext -i
 
+PYVER=$(shell $(PYTHON) misc/pyver.py)
+SUPPORT = $(BASE)/support
+SUPPORTLIB = $(SUPPORT)/lib/$(PYVER)/site-packages
+build-deps:
+	mkdir -p $(SUPPORTLIB)
+	PYTHONPATH=$(SUPPORTLIB) $(PYTHON) setup.py install \
+	 --prefix=$(SUPPORT)
+EGGSPATH = $(shell $(PYTHON) misc/find-dep-eggs.py)
+show-eggspath:
+	@echo $(EGGSPATH)
+
+PP = PYTHONPATH=$(EGGSPATH)
+
 # 'make install' will do the following:
 #   build+install tahoe (probably to /usr/lib/pythonN.N/site-packages)
 
diff --git a/README b/README
index cfb060e4..2b21d828 100644
--- a/README
+++ b/README
@@ -181,7 +181,9 @@ Running-In-Place Way.  Choose one:
  The Running-In-Place Way:
 
   You can use Tahoe without installing it. Once you've built Tahoe then you
-  can execute "./bin/allmydata-tahoe".
+  can execute "./bin/allmydata-tahoe". (When the allmydata-tahoe script is in
+  an Tahoe source distribution, it adds the necessary directory to the Python
+  "sys.path".)
 
 
 TESTING THAT IT IS PROPERLY INSTALLED
diff --git a/misc/find-dep-eggs.py b/misc/find-dep-eggs.py
new file mode 100644
index 00000000..ebd8129d
--- /dev/null
+++ b/misc/find-dep-eggs.py
@@ -0,0 +1,14 @@
+#! /usr/bin/python
+
+import os.path, sys
+
+pyver = "python%d.%d" % (sys.version_info[:2])
+
+path = []
+support_lib = "support/lib/%s/site-packages" % pyver
+if os.path.exists(support_lib):
+    for fn in os.listdir(support_lib):
+        if fn.endswith(".egg"):
+            path.append(os.path.abspath(os.path.join(support_lib, fn)))
+
+print ":".join(path)
diff --git a/misc/pyver.py b/misc/pyver.py
new file mode 100644
index 00000000..aea81100
--- /dev/null
+++ b/misc/pyver.py
@@ -0,0 +1,4 @@
+#! /usr/bin/python
+
+import sys
+print "python%d.%d" % (sys.version_info[:2])
-- 
2.45.2