Skip to content

Commit f01b4b5

Browse files
committed
Make the zipfile distributions build within a variant directory and
avoid including build-related files.
1 parent a8745e8 commit f01b4b5

File tree

4 files changed

+131
-37
lines changed

4 files changed

+131
-37
lines changed

SConscript

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1+
import os
12
import re
2-
Import('RecursiveGlob')
3+
Import('env')
4+
5+
# clone the environment so as not to pollute the parent
6+
my_env = env.Clone()
37

48
# divine the version number from thrust/version.h
5-
version = int(re.search('THRUST_VERSION ([0-9]+)', open('thrust/version.h').read()).group(1))
9+
version = int(re.search('THRUST_VERSION ([0-9]+)', File('#thrust/version.h').get_contents()).group(1))
610
major = int(version / 100000)
711
minor = int(version / 100) % 1000
812
subminor = version % 100
913

10-
# create the zip distribution
11-
# note that we package the CHANGELOG with the headers
12-
installation_nodes = Install('thrust', 'CHANGELOG')
13-
Zip('thrust-{0}.{1}.{2}.zip'.format(major,minor,subminor), 'thrust')
14+
# create the Thrust zip
15+
for item in my_env.RecursiveGlob('*', '#thrust'):
16+
my_env.InstallAs(os.path.join('thrust', Dir('#thrust').rel_path(item)), item)
17+
# grab the CHANGELOG as well
18+
my_env.Install('thrust', '#CHANGELOG')
19+
20+
# make sure to change directory into the variant dir to ensure the paths are correct in the zipfile
21+
# note Zip uses the special site_scons/site_tools/zip.py to WAR an issue with the chdir parameter
22+
my_env.Zip('thrust-{0}.{1}.{2}.zip'.format(major,minor,subminor), 'thrust', chdir = 1)
23+
1424

1525
# create the examples zip
16-
# XXX we shouldn't include build files in the zip
17-
# XXX this should be rewritten
18-
Zip('examples-{0}.{1}.zip'.format(major,minor), 'examples')
26+
# do not recurse into the 'targets' directory, should it exist
27+
for item in my_env.RecursiveGlob('*', '#examples', 'targets'):
28+
# avoid included SCons-related files in the distribution
29+
# XXX would be nice if we could ignore all dotfiles and anything in .gitignore
30+
if item.get_path(item.get_dir()) not in ['SConscript','.sconsign.dblite']:
31+
my_env.InstallAs(os.path.join('examples', Dir('#examples').rel_path(item)), item)
32+
# make sure to change directory into the variant dir to ensure the paths are correct in the zipfile
33+
# note Zip uses the special site_scons/site_tools/zip.py to WAR an issue with the chdir parameter
34+
my_env.Zip('examples-{0}.{1}.zip'.format(major,minor), 'examples', chdir = 1)
1935

2036
# generate documentation
21-
public_headers = RecursiveGlob(Environment(), '*.h', '#thrust', exclude='detail')
22-
Command('doc/html', public_headers, 'doxygen doc/thrust.dox')
23-
Clean('doc', 'doc/html')
37+
public_headers = my_env.RecursiveGlob('*.h', '#thrust', exclude='detail')
38+
my_env.Command('doc/html', public_headers, 'doxygen doc/thrust.dox')
2439

SConstruct

+3-4
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def command_line_variables():
305305

306306
# create a master Environment
307307
vars = command_line_variables()
308-
master_env = Environment(variables = vars, tools = ['default', 'nvcc'])
308+
master_env = Environment(variables = vars, tools = ['default', 'nvcc', 'zip'])
309309

310310
# XXX it might be a better idea to harvest help text from subsidiary
311311
# SConscripts and only add their help text if one of their targets
@@ -356,7 +356,6 @@ for (host,device) in itertools.product(host_backends, device_backends):
356356
env.SConscript('testing/SConscript', exports='env', variant_dir = 'testing/' + targets_dir, duplicate = 0)
357357
env.SConscript('performance/SConscript', exports='env', variant_dir = 'performance/' + targets_dir, duplicate = 0)
358358

359-
# the top-level SConscript doesn't need a variant directory as it has no build variation
360-
# pass RecursiveGlob to the SConscript as it needs to find all public Thrust headers
361-
master_env.SConscript('SConscript', exports='RecursiveGlob')
359+
env = master_env
360+
master_env.SConscript('SConscript', exports='env', variant_dir = 'targets', duplicate = False)
362361

examples/cpp_integration/README.txt

-21
This file was deleted.

site_scons/site_tools/zip.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
"""SCons.Tool.zip
2+
3+
Tool-specific initialization for zip.
4+
5+
There normally shouldn't be any need to import this module directly.
6+
It will usually be imported through the generic SCons.Tool.Tool()
7+
selection method.
8+
9+
This version applies the patch from scons.tigris.org/issues/show_bug.cgi?id=2575
10+
11+
"""
12+
13+
#
14+
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
15+
#
16+
# Permission is hereby granted, free of charge, to any person obtaining
17+
# a copy of this software and associated documentation files (the
18+
# "Software"), to deal in the Software without restriction, including
19+
# without limitation the rights to use, copy, modify, merge, publish,
20+
# distribute, sublicense, and/or sell copies of the Software, and to
21+
# permit persons to whom the Software is furnished to do so, subject to
22+
# the following conditions:
23+
#
24+
# The above copyright notice and this permission notice shall be included
25+
# in all copies or substantial portions of the Software.
26+
#
27+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
28+
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
29+
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34+
#
35+
36+
__revision__ = "src/engine/SCons/Tool/zip.py 5134 2010/08/16 23:02:40 bdeegan"
37+
38+
import os.path
39+
40+
import SCons.Builder
41+
import SCons.Defaults
42+
import SCons.Node.FS
43+
import SCons.Util
44+
45+
try:
46+
import zipfile
47+
internal_zip = 1
48+
except ImportError:
49+
internal_zip = 0
50+
51+
if internal_zip:
52+
zipcompression = zipfile.ZIP_DEFLATED
53+
def zip(target, source, env):
54+
compression = env.get('ZIPCOMPRESSION', 0)
55+
zf = zipfile.ZipFile(target[0].abspath, 'w', compression)
56+
for s in source:
57+
if s.isdir():
58+
for dirpath, dirnames, filenames in os.walk(os.path.relpath(s.abspath)):
59+
for fname in filenames:
60+
path = os.path.join(dirpath, fname)
61+
if os.path.isfile(path):
62+
zf.write(path)
63+
else:
64+
zf.write(os.path.relpath(s.abspath))
65+
zf.close()
66+
else:
67+
zipcompression = 0
68+
zip = "$ZIP $ZIPFLAGS ${TARGET.abspath} $SOURCES"
69+
70+
71+
zipAction = SCons.Action.Action(zip, varlist=['ZIPCOMPRESSION'])
72+
73+
ZipBuilder = SCons.Builder.Builder(action = SCons.Action.Action('$ZIPCOM', '$ZIPCOMSTR'),
74+
source_factory = SCons.Node.FS.Entry,
75+
source_scanner = SCons.Defaults.DirScanner,
76+
suffix = '$ZIPSUFFIX',
77+
multi = 1)
78+
79+
80+
def generate(env):
81+
"""Add Builders and construction variables for zip to an Environment."""
82+
try:
83+
bld = env['BUILDERS']['Zip']
84+
except KeyError:
85+
bld = ZipBuilder
86+
env['BUILDERS']['Zip'] = bld
87+
88+
env['ZIP'] = 'zip'
89+
env['ZIPFLAGS'] = SCons.Util.CLVar('')
90+
env['ZIPCOM'] = zipAction
91+
env['ZIPCOMPRESSION'] = zipcompression
92+
env['ZIPSUFFIX'] = '.zip'
93+
94+
def exists(env):
95+
return internal_zip or env.Detect('zip')
96+
97+
# Local Variables:
98+
# tab-width:4
99+
# indent-tabs-mode:nil
100+
# End:
101+
# vim: set expandtab tabstop=4 shiftwidth=4:

0 commit comments

Comments
 (0)