ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/build_utils/load_plat.py
(Generate patch)

Comparing ray/build_utils/load_plat.py (file contents):
Revision 1.8 by schorsch, Tue Jun 6 22:32:05 2006 UTC vs.
Revision 1.20 by schorsch, Tue Jan 9 00:08:57 2018 UTC

# Line 1 | Line 1
1 + from __future__ import division, print_function, unicode_literals
2  
3   import os
4   import sys
5 < import ConfigParser
5 > import re
6 > import platform
7 > try: import configparser # Py3
8 > except ImportError:
9 >        import ConfigParser as configparser # Py2
10  
6
11   _platdir = 'platform'
12  
13  
14 < def read_plat(env, args, fn):
15 <        cfig = ConfigParser.ConfigParser(env.Dictionary())
14 > def read_plat(env, fn):
15 >        envdict = env.Dictionary().copy()
16 >        # can't feed configparser the original dict, because it also
17 >        # contains non-string values.
18 >        for k,v in list(envdict.items()): # make a list, so we can change the dict.
19 >                if not isinstance(v, str):
20 >                        del envdict[k]
21 >        cfig = configparser.ConfigParser(envdict)
22          cfig.read(fn)
23 <        buildvars = [['CC'], # replace
23 >        buildvars = [['CC',
24 >                        'TIFFINCLUDE', # where to find preinstalled tifflib headers
25 >                        'TIFFLIB',     # where to find a preinstalled tifflib library
26 >                        ], # replace
27                          ['CPPPATH', 'CPPDEFINES', 'CPPFLAGS', 'CCFLAGS',
28 <                        'LIBPATH', 'LINKFLAGS']] # append
28 >                        'LIBS', 'LIBPATH', 'LINKFLAGS',
29 >                        'EZXML_CPPDEFINES', # build flags specific to ezxml.c
30 >                        ]] # append
31          vars = [
32                  ['install',
33                          ['RAD_BASEDIR', 'RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR'],
34                          []],
35                  ['code',
36 <                        [], # replace
36 >                        [   # replace
37 >                        ],
38                          [   # append
39 <                        'RAD_COMPAT',    # currently obsolete
39 >                        'RAD_COMPAT',     # theoretically obsolete (src/common/strcmp.c)
40                          'RAD_MATHCOMPAT', # erf.c floating point error function
41                          'RAD_ARGSCOMPAT', # fixargv0.c for Windows
42                          'RAD_NETCOMPAT',  # [win_]netproc.c for ranimate
43                          'RAD_MLIB',       # usually 'm', or any fastlib available
44                          'RAD_SOCKETLIB',  # ws_2_32 on Windows (VC links it automatically)
45 <                        'RAD_PROCESS']],  # our process abstraction and win_popen()
45 >                        'RAD_PROCESS',    # our process abstraction and win_popen()
46 >                        'RAD_PCALLS',     # more custom process abstraction
47 >                        ]],
48          ]
49 <        if args.get('RAD_DEBUG',0):
49 >        if env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',False,None):
50                  vars.insert(0, ['debug'] + buildvars)
51 <        else: vars.insert(0, ['build'] + buildvars)
51 >                print('Processing DEBUG version')
52 >        else:
53 >                vars.insert(0, ['build'] + buildvars)
54 >                print('Processing RELEASE version')
55          for section in vars:
56                  if cfig.has_section(section[0]):
57                          for p in section[1]: # single items to replace
58                                  try: v = cfig.get(section[0], p)
59 <                                except ConfigParser.NoOptionError: continue
59 >                                except configparser.NoOptionError: continue
60 >                                if section[0] in ('install','build','debug'):
61 >                                        if '{' in v:
62 >                                                v = subst_sysenvvars(v, env)
63                                  env[p] = v
64 <                                #print '%s: %s' % (p, env[p])
64 >                                #print('%s: %s' % (p, env[p]))
65                          for p in section[2]: # multiple items to append
66 <                                try: v = cfig.get(section[0], p)
67 <                                except ConfigParser.NoOptionError: continue
68 <                                apply(env.Append,[],{p:`v`.split()})
69 <                                #print '%s: %s' % (p, env[p])
70 <        # XXX Check that basedir exists.
66 >                                try:
67 >                                        v = cfig.get(section[0], p)
68 >                                        if section[0] in ('build','debug') and '{' in v:
69 >                                                v = subst_sconsvars(v, env)
70 >                                        #print('%s: %s - %s' % (section[0], p, v))
71 >                                except configparser.NoOptionError: continue
72 >                                env.Append(*[], **{p:env.Split(v)})
73 >                                #apply(env.Append,[],{p:env.Split(v)})
74 >
75 > def combine_instpaths(env):
76 >        # XXX Check that basedir exists?
77          for k in ['RAD_BINDIR', 'RAD_RLIBDIR', 'RAD_MANDIR']:
78                  if (env.has_key('RAD_BASEDIR') and env.has_key(k)
79                                  and not os.path.isabs(env[k])):
80                          env[k] = os.path.join(env['RAD_BASEDIR'],env[k])
81  
82  
83 < def load_plat(env, args, platform=None):
84 <        if platform == None: # override
85 <                p = sys.platform
86 <        else: p = platform
87 <        if p == 'win32' and 'gcc' in env['TOOLS']:
88 <                # we don't really want to know this here...
89 <                p = 'mingw'
90 <        pl = []
91 <        print 'Detected platform "%s" (%s).' % (sys.platform, os.name)
92 <        for i in [len(p), -1, -2]:
93 <                pfn = os.path.join(_platdir, p[:i] + '_custom.cfg')
94 <                if os.path.isfile(pfn):
95 <                        print 'Reading configuration "%s"' % pfn
96 <                        read_plat(env, args, pfn)
97 <                        return 1
98 <                pfn = os.path.join(_platdir, p[:i] + '.cfg')
99 <                if os.path.isfile(pfn):
100 <                        print 'Reading configuration "%s"' % pfn
101 <                        read_plat(env, args, pfn)
102 <                        return 1
103 <                
83 >
84 > def subst_sysenvvars(s, env):
85 >        try: return s.format(**os.environ)
86 >        except KeyError: return s
87 >
88 > def subst_sconsvars(s, env,
89 >                pat=re.compile('({[a-z0-9_]+})', re.I)):
90 >        l = pat.split(s)
91 >        nl = []
92 >        for ss in l:
93 >                if ss.startswith('{') and ss.endswith('}'):
94 >                        v = env.get(ss[1:-1])
95 >                        #print(ss, v)
96 >                        if v:
97 >                                if v.startswith('#'):
98 >                                        v = str(env.Dir(v))
99 >                                nl.append(v)
100 >                                continue
101 >                nl.append(ss)
102 >        return ''.join(nl)
103 >
104 >
105 > def identify_plat(env):
106 >        memmodel, binformat = platform.architecture()
107 >        platsys = platform.system()
108 >        print('Detected platform "%s" (%s).' % (platsys, memmodel))
109 >        cfgname = platsys + '_' + memmodel[:2]
110 >        env['CFG_PLATSYS'] = platsys
111 >        env['CFG_MEMMODEL'] = memmodel[:2]
112 >        env['CFG_PATHFILE'] = os.path.join('#scbuild', cfgname, 'install_paths.py')
113 >        env['CFG_OPTFILE']  = os.path.join('#scbuild', cfgname, 'build_opts.py')
114 >
115 >
116 > def load_plat(env, testenv):
117 >        platsys = testenv['CFG_PLATSYS']
118 >        memmodel = testenv['CFG_MEMMODEL']
119 >        cfgname = platsys + '_' + memmodel[:2]
120 >
121 >        env['RAD_BUILDBIN'] = os.path.join('#scbuild', cfgname, 'bin')
122 >        env['RAD_BUILDLIB'] = os.path.join('#scbuild', cfgname, 'lib')
123 >        env['RAD_BUILDOBJ'] = os.path.join('#scbuild', cfgname, 'obj')
124 >
125 >        cust_pfn = os.path.join(_platdir, cfgname + '_custom.cfg')
126 >        if os.path.isfile(cust_pfn):
127 >                print('Reading configuration "%s"' % cust_pfn)
128 >                read_plat(env, cust_pfn)
129 >                return 1
130 >        pfn = os.path.join(_platdir, cfgname + '.cfg')
131 >        if os.path.isfile(pfn):
132 >                print('Reading configuration "%s"' % pfn)
133 >                read_plat(env, pfn)
134 >                return 1
135 >
136          if os.name == 'posix':
137                  pfn = os.path.join(_platdir, 'posix.cfg')
138                  if os.path.isfile(pfn):
139 <                        print 'Reading generic configuration "%s".' % pfn
140 <                        read_plat(env, args, pfn)
139 >                        print('No platform specific configuration found.\n')
140 >                        print('Reading generic configuration "%s".' % pfn)
141 >                        read_plat(env, pfn)
142                          return 1
143  
144 <        print 'Platform "%s/%s" not supported yet' % (os.name, sys.platform)
144 >        print('Platform "%s", system "%s" not supported yet'
145 >                        % (os.name, sys.platform))
146          sys.exit(2)
147  
148 <        
85 <        
148 > # vi: set ts=4 sw=4 :

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines