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.15 by schorsch, Thu Mar 10 01:49:56 2016 UTC vs.
Revision 1.16 by schorsch, Thu Mar 10 17:36:18 2016 UTC

# Line 1 | Line 1
1 + from __future__ import print_function
2  
3   import os
4   import sys
5 + import re
6   import platform
7   import ConfigParser
8  
# Line 43 | Line 45 | def read_plat(env, args, fn):
45                          'RAD_PCALLS',     # more custom process abstraction
46                          ]],
47          ]
48 <        if args.get('RAD_DEBUG',0):
48 >        if env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',None):
49                  vars.insert(0, ['debug'] + buildvars)
50 <        else: vars.insert(0, ['build'] + buildvars)
50 >                print('Processing DEBUG version')
51 >        else:
52 >                vars.insert(0, ['build'] + buildvars)
53 >                print('Processing RELEASE version')
54          for section in vars:
55                  if cfig.has_section(section[0]):
56                          for p in section[1]: # single items to replace
57                                  try: v = cfig.get(section[0], p)
58                                  except ConfigParser.NoOptionError: continue
59 <                                if section[0] == 'install' and '{' in v:
60 <                                        try:
56 <                                                vv = v.format(**os.environ)
57 <                                        except KeyError: vv = v
58 <                                        else: v = vv
59 >                                if section[0] in ('install','build','debug') and '{' in v:
60 >                                        v = subst_osenvvars(v)
61                                  env[p] = v
62                                  #print('%s: %s' % (p, env[p]))
63                          for p in section[2]: # multiple items to append
64 <                                try: v = cfig.get(section[0], p)
64 >                                try:
65 >                                        v = cfig.get(section[0], p)
66 >                                        if section[0] in ('build','debug') and '{' in v:
67 >                                                v = subst_sconsvars(v, env)
68 >                                        #print('%s: %s - %s' % (section[0], p, v))
69                                  except ConfigParser.NoOptionError: continue
70                                  apply(env.Append,[],{p:env.Split(v)})
71          # XXX Check that basedir exists.
# Line 68 | Line 74 | def read_plat(env, args, fn):
74                                  and not os.path.isabs(env[k])):
75                          env[k] = os.path.join(env['RAD_BASEDIR'],env[k])
76  
77 + def subst_osenvvars(s):
78 +        try: return s.format(**os.environ)
79 +        except KeyError: return s
80  
81 + def subst_sconsvars(s, env,
82 +                pat=re.compile('({[a-z0-9_]+})', re.I)):
83 +        l = pat.split(s)
84 +        nl = []
85 +        for ss in l:
86 +                if ss.startswith('{') and ss.endswith('}'):
87 +                        v = env.get(ss[1:-1])
88 +                        #print(ss, v)
89 +                        if v:
90 +                                if v.startswith('#'):
91 +                                        v = str(env.Dir(v))
92 +                                nl.append(v)
93 +                                continue
94 +                nl.append(ss)
95 +        return ''.join(nl)
96 +
97   def load_plat(env, args, arch=None):
73        cfgname = 'posix'
98          memmodel, binformat = platform.architecture()
99          platsys = platform.system()
100 <        print 'Detected platform "%s" (%s).' % (platsys, memmodel)
100 >        print('Detected platform "%s" (%s).' % (platsys, memmodel))
101          cfgname = platsys + '_' + memmodel[:2]
102 +
103          env['RAD_BUILDBIN'] = os.path.join('#scbuild', cfgname, 'bin')
104          env['RAD_BUILDLIB']  = os.path.join('#scbuild', cfgname, 'lib')
105          env['RAD_BUILDOBJ']  = os.path.join('#scbuild', cfgname, 'obj')
106  
107 <        pfn = os.path.join(_platdir, cfgname + '_custom.cfg')
108 <        if os.path.isfile(pfn):
109 <                print 'Reading configuration "%s"' % pfn
110 <                read_plat(env, args, pfn)
107 >        cust_pfn = os.path.join(_platdir, cfgname + '_custom.cfg')
108 >        if os.path.isfile(cust_pfn):
109 >                print('Reading configuration "%s"' % cust_pfn)
110 >                read_plat(env, args, cust_pfn)
111                  return 1
112          pfn = os.path.join(_platdir, cfgname + '.cfg')
113          if os.path.isfile(pfn):
114 <                print 'Reading configuration "%s"' % pfn
114 >                print('Reading configuration "%s"' % pfn)
115                  read_plat(env, args, pfn)
116                  return 1
117  
118          if os.name == 'posix':
119                  pfn = os.path.join(_platdir, 'posix.cfg')
120                  if os.path.isfile(pfn):
121 <                        print 'Reading generic configuration "%s".' % pfn
121 >                        print('No platform specific configuration found.\n')
122 >                        print('Reading generic configuration "%s".' % pfn)
123                          read_plat(env, args, pfn)
124                          return 1
125  
126 <        print 'Platform "%s", system "%s" not supported yet' % (os.name, sys.platform)
126 >        print('Platform "%s", system "%s" not supported yet'
127 >                        % (os.name, sys.platform))
128          sys.exit(2)
129  
130          

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines