Subversion Repositories HelenOS-historic

Rev

Rev 567 | Rev 573 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 567 Rev 568
Line 228... Line 228...
228
        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
228
        res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
229
        if res:
229
        if res:
230
            defaults[res.group(1)] = res.group(2)
230
            defaults[res.group(1)] = res.group(2)
231
    f.close()
231
    f.close()
232
 
232
 
233
def check_condition(text, defaults):
233
def check_condition(text, defaults, asked_names):
-
 
234
    seen_vars = [ x[0] for x in asked_names ]
234
    result = True
235
    ctype = 'cnf'
-
 
236
    if ')|' in text or '|(' in text:
-
 
237
        ctype = 'dnf'
-
 
238
   
-
 
239
    if ctype == 'cnf':
235
    conds = text.split('&')
240
        conds = text.split('&')
-
 
241
    else:
-
 
242
        conds = text.split('|')
-
 
243
 
236
    for cond in conds:
244
    for cond in conds:
237
        if cond.startswith('(') and cond.endswith(')'):
245
        if cond.startswith('(') and cond.endswith(')'):
238
            cond = cond[1:-1]
246
            cond = cond[1:-1]
-
 
247
           
239
        if not check_dnf(cond, defaults):
248
        inside = check_inside(cond, defaults, ctype, seen_vars)
-
 
249
       
-
 
250
        if ctype == 'cnf' and not inside:
240
            return False
251
            return False
-
 
252
        if ctype == 'dnf' and inside:
241
    return True
253
            return True
242
 
254
 
-
 
255
    if ctype == 'cnf':
-
 
256
        return True
-
 
257
    return False
-
 
258
 
243
def check_dnf(text, defaults):
259
def check_inside(text, defaults, ctype, seen_vars):
244
    """
260
    """
245
    Check that the condition specified on input line is True
261
    Check that the condition specified on input line is True
246
 
262
 
247
    only CNF is supported
263
    only CNF is supported
248
    """
264
    """
-
 
265
    if ctype == 'cnf':
249
    conds = text.split('|')
266
        conds = text.split('|')
-
 
267
    else:
-
 
268
        conds = text.split('&')
250
    for cond in conds:
269
    for cond in conds:
251
        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
270
        res = re.match(r'^(.*?)(!?=)(.*)$', cond)
252
        if not res:
271
        if not res:
253
            raise RuntimeError("Invalid condition: %s" % cond)
272
            raise RuntimeError("Invalid condition: %s" % cond)
254
        condname = res.group(1)
273
        condname = res.group(1)
255
        oper = res.group(2)
274
        oper = res.group(2)
256
        condval = res.group(3)
275
        condval = res.group(3)
-
 
276
        if condname not in seen_vars:
-
 
277
            raise RuntimeError("Variable %s not defined before being asked." %\
-
 
278
                               condname)
257
        if not defaults.has_key(condname):
279
        if not defaults.has_key(condname):
258
            raise RuntimeError("Condition var %s does not exist: %s" % \
280
            raise RuntimeError("Condition var %s does not exist: %s" % \
259
                               (condname,text))
281
                               (condname,text))
260
 
282
 
-
 
283
        if ctype == 'cnf':
261
        if oper=='=' and  condval == defaults[condname]:
284
            if oper == '=' and  condval == defaults[condname]:
262
            return True
285
                return True
263
        if oper == '!=' and condval != defaults[condname]:
286
            if oper == '!=' and condval != defaults[condname]:
264
            return True
287
                return True
-
 
288
        else:
-
 
289
            if oper== '=' and condval != defaults[condname]:
-
 
290
                return False
-
 
291
            if oper== '!=' and condval == defaults[condname]:
-
 
292
                print 2
-
 
293
                return False
-
 
294
    if ctype=='cnf':
265
    return False
295
        return False
-
 
296
    return True
266
 
297
 
267
def parse_config(input, output, dlg, defaults={}, askonly=None):
298
def parse_config(input, output, dlg, defaults={}, askonly=None):
268
    "Parse configuration file and create Makefile.config on the fly"
299
    "Parse configuration file and create Makefile.config on the fly"
269
    def ask_the_question(dialog):
300
    def ask_the_question(dialog):
270
        "Ask question based on the type of variables to ask"
301
        "Ask question based on the type of variables to ask"
Line 302... Line 333...
302
        if line.startswith('%'):
333
        if line.startswith('%'):
303
            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
334
            res = re.match(r'^%\s*(?:\[(.*?)\])?\s*(.*)$', line)
304
            if not res:
335
            if not res:
305
                raise RuntimeError('Invalid command: %s' % line)
336
                raise RuntimeError('Invalid command: %s' % line)
306
            if res.group(1):
337
            if res.group(1):
307
                if not check_condition(res.group(1), defaults):
338
                if not check_condition(res.group(1), defaults,
-
 
339
                                       asked_names):
308
                    continue
340
                    continue
309
            args = res.group(2).strip().split(' ')
341
            args = res.group(2).strip().split(' ')
310
            cmd = args[0].lower()
342
            cmd = args[0].lower()
311
            args = args[1:]
343
            args = args[1:]
312
            if cmd == 'saveas':
344
            if cmd == 'saveas':
Line 332... Line 364...
332
            vartype = res.group(3)
364
            vartype = res.group(3)
333
 
365
 
334
            default = defaults.get(varname,None)
366
            default = defaults.get(varname,None)
335
           
367
           
336
            if res.group(1):
368
            if res.group(1):
337
                if not check_condition(res.group(1), defaults):
369
                if not check_condition(res.group(1), defaults,
-
 
370
                                       asked_names):
338
                    if default is not None:
371
                    if default is not None:
339
                        outf.write('#!# %s = %s\n' % (varname, default))
372
                        outf.write('#!# %s = %s\n' % (varname, default))
340
                    # Clear cumulated values
373
                    # Clear cumulated values
341
                    comment = ''
374
                    comment = ''
342
                    default = None
375
                    default = None
Line 363... Line 396...
363
            # Add new line into the 'choice array' 
396
            # Add new line into the 'choice array' 
364
            res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
397
            res = re.match(r'@\s*(?:\[(.*?)\])?\s*"(.*?)"\s*(.*)$', line)
365
            if not res:
398
            if not res:
366
                raise RuntimeError("Bad line: %s" % line)
399
                raise RuntimeError("Bad line: %s" % line)
367
            if res.group(1):
400
            if res.group(1):
368
                if not check_condition(res.group(1),defaults):
401
                if not check_condition(res.group(1),defaults,
-
 
402
                                       asked_names):
369
                    continue
403
                    continue
370
            choices.append((res.group(2), res.group(3)))
404
            choices.append((res.group(2), res.group(3)))
371
            continue
405
            continue
372
 
406
 
373
        # All other things print to output file
407
        # All other things print to output file
Line 431... Line 465...
431
    if os.path.exists(OUTPUT):
465
    if os.path.exists(OUTPUT):
432
        os.unlink(OUTPUT)
466
        os.unlink(OUTPUT)
433
    os.rename(TMPOUTPUT, OUTPUT)
467
    os.rename(TMPOUTPUT, OUTPUT)
434
   
468
   
435
    if not defmode and dlg.yesno('Rebuild kernel?') == 'y':
469
    if not defmode and dlg.yesno('Rebuild kernel?') == 'y':
436
        os.execlp('make','make','clean','all')
470
        os.execlp('make','make','clean','build')
437
 
471
 
438
if __name__ == '__main__':
472
if __name__ == '__main__':
439
    main()
473
    main()