1 |
< |
from __future__ import print_function |
1 |
> |
from __future__ import division, print_function, unicode_literals |
2 |
|
|
3 |
|
import os |
4 |
|
import sys |
5 |
|
import re |
6 |
|
import platform |
7 |
< |
import ConfigParser |
7 |
> |
try: import configparser # Py3 |
8 |
> |
except ImportError: |
9 |
> |
import ConfigParser as configparser # Py2 |
10 |
|
|
9 |
– |
|
11 |
|
_platdir = 'platform' |
12 |
|
|
13 |
|
|
14 |
< |
def read_plat(env, args, fn): |
14 |
> |
def read_plat(env, fn): |
15 |
|
envdict = env.Dictionary().copy() |
16 |
< |
# can't feed ConfigParser the original dict, because it also |
16 |
> |
# can't feed configparser the original dict, because it also |
17 |
|
# contains non-string values. |
18 |
< |
for k,v in envdict.items(): |
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) |
21 |
> |
cfig = configparser.ConfigParser(envdict) |
22 |
|
cfig.read(fn) |
23 |
|
buildvars = [['CC', |
24 |
|
'TIFFINCLUDE', # where to find preinstalled tifflib headers |
46 |
|
'RAD_PCALLS', # more custom process abstraction |
47 |
|
]], |
48 |
|
] |
49 |
< |
if env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',None): |
49 |
> |
if env.get('RAD_DEBUG',0) not in(0,'0','','n','no','false',False,None): |
50 |
|
vars.insert(0, ['debug'] + buildvars) |
51 |
|
print('Processing DEBUG version') |
52 |
|
else: |
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 |
60 |
< |
if section[0] in ('install','build','debug') and '{' in v: |
61 |
< |
v = subst_osenvvars(v) |
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])) |
65 |
|
for p in section[2]: # multiple items to append |
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 |
< |
apply(env.Append,[],{p:env.Split(v)}) |
73 |
< |
# XXX Check that basedir exists. |
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 |
< |
def subst_osenvvars(s): |
82 |
> |
|
83 |
> |
|
84 |
> |
def subst_sysenvvars(s, env): |
85 |
|
try: return s.format(**os.environ) |
86 |
|
except KeyError: return s |
87 |
|
|
101 |
|
nl.append(ss) |
102 |
|
return ''.join(nl) |
103 |
|
|
104 |
< |
def load_plat(env, args, arch=None): |
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') |
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, args, 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, args, pfn) |
133 |
> |
read_plat(env, pfn) |
134 |
|
return 1 |
135 |
|
|
136 |
|
if os.name == 'posix': |
138 |
|
if os.path.isfile(pfn): |
139 |
|
print('No platform specific configuration found.\n') |
140 |
|
print('Reading generic configuration "%s".' % pfn) |
141 |
< |
read_plat(env, args, pfn) |
141 |
> |
read_plat(env, pfn) |
142 |
|
return 1 |
143 |
|
|
144 |
|
print('Platform "%s", system "%s" not supported yet' |
145 |
|
% (os.name, sys.platform)) |
146 |
|
sys.exit(2) |
147 |
|
|
148 |
< |
|
131 |
< |
|
148 |
> |
# vi: set ts=4 sw=4 : |