Changeset 3544


Ignore:
Timestamp:
Sep 7, 2006, 1:36:10 PM (18 years ago)
Author:
jack
Message:

Make the SCons script build .pyo files in addition to .pyc files.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • SConstruct

    r3523 r3544  
    55# Function to build a .pyc from a .py
    66def build_pyc(target, source, env):
    7     py_compile.compile(str(source[0]), str(target[0]), doraise=True)
     7    python = sys.executable
     8    command = "import py_compile; py_compile.compile('%s', doraise=True)"
     9    if sys.platform == 'win32':
     10        command %= str(source[0]).replace('\\', '\\\\')
     11    else:
     12        command %= str(source[0])
     13    rv = os.system('%s -c "%s"' % (python, command))
     14    if not rv == 0:
     15        raise SyntaxError, "Could not compile %s" % str(source[0])
     16    return None
     17
     18# Function to build a .pyo from a .py
     19def build_pyo(target, source, env):
     20    python = sys.executable
     21    command = "import py_compile; py_compile.compile('%s', doraise=True)"
     22    if sys.platform == 'win32':
     23        command %= str(source[0]).replace('\\', '\\\\')
     24    else:
     25        command %= str(source[0])
     26    options = '-' + 'O' * env['OPTIMISATION_LEVEL']
     27    rv = os.system('%s %s -c "%s"' % (python, options, command))
     28    if not rv == 0:
     29        raise SyntaxError, "Could not compile %s" % str(source[0])
    830    return None
    931
     
    1335opts.Add('MSVCFLAGS', 'Flags passed to the MSVC compiler')
    1436opts.Add('METIS_DIR', 'Location of the metis directory relative to the pymetis directory')
     37opts.Add('OPTIMISATION_LEVEL', 'Optimisation level for the building of .pyo files. Must be 1 or 2')
    1538
    1639# Create the .pyc builder
     
    1841                      suffix = '.pyc',
    1942                      src_suffix = '.py')
     43# Create the .pyo builder
     44pyo_builder = Builder(action = build_pyo,
     45                      suffix = '.pyo',
     46                      src_suffix = '.py')
    2047
    2148env = Environment(options = opts)
    22 env.Append(BUILDERS={'Pyc' : pyc_builder})
     49env.Append(BUILDERS={'Pyc' : pyc_builder,
     50                     'Pyo' : pyo_builder})
    2351
    2452Help(opts.GenerateHelpText(env))
     53
     54if not (env['OPTIMISATION_LEVEL'] == 1 or env['OPTIMISATION_LEVEL'] == 2):
     55    raise ValueError, "OPTIMISATION_LEVEL must be between 1 and 2 inclusive"
    2556
    2657# Find the path for Python.h and then share it to other SConscripts later on
     
    72103for x in files:
    73104    env.Pyc(x + 'c', x)
     105    env.Pyo(x + 'o', x)
    74106
    75107SConscript(['anuga_core/source/anuga/SConscript'])
  • build_options.py

    r3414 r3544  
    99# Location of the metis directory relative to the pymetis directory
    1010METIS_DIR = 'metis-4.0'
     11
     12# Optimisation level used when building the .pyo files
     13OPTIMISATION_LEVEL = 1
Note: See TracChangeset for help on using the changeset viewer.