2010-11-13 15:28:22 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2011-01-21 02:10:11 +00:00
|
|
|
import StringIO, os, platform, shutil, subprocess, sys, tarfile, zipfile
|
2010-11-18 06:31:09 +00:00
|
|
|
import pkg_resources
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
def test():
|
2011-01-15 02:26:51 +00:00
|
|
|
# We put a "fakedependency-1.0.0.egg" package and a
|
|
|
|
# "fakedependency-9.9.99.tar.gz" into a directory, but the latter is
|
|
|
|
# booby-trapped so it will raise an exception when you try to build it.
|
|
|
|
#
|
|
|
|
# Then we run
|
|
|
|
#
|
2011-01-15 04:53:25 +00:00
|
|
|
# python setup.py --fakedependency -v test -s buildtest.test_build_with_fake_dist
|
2011-01-15 02:26:51 +00:00
|
|
|
#
|
2012-05-13 03:42:52 +00:00
|
|
|
# which requires "fakedependency >= 1.0.0", imports fakedependency
|
|
|
|
# and passes if fakedependency.__version__ == '1.0.0'.
|
2011-01-15 02:26:51 +00:00
|
|
|
#
|
2010-11-18 06:31:09 +00:00
|
|
|
# The goal is to turn red if the build system tries to build the
|
|
|
|
# source dist when it could have used the binary dist.
|
2011-01-15 02:26:51 +00:00
|
|
|
#
|
|
|
|
# Note that for this test to make sense, Tahoe-LAFS needs to be asking
|
|
|
|
# for a version of fakedependency which can be satisfied by 1.0.0.
|
|
|
|
# The --fakedependency option to setup.py arranges that.
|
2010-11-18 06:31:09 +00:00
|
|
|
|
|
|
|
fake_distdir = 'tahoe-deps'
|
2011-01-15 02:26:51 +00:00
|
|
|
fake_distname = "fakedependency"
|
2010-11-18 06:31:09 +00:00
|
|
|
fake_sdistversion = "9.9.99"
|
2011-01-15 02:26:51 +00:00
|
|
|
fake_bdistversion = "1.0.0"
|
|
|
|
sdist_setup = "raise Exception('Aha I caught you trying to build me. I am a fakedependency 9.9.99 sdist and you should be satisfied with a bdist.')"
|
2010-11-18 06:31:09 +00:00
|
|
|
|
|
|
|
testsuite = "buildtest.test_build_with_fake_dist"
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
dist_dirname = os.path.join(os.getcwd(), fake_distdir)
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
try:
|
|
|
|
os.makedirs(dist_dirname)
|
|
|
|
except OSError:
|
|
|
|
# probably already exists
|
|
|
|
pass
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
bdist_egg_name = os.path.join(dist_dirname, '%s-%s-py%s.%s-%s.egg' % (fake_distname, fake_bdistversion, platform.python_version_tuple()[0], platform.python_version_tuple()[1], pkg_resources.get_supported_platform()))
|
|
|
|
try:
|
|
|
|
bdist_egg = zipfile.ZipFile(bdist_egg_name, 'w')
|
2011-01-15 02:26:51 +00:00
|
|
|
bdist_egg.writestr('fakedependency/__init__.py', '__version__ = "%s"\n' % (fake_bdistversion,))
|
2010-11-18 06:31:09 +00:00
|
|
|
bdist_egg.close()
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
sdist_name = os.path.join(dist_dirname, '%s-%s.tar' % (fake_distname, fake_sdistversion))
|
|
|
|
sdist = tarfile.open(sdist_name, 'w:gz')
|
2011-01-15 02:26:51 +00:00
|
|
|
sdist.errorlevel = 2
|
2010-11-18 06:31:09 +00:00
|
|
|
tarinfo = tarfile.TarInfo('setup.py')
|
2011-01-15 02:26:51 +00:00
|
|
|
tarinfo.errorlevel = 2
|
2010-11-18 06:31:09 +00:00
|
|
|
tarinfo.size = len(sdist_setup)
|
|
|
|
sdist.addfile(tarinfo, StringIO.StringIO(sdist_setup))
|
|
|
|
sdist.close()
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2011-01-15 02:26:51 +00:00
|
|
|
sys.exit(subprocess.call([sys.executable, "setup.py", "--fakedependency", "-v", "test", "-s", testsuite],
|
|
|
|
env=os.environ))
|
2010-11-18 06:31:09 +00:00
|
|
|
finally:
|
|
|
|
os.remove(bdist_egg_name)
|
|
|
|
os.remove(sdist_name)
|
|
|
|
cleanup()
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
def cleanup():
|
2011-01-15 05:30:11 +00:00
|
|
|
egg_info = os.path.join('src', 'allmydata_tahoe.egg-info')
|
|
|
|
bin_tahoe = os.path.join('bin', 'tahoe')
|
|
|
|
bin_tahoe_pyscript = os.path.join('bin', 'tahoe.pyscript')
|
|
|
|
|
|
|
|
if os.path.exists('build'):
|
|
|
|
shutil.rmtree('build')
|
|
|
|
if os.path.exists('support'):
|
|
|
|
shutil.rmtree('support')
|
|
|
|
if os.path.exists(egg_info):
|
|
|
|
shutil.rmtree(egg_info)
|
|
|
|
if os.path.exists(bin_tahoe):
|
|
|
|
os.remove(bin_tahoe)
|
|
|
|
if os.path.exists(bin_tahoe_pyscript):
|
|
|
|
os.remove(bin_tahoe_pyscript)
|
2010-11-13 15:28:22 +00:00
|
|
|
|
2010-11-18 06:31:09 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
test()
|