blob: 1aa73fc79a7b4e9a4f57ca388da0bb8435e12977 [file] [log] [blame]
Devin Jeanpierre19fc55f2017-04-24 10:49:00 -07001# Copyright 2009 The JsonCpp Authors
Sam Clegg63860612015-04-09 18:01:33 -07002# Distributed under MIT license, or public domain if desired and
3# recognized in your jurisdiction.
4# See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
5
Christopher Dunndc0f7362011-06-21 21:18:49 +00006import fnmatch
7import os
8
Christopher Dunn494950a2015-01-24 15:29:52 -06009def generate(env):
10 def Glob(env, includes = None, excludes = None, dir = '.'):
11 """Adds Glob(includes = Split('*'), excludes = None, dir = '.')
Christopher Dunndc0f7362011-06-21 21:18:49 +000012 helper function to environment.
13
14 Glob both the file-system files.
15
16 includes: list of file name pattern included in the return list when matched.
17 excludes: list of file name pattern exluced from the return list.
18
19 Example:
Christopher Dunn494950a2015-01-24 15:29:52 -060020 sources = env.Glob(("*.cpp", '*.h'), "~*.cpp", "#src")
Christopher Dunndc0f7362011-06-21 21:18:49 +000021 """
22 def filterFilename(path):
Christopher Dunn494950a2015-01-24 15:29:52 -060023 abs_path = os.path.join(dir, path)
Christopher Dunndc0f7362011-06-21 21:18:49 +000024 if not os.path.isfile(abs_path):
25 return 0
26 fn = os.path.basename(path)
27 match = 0
28 for include in includes:
Christopher Dunn494950a2015-01-24 15:29:52 -060029 if fnmatch.fnmatchcase(fn, include):
Christopher Dunndc0f7362011-06-21 21:18:49 +000030 match = 1
31 break
32 if match == 1 and not excludes is None:
33 for exclude in excludes:
Christopher Dunn494950a2015-01-24 15:29:52 -060034 if fnmatch.fnmatchcase(fn, exclude):
Christopher Dunndc0f7362011-06-21 21:18:49 +000035 match = 0
36 break
37 return match
38 if includes is None:
39 includes = ('*',)
Christopher Dunn494950a2015-01-24 15:29:52 -060040 elif type(includes) in (type(''), type(u'')):
Christopher Dunndc0f7362011-06-21 21:18:49 +000041 includes = (includes,)
Christopher Dunn494950a2015-01-24 15:29:52 -060042 if type(excludes) in (type(''), type(u'')):
Christopher Dunndc0f7362011-06-21 21:18:49 +000043 excludes = (excludes,)
44 dir = env.Dir(dir).abspath
Christopher Dunn494950a2015-01-24 15:29:52 -060045 paths = os.listdir(dir)
46 def makeAbsFileNode(path):
47 return env.File(os.path.join(dir, path))
48 nodes = filter(filterFilename, paths)
49 return map(makeAbsFileNode, nodes)
Christopher Dunndc0f7362011-06-21 21:18:49 +000050
51 from SCons.Script import Environment
Baptiste Lepilleurf66d3702008-01-20 16:49:53 +000052 Environment.Glob = Glob
Christopher Dunndc0f7362011-06-21 21:18:49 +000053
54def exists(env):
55 """
56 Tool always exists.
57 """
58 return True