Beispiel #1
0
def _customize_doxygen_file(env, subs):
    """Change the $(*) strings to the proper value in the config file.
    Returns True on success"""

    # doxygen wants quotes around paths with spaces
    for k, s in subs.iteritems():
        if re.search(' ', s):
            if not re.search('^".*"$', s):
                mbuild.die(
                    "Doxygen requires quotes around strings with spaces: [%s]->[%s]"
                    % (k, s))
                return False

    # input and output files
    try:
        lines = file(env['doxygen_config']).readlines()
    except:
        mbuild.msgb("Could not open input file: " + env['doxygen_config'])
        return False

    env['doxygen_config_customized'] = \
             env.build_dir_join(os.path.basename(env['doxygen_config']) + '.customized')
    try:
        ofile = open(env['doxygen_config_customized'], 'w')
    except:
        mbuild.msgb("Could not open output file: " +
                    env['doxygen_config_customized'])
        return False

    # compile the patterns
    rsubs = {}
    for k, v in subs.iteritems():
        rsubs[k] = re.compile(r'(?P<tag>[$][(]' + k + '[)])')

    olines = []
    for line in lines:
        oline = line
        for k, p in rsubs.iteritems():
            #print 'searching for', k, 'to replace it with', subs[k]
            m = p.search(oline)
            while m:
                #print 'replacing', k, 'with', subs[k]
                oline = _replace_match(oline, m, subs[k], 'tag')
                m = p.search(oline)
        olines.append(oline)

    try:
        for line in olines:
            ofile.write(line)
    except:
        ofile.close()
        mbuild.msgb("Could not write output file: " +
                    env['doxygen_config_customized'])
        return False

    ofile.close()
    return True
Beispiel #2
0
def _find_doxygen(env):
    """Find the right version of doxygen. Return a tuple of the
    command name and a boolean indicating whether or not the version
    checked out."""

    if env['doxygen_cmd'] == '':
        doxygen_cmd_intel = "/usr/intel/bin/doxygen"
        doxygen_cmd_cygwin = "C:/cygwin/bin/doxygen"
        doxygen_cmd_mac    = \
                    "/Applications/Doxygen.app/Contents/Resources/doxygen"
        doxygen_cmd = "doxygen"

        if env['build_os'] == 'win':
            if os.path.exists(doxygen_cmd_cygwin):
                doxygen_cmd = doxygen_cmd_cygwin
            else:
                mbuild.msgb(
                    'DOXYGEN', "Could not find cygwin's doxygen," +
                    "trying doxygen from PATH")
        elif env['build_os'] == 'lin':
            if mbuild.verbose(1):
                mbuild.msgb("CHECKING FOR", doxygen_cmd_intel)
            if os.path.exists(doxygen_cmd_intel):
                doxygen_cmd = doxygen_cmd_intel
        elif env['build_os'] == 'mac':
            if mbuild.verbose(1):
                mbuild.msgb("CHECKING FOR", doxygen_cmd_mac)
            if os.path.exists(doxygen_cmd_mac):
                doxygen_cmd = doxygen_cmd_mac
    else:
        doxygen_cmd = env['doxygen_cmd']

    doxygen_cmd = env.escape_string(doxygen_cmd)
    doxygen_okay = False
    if mbuild.verbose(1):
        mbuild.msgb('Checking doxygen version', '...')
    if mbuild.check_python_version(2, 4):
        try:
            (retval, output, error_output) = \
                     mbuild.run_command(doxygen_cmd + " --version")
            if retval == 0:
                if len(output) > 0:
                    first_line = output[0].strip()
                    if mbuild.verbose(1):
                        mbuild.msgb("Doxygen version", first_line)
                    doxygen_okay = _doxygen_version_okay(first_line, 1, 4, 6)
            else:
                for o in output:
                    mbuild.msgb("Doxygen-version-check STDOUT", o)
                if error_output:
                    for line in error_output:
                        mbuild.msgb("STDERR ", line.rstrip())
        except:
            mbuild.die("Doxygen required by the command line options " +
                       "but no doxygen found")

    return (doxygen_cmd, doxygen_okay)
Beispiel #3
0
def work(env):
    #with then env, the dag hash file is put in the build_dir.
    dag = mbuild.dag_t('circular-test', env=env)
    work_queue = mbuild.work_queue_t(env['jobs'])

    env.compile_and_link(dag, ['main.c'], 'main' + env['EXEEXT'])

    okay = work_queue.build(dag=dag)
    if not okay:
        mbuild.die("build failed")
    mbuild.msgb("SUCCESS")
Beispiel #4
0
def locate_pin_tree(env):

    if 'pin' not in env:
        find_build_kit_path(env)
        env['pin'] = mbuild.join(env['build_kit_path'], 'pinkit')
    if not env['pin']:
        mbuild.die('Pin directory is not setup ' +
                   'properly in the environment {0}'.format(env['pin']))
    if not os.path.exists(env['pin']):
        mbuild.die('cannot find the PIN directory: {0:s}'.format(env['pin']))
    mbuild.msgb("FOUND PIN KIT", env['pin'])
    env['kit'] = True
Beispiel #5
0
def find_linux_linker(env):
    ld1 = env.expand_string("%(LINK)s")
    ld2 = mbuild.join(env.expand_string("%(toolchain)s"), 'gld')
    ld3 = mbuild.join(env.expand_string("%(toolchain)s"), 'ld')
    ld4 = env.path_search(ld1)
    ld5 = env.path_search('gld')
    ld6 = env.path_search('ld')
    locs = [ld1, ld2, ld3, ld4, ld5, ld6]
    found = find_file(locs)
    if found:
        env['LINK'] = found
    else:
        mbuild.die("Cannot find linker (ld,gld): %s" % ("\n\t".join(locs)))
Beispiel #6
0
def find_linux_archiver(env):
    ar1 = env.expand_string("%(AR)s")
    ar2 = mbuild.join(env.expand_string("%(toolchain)s"), 'gar')
    ar3 = mbuild.join(env.expand_string("%(toolchain)s"), 'ar')
    ar4 = env.path_search(ar1)
    ar5 = env.path_search('gar')
    ar6 = env.path_search('ar')
    locs = [ar1, ar2, ar3, ar4, ar5, ar6]
    found = find_file(locs)
    if found:
        env['AR'] = found
    else:
        mbuild.die("Cannot find archiver (ar,gar): %s" % ("\n\t".join(locs)))
Beispiel #7
0
def find_python(env):
    """return path to NON cygwin"""
    pycmd = sys.executable # use whatever the user invoked us with
    if env.on_windows() and env.on_cygwin():
      # avoid cygwin python
      if pycmd in ['/usr/bin/python', '/bin/python']:
          python_commands = [ 'c:/python27/python.exe',
                              'c:/python26/python.exe',
                              'c:/python25/python.exe' ]
          pycmd  = None
          for p in python_commands:
              if os.path.exists(p):
                  return p
          if not pycmd:
              mbuild.die("Could not find win32 python at these locations: %s" %
                         "\n\t" + "\n\t".join(python_commands))
    
    return pycmd                     
Beispiel #8
0
def _make_doxygen_reference_manual(env,
                                   doxygen_inputs,
                                   subs,
                                   work_queue,
                                   hash_file_name='dox'):
    """Install the doxygen reference manual the doyxgen_output_dir
    directory. doxygen_inputs is a list of files """

    dox_dag = mbuild.dag_t(hash_file_name, env=env)

    # so that the scanner can find them
    dirs = {}
    for f in doxygen_inputs:
        dirs[os.path.dirname(f)] = True
    for d in dirs.iterkeys():
        env.add_include_dir(d)

    # make sure the config and top file are in the inptus list
    doxygen_inputs.append(env['doxygen_config'])
    doxygen_inputs.append(env['doxygen_top_src'])

    dummy = env.build_dir_join('dummy-doxygen-' + hash_file_name)

    # Run it via the builder to make it dependence driven
    run_always = False
    if _empty_dir(env['doxygen_install']):
        run_always = True

    if run_always:
        _build_doxygen_main([subs, dummy], env)
    else:
        c1 = mbuild.plan_t(command=_build_doxygen_main,
                           args=[subs, dummy],
                           env=env,
                           input=doxygen_inputs,
                           output=dummy)
        dox1 = dox_dag.add(env, c1)

        okay = work_queue.build(dag=dox_dag)
        phase = "DOXYGEN"
        if not okay:
            mbuild.die("[%s] failed. dying..." % phase)
        if mbuild.verbose(1):
            mbuild.msgb(phase, "build succeeded")
Beispiel #9
0
def _build_doxygen_main(args, env):
    """Customize the doxygen input file. Run the doxygen command, copy
    in any images, and put the output in the right place."""

    if type(args) is types.ListType:
        if len(args) < 2:
            mbuild.die(
                "Need subs dictionary and  dummy file arg for the doxygen command "
                + "to indicate its processing")
    else:
        mbuild.die("Need a list for _build_doxygen_main with the subs " +
                   "dictionary and the dummy file name")

    (subs, dummy_file) = args

    (doxygen_cmd, doxygen_okay) = _find_doxygen(env)
    if not doxygen_okay:
        msg = 'No good doxygen available on this system; ' + \
              'Your command line arguments\n\trequire it to be present. ' + \
              'Consider dropping the "doc" and "doc-build" options\n\t or ' + \
              'specify a path to doxygen with the --doxygen knob.\n\n\n'
        return (1, [msg])  # failure
    else:
        env['DOXYGEN'] = doxygen_cmd

    try:
        okay = _customize_doxygen_file(env, subs)
    except:
        mbuild.die("CUSTOMIZE DOXYGEN INPUT FILE FAILED")
    if not okay:
        return (1, ['Doxygen customization failed'])

    cmd   = env['DOXYGEN'] + ' ' + \
            env.escape_string(env['doxygen_config_customized'])
    if mbuild.verbose(1):
        mbuild.msgb("RUN DOXYGEN", cmd)
    (retval, output, error_output) = mbuild.run_command(cmd)

    for line in output:
        mbuild.msgb("DOX", line.rstrip())
    if error_output:
        for line in error_output:
            mbuild.msgb("DOX-ERROR", line.rstrip())
    if retval != 0:
        mbuild.msgb("DOXYGEN FAILED")
        mbuild.die("Doxygen run failed. Retval=", str(retval))
    mbuild.touch(dummy_file)
    mbuild.msgb("DOXYGEN", "succeeded")
    return (0, [])  # success
Beispiel #10
0
def find_build_kit_path(env):
    if 'build_kit_path' not in env:
        try:
            env['build_kit_path'] = os.getenv("SDE_BUILD_KIT")
            mbuild.msgb("SDE_BUILD_KIT env var", env['build_kit_path'])
        except:
            mbuild.die("Could not find SDE_BUILD_KIT in the shell environment")

    if not env['build_kit_path']:
        mbuild.die("Could not find build_kit_path is not set properly")

    if os.path.exists(env['build_kit_path']):
        return
    mbuild.die("Could not find build kit at {0:s}".format(
        env['build_kit_path']))
Beispiel #11
0
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
#END_LEGAL

import os, sys

sys.path = ['..'] + sys.path
import mbuild

env = mbuild.env_t()
env.parse_args()

env['jobs'] = 1
work_queue = mbuild.work_queue_t(env['jobs'])
all_cmds = ['python -c "1+1"']
subs = {}
command_list = []
for cmd in all_cmds:
    cmd = cmd % (subs)
    mbuild.msgb('ADDING', cmd)
    c = mbuild.command_t(cmd, output_file_name="foo")
    work_queue.add(c)
    command_list.append(cmd)

phase = "BUILD"
okay = work_queue.build()
if not okay:
    mbuild.die("[%s] failed. dying..." % phase)
mbuild.msgb(phase, "succeeded")
Beispiel #12
0
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  
#END_LEGAL

import sys
import os
import find
import mbuild

env = mbuild.env_t()
env.parse_args()

os.environ['LANG']='en_US.UTF-8'
mbuild.cmkdir(env['build_dir'])
dep_tracker = mbuild.dag_t()
cmd1 = dep_tracker.add(env, env.cc_compile('foo.c'))
work_queue = mbuild.work_queue_t()
okay = work_queue.build(dag=dep_tracker)
if not okay:
    mbuild.die("build failed")
mbuild.msgb("SUCCESS")
Beispiel #13
0
def foo():
    mbuild.die("dying...")
Beispiel #14
0
def foo():
    try:
        x = 1 / 0
    except:
        mbuild.die("dying...")
Beispiel #15
0
def init_gnu_env_compile(env):

    if env['toolchain'] == '':
        # find a reasonable toolchain if none is set
        if not env['gcc_version']:
            # First try local gcc
            if not setup_local_gcc(env):
                # Then try intel packages
                find_gcc_usr_intel(env)
                p = env.expand('/usr/intel/pkgs/gcc/%(gcc_version)s/bin')
                if os.path.exists(p):
                    env['toolchain'] = p + '/'
                else:  # search the path
                    gccname = env.expand('%(CC_COMPILER)s')
                    env['toolchain'] = find_path(gccname) + '/'
                    env['gcc_version'] = mbuild.compute_gcc_version(
                        env['toolchain'] + gccname)

    mbuild.msgb("TOOLCHAIN", env['toolchain'])
    if env['toolchain'] == '':
        mbuild.die("must set toolchain= on the command line")
    if not os.path.exists(env['toolchain']):
        mbuild.die("toolchain not found: %s" % (env['toolchain']))

    flags = ''
    if not env['gcc_version']:
        env['gcc_version'] = mbuild.compute_gcc_version(env['toolchain'] +
                                                        env['CC_COMPILER'])

    flags += ' -fomit-frame-pointer'
    flags += ' -Wall'
    flags += ' -Werror'
    flags += ' -Wno-unknown-pragmas'
    flags += ' -fno-strict-aliasing'
    flags += ' -Wno-long-long'  # from libs
    flags += ' -Wno-unused-function'
    flags += ' -pipe -fmessage-length=0'
    flags += ' -fno-exceptions'  # from libs
    flags += ' -fno-stack-protector'
    flags += ' -Wno-missing-braces '
    flags += ' -Wuninitialized -Winit-self -Wmissing-field-initializers '

    flags += ' -Wformat -Wformat-security'  # printf static checks

    # use for C++ only flags
    major_gcc_ver = int(env['gcc_version'].split('.')[0])
    cxxflags = ''
    if env.on_linux() and major_gcc_ver >= 7:
        cxxflags += ' -faligned-new '

    if env.on_linux():
        flags += ' -fstack-clash-protection '
        flags += ' -fabi-version=2 '

    # Modify maximal alignment in SDE on MAC to 8
    # This is done as a workaround for a bug in PIN code.
    if env.on_mac() and env['host_cpu'] == 'ia32':
        flags += ' -fmax-type-align=8'

    # MAC darwin flags
    if env.on_mac():
        flags += ' -D__DARWIN_ONLY_UNIX_CONFORMANCE=1 -D__DARWIN_UNIX03=0 '

    # PIN CRT flags
    if not env['standalone_program']:
        flags += ' -funwind-tables'

    if env.on_linux() or env.on_mac():
        find_linux_archiver(env)
        find_linux_linker(env)

    if env.on_linux():
        if not env['standalone_program']:
            if env['host_cpu'] == 'x86-64':
                env['fpic'] = '-fPIC'
                flags += ' %(fpic)s '

    if env['host_cpu'] == 'ia32':
        if env.on_cygwin():
            flags += ' -mno-cygwin'

    # required for gcc cmpxchg16b intrinsics on 64b systems
    if env.on_linux() and env['host_cpu'] == 'x86-64':
        flags += ' -mcx16'

    if env['avx']:
        flags += ' -march=corei7-avx -mavx '
    else:
        # enable sse2/3 on lin32 and lin64
        flags += ' -msse3 '
        if not env.on_mac():
            # clang does not support -mfpath=sse
            flags += ' -mfpmath=sse '

    env['CXXFLAGS'] += flags + cxxflags
    env['CCFLAGS'] += flags
    if not env['standalone_program']:
        env['CXXFLAGS'] += ' -fno-rtti -Wno-error=shadow -Wno-shadow'

    if not env['standalone_program']:
        init_pin_crt_compile(env)
Beispiel #16
0
sys.path = [find_dir('mbuild')] + sys.path

def dirname_n(s,n):
    t = s
    for i in range(0,n):
        t = os.path.dirname(t)
    return t

import mbuild
start_time=mbuild.get_time()

env = mbuild.env_t()
env.parse_args()
work_queue = mbuild.work_queue_t(env['jobs'])


cmds= ['obj/xed -64 -i /bin/ls > ls.out',
       'obj/xed -n 10m -v 0 -64 -i /usr/X11R6/bin/Xvnc ' ]
for cmd in cmds:
    c = mbuild.command_t(cmd)
    work_queue.add(c)

phase = "XED2-TESTS"
okay = work_queue.build()
if not okay:
    mbuild.die("[%s]  failed" % (phase))
mbuild.msgb(phase, "succeeded")

end_time=mbuild.get_time()
mbuild.msgb("ELAPSED TIME", mbuild.get_elapsed_time(start_time,end_time))
Beispiel #17
0
def init_gnu_env_link_tool(env):
    lflags = ''
    libs = ''
    if env.on_linux():
        if 'static_pin' in env and env['static_pin']:
            libs += ' -lsapin'
        else:
            libs += ' -lpin'
    if env.on_mac():
        libs += ' -lpin'

    # PIN CRT linker flags
    libs += ' -nostdlib -lc-dynamic -lm-dynamic -lstlport-dynamic '
    libs += ' -lunwind-dynamic '

    if env['xedshared']:
        if env['build_os'] == 'win':
            libs += ' %(xed_lib_dir)s/xed%(DLLEXT)s'
        else:
            libs += ' %(xed_lib_dir)s/libxed%(DLLEXT)s'
    else:
        libs += ' -lxed'

    if env['build_os'] == 'mac':
        env['sotool_linker_script'] = '%(pin)s/source/include/pin/pintool.exp'
        sotool_lflags = ' -Wl,-exported_symbols_list'
        sotool_lflags += ' -Wl,%(sotool_linker_script)s'

        env['sotool_lflags'] = sotool_lflags
        lflags += ' %(sotool_lflags)s '

    if env.on_linux():
        libs += ' -lpin3dwarf'

        # make the pin tools shared objects on linux
        sotool_lflags = ''

        # omitting -shared because linker adds it
        sotool_lflags += ' -Wl,-Bsymbolic'

        # this will result in minimal exported symbols (in stripped binaries)
        # /pin/ required for pin >= r56431.
        env['sotool_linker_script'] = '%(pin)s/source/include/pin/pintool.ver'
        sotool_lflags += ' -Wl,--version-script=%(sotool_linker_script)s'

        env['sotool_lflags'] = sotool_lflags
        lflags += ' %(sotool_lflags)s   -Wl,--no-undefined'

        # security related settings
        lflags += ' -z noexecstack'
        lflags += ' -z relro'

    if env['host_os'] in ['lin']:
        if not env['standalone_program']:
            libs += ' -ldl-dynamic'

    if env['host_cpu'] == 'ia32':

        if env.on_cygwin():
            lflags += ' -mno-cygwin'

        if env['build_os'] == 'win':
            libs += ' -lpinvm -lntdll'
            lflags += ' -Wl,--export-all-symbols'
            lflags += ' -shared'
            lflags += ' -Wl,-wrap,atexit,' +  \
                           '-wrap,_onexit,-e,_True_DllMainCRTStartup@12'
            lflags += ' -Wl,--image-base -Wl,0x55000000'
        elif env['host_os'] in ['lin']:
            pass
        elif env['build_os'] == 'mac':
            lflags += ' -w -Wl,-multiply_defined -Wl,suppress'
        else:
            mbuild.die("Unhandled ia32 os: build_os: " + env['build_os'] +
                       ' / host_os: ' + env['host_os'])

    # Enable old linker on Mac and add lpin3dwarf
    if env.on_mac():
        libs += ' -Wl,-no_new_main'
        libs += ' -lpin3dwarf'

    env['LINKFLAGS'] += lflags
    env['LIBS'] += libs