Example #1
0
def create_reference(env, test_dir, codes_and_cmd, make_new=True):
    mbuild.cmkdir(test_dir)

    if make_new:
        codes, cmd = codes_and_cmd.split(';')
        cmd_fn = os.path.join(test_dir, "cmd")
        write_file(cmd_fn, cmd + '\n')
        codes_fn = os.path.join(test_dir, "codes")
        write_file(codes_fn, codes + '\n')
    else:
        cmd = codes_and_cmd

    # abspath required for windoze
    build_dir = mbuild.posix_slashes(os.path.abspath(env['build_dir']))
    cmd2 = re.sub('BUILDDIR', build_dir, cmd)
    print(cmd2)

    (retcode, stdout, stderr) = mbuild.run_command(cmd2, separate_stderr=True)
    print("Retcode %s" % (str(retcode)))
    if stdout:
        for line in stdout:
            print("[STDOUT] %s" % (line))
    if stderr:
        for line in stderr:
            print("[STDERR] %s" % (line))

    write_file(os.path.join(test_dir, "retcode.reference"),
               [str(retcode) + "\n"])
    write_file(os.path.join(test_dir, "stdout.reference"), stdout)
    write_file(os.path.join(test_dir, "stderr.reference"), stderr)
Example #2
0
def examples_work(env):
    """External entry point for non-command line invocations.
    Initialize the environment, build libxed, the examples, the kit
    and run the tests"""
    xbc.prep(env)
    verify_args(env)
    start_time = mbuild.get_time()
    xbc.init_once(env)

    init(env)

    if 'clean' in env['targets'] or env['clean']:
        xbc.xed_remove_files_glob(env)
        if len(env['targets']) <= 1:
            xbc.cexit(0)

    mbuild.cmkdir(env['build_dir'])

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

    xbc.get_libxed_names(env, work_queue)
    retval = build_examples(env, work_queue)
    end_time = mbuild.get_time()
    mbuild.msgb("EXAMPLES BUILD ELAPSED TIME",
                mbuild.get_elapsed_time(start_time, end_time))
    return retval
Example #3
0
def setup():
    env = mbuild.env_t()
    env.parse_args()
    mbuild.cmkdir(env['build_dir'])
    if not env.on_windows():
        env['LINK'] = env['CC']  # not g++ for this program
    return env
Example #4
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")
Example #5
0
def build_examples(env, work_queue):
    """Build the examples"""
    example_exes = []
    env['example_exes'] = []  # used by install
    examples_dag = mbuild.dag_t('xedexamples', env=env)

    if not env.on_windows():
        for d in env['example_rpaths']:
            env.add_to_var('example_linkflags', '-Wl,-rpath,{}'.format(d))
    env.add_to_var('LINKFLAGS', env['example_linkflags'])
    # put the examples in their own subdirectory
    env['build_dir'] = mbuild.join(env['build_dir'], 'examples')
    mbuild.cmkdir(env['build_dir'])

    link_libxed = env['link_libxed']

    if env['shared']:
        _add_libxed_rpath(env)

    # C vs C++: env is for C++ and env_c is for C programs.
    if env['compiler'] in ['gnu', 'clang', 'icc']:
        env['LINK'] = env['CXX']
    env_c = copy.deepcopy(env)
    if env_c['compiler'] in ['gnu', 'clang']:
        env_c['LINK'] = '%(CC)s'

    if env['pin_crt']:
        xbc.compile_with_pin_crt_lin_mac_common_cplusplus(env)

    # shared files
    cc_shared_files = env.src_dir_join(['xed-examples-util.c'])
    if env['decoder']:
        cc_shared_files.extend(
            env.src_dir_join(['xed-dot.c', 'xed-dot-prep.c']))

    if env['encoder']:
        cc_shared_files += env.src_dir_join(['xed-enc-lang.c'])
    cc_shared_objs = env.compile(examples_dag, cc_shared_files)
    # the XED command line tool
    xed_cmdline_files = [
        'xed-disas-raw.c', 'avltree.c', 'xed-disas-hex.c', 'xed-symbol-table.c'
    ]
    if env.on_windows() and env['set_copyright']:
        xed_cmdline_files.append("xed.rc")
    extra_libs = []
    if env['decoder']:

        if env.on_linux() or env.on_freebsd() or env.on_netbsd():
            xed_cmdline_files.append('xed-disas-elf.c')

        elif env.on_mac():
            xed_cmdline_files.append('xed-disas-macho.c')

        elif env.on_windows():
            xed_cmdline_files.append('xed-disas-pecoff.cpp')
            if (env['dbghelp'] and env['msvs_version'] not in ['6', '7']):
                env.add_define("XED_DBGHELP")
                xed_cmdline_files.append('udhelp.cpp')
                extra_libs = ['dbghelp.lib', 'version.lib']

    xed_cmdline_files = env.src_dir_join(xed_cmdline_files)
    xed_cmdline_obj = copy.deepcopy(cc_shared_objs)

    # Env for cmdline tool (with libelf/dwarf on linux.)
    if env.on_windows():  # still C++
        cenv = copy.deepcopy(env)
    else:  # lin/mac are C code only.
        cenv = copy.deepcopy(env_c)

    if env.on_linux():
        xbc.cond_add_elf_dwarf(cenv)

    xed_cmdline_obj += cenv.compile(examples_dag, xed_cmdline_files)

    xed_cmdline = ex_compile_and_link(
        cenv, examples_dag, env.src_dir_join('xed.c'),
        xed_cmdline_obj + [link_libxed] + extra_libs)
    mbuild.msgb("CMDLINE", xed_cmdline)
    example_exes.append(xed_cmdline)

    ild_examples = []
    other_c_examples = []
    small_examples = ['xed-size.c']
    if env['encoder']:
        small_examples += ['xed-ex5-enc.c']
        other_c_examples += ['xed-ex3.c']
    if env['decoder'] and env['encoder']:
        other_c_examples += ['xed-ex6.c']
    if env['decoder']:
        ild_examples += ['xed-ex-ild.c']
        other_c_examples += [
            'xed-ex1.c', 'xed-ex-ild2.c', 'xed-min.c', 'xed-reps.c',
            'xed-ex4.c', 'xed-tester.c', 'xed-dec-print.c', 'xed-ex-agen.c',
            'xed-ex7.c', 'xed-ex8.c', 'xed-ex-cpuid.c', 'xed-tables.c',
            'xed-dll-discovery.c'
        ]

    # compile & link other_c_examples
    for example in env.src_dir_join(other_c_examples):
        example_exes.append(
            ex_compile_and_link(env_c, examples_dag, example,
                                cc_shared_objs + [link_libxed]))
    # compile & link ild_examples
    for example in env.src_dir_join(ild_examples):
        example_exes.append(
            ex_compile_and_link(env_c, examples_dag, example,
                                [env['link_libild']]))

    # compile & link small_examples
    for example in env.src_dir_join(small_examples):
        example_exes.append(
            ex_compile_and_link(env_c, examples_dag, example, [link_libxed]))
    if mbuild.verbose(3):
        mbuild.msgb("ALL EXAMPLES", "\n\t".join(example_exes))

    examples_to_build = example_exes
    env['example_exes'] = example_exes

    mbuild.msgb("BUILDING EXAMPLES")
    okay = work_queue.build(examples_dag,
                            targets=examples_to_build,
                            die_on_errors=env['die_on_errors'],
                            show_progress=True,
                            show_output=True,
                            show_errors_only=_wk_show_errors_only())
    if not okay:
        xbc.cdie("XED EXAMPLES build failed")
    if mbuild.verbose(2):
        mbuild.msgb("XED EXAMPLES", "build succeeded")
    return 0
Example #6
0
def build_examples(env, work_queue):
    """Build the examples"""
    example_exes = [] 
    env['example_exes'] = []  # used by install
    examples_dag = mbuild.dag_t('xedexamples', env=env)
    
    if not env.on_windows():
        for d in env['example_rpaths']:
            env.add_to_var('example_linkflags',
                                   '-Wl,-rpath,{}'.format(d))
    env.add_to_var('LINKFLAGS', env['example_linkflags'])
    env.add_to_var('CCFLAGS', env['example_flags'])
    env.add_to_var('CXXFLAGS', env['example_flags'])
    mbuild.cmkdir(env['build_dir'])

    link_libxed = env['link_libxed']
    
    if env['shared']:
       _add_libxed_rpath(env)

    # C vs C++: env is for C++ and env_c is for C programs.
    if env['compiler'] in  ['gnu','clang', 'icc']:
        env['LINK'] = env['CXX']
    env_c = copy.deepcopy(env)
    if env_c['compiler'] in ['gnu','clang']:
        env_c['LINK'] = '%(CC)s'
        
    if env['pin_crt']:
        xbc.compile_with_pin_crt_lin_mac_common_cplusplus(env)
    
    # shared files
    cc_shared_files = env.src_dir_join([ 
          'xed-examples-util.c'])
    if env['decoder']:
        cc_shared_files.extend(env.src_dir_join([ 
          'xed-dot.c',
          'xed-dot-prep.c']))
        
    if env['encoder']:
       cc_shared_files += env.src_dir_join([ 'xed-enc-lang.c'])
    cc_shared_objs  = env.compile( examples_dag, cc_shared_files)
    # the XED command line tool
    xed_cmdline_files = [ 'xed-disas-raw.c',
                          'avltree.c',
                          'xed-disas-hex.c',
                          'xed-symbol-table.c']
    if env.on_windows() and env['set_copyright']:
        # AUTOMATICALLY UPDATE YEAR IN THE RC FILE
        year = time.strftime("%Y")
        lines = open(env.src_dir_join('xed-rc-template.txt')).readlines()
        lines = [ re.sub('%%YEAR%%',year,x) for x in lines ]
        xbc.write_file(env.src_dir_join('xed.rc'), lines)
        xed_cmdline_files.append("xed.rc")
        
    extra_libs = []    
    if env['decoder']:

        if env.on_linux() or env.on_freebsd() or env.on_netbsd():
            xed_cmdline_files.append('xed-disas-filter.c')
            xed_cmdline_files.append('xed-nm-symtab.c')
            
        elif env.on_mac():
            xed_cmdline_files.append('xed-disas-macho.c')

        elif env.on_windows():
            xed_cmdline_files.append('xed-disas-pecoff.cpp')
            if ( env['dbghelp'] and 
                 env['msvs_version'] not in ['6','7'] ):
                env.add_define("XED_DBGHELP")
                xed_cmdline_files.append('udhelp.cpp')
                extra_libs = ['dbghelp.lib', 'version.lib' ]

    xed_cmdline_files = env.src_dir_join(xed_cmdline_files)
    xed_cmdline_obj = copy.deepcopy(cc_shared_objs)

    # Env for cmdline tool (with libelf/dwarf on linux.)
    if env.on_windows():  # still C++
        cenv = copy.deepcopy(env)
    else: # lin/mac are C code only.
        cenv = copy.deepcopy(env_c)
        
    if env.on_linux():
        xbc.cond_add_elf_dwarf(cenv)
        
    if env.on_linux() or env.on_freebsd() or env.on_netbsd():
        src_elf = env.src_dir_join('xed-disas-elf.c')
        if env['use_elf_dwarf_precompiled']:
            cenv2 = copy.deepcopy(cenv)
            # need to remove -pedantic because of redundant typedef Elf in dwarf header file
            cenv2.remove_from_var('CCFLAGS','-pedantic')
            xed_cmdline_obj += cenv2.compile(examples_dag, [src_elf])
        else:
            xed_cmdline_files.append(src_elf)
            
    xed_cmdline_obj += cenv.compile(examples_dag, xed_cmdline_files)
    xed_cmdline = ex_compile_and_link(cenv, examples_dag,
                                      env.src_dir_join('xed.c'),
                                      xed_cmdline_obj + [link_libxed] +
                                      extra_libs)

    mbuild.msgb("CMDLINE", xed_cmdline)
    example_exes.append(xed_cmdline)

    if env['encoder']:
        exe = build_asmparse(cenv, examples_dag, cc_shared_objs)
        example_exes.append(exe)
        

    ild_examples = []
    other_c_examples = []
    enc2_examples = []
    small_examples = ['xed-size.c']
    if env['enc2']:
        enc2_examples += [ 'xed-enc2-1.c',
                           'xed-enc2-2.c',
                           'xed-enc2-3.c' ]
    if env['encoder']:
       small_examples += ['xed-ex5-enc.c']
       other_c_examples += ['xed-ex3.c']
    if env['decoder'] and env['encoder']:
       other_c_examples += ['xed-ex6.c',
                            'xed-ex9-patch.c' ]
    if env['decoder']:
       ild_examples += [ 'xed-ex-ild.c' ]
       other_c_examples += ['xed-ex1.c',
                            'xed-ex-ild2.c',
                            'xed-min.c',
                            'xed-reps.c',
                            'xed-ex4.c',
                            'xed-tester.c',
                            'xed-dec-print.c',           
                            'xed-ex-agen.c',
                            'xed-ex7.c',
                            'xed-ex8.c',
                            'xed-ex-cpuid.c',
                            'xed-tables.c',
                            'xed-find-special.c',                            
                            'xed-dll-discovery.c']

    # compile & link other_c_examples
    for example in env.src_dir_join(other_c_examples):
        example_exes.append(ex_compile_and_link(env_c,
                                                examples_dag,
                                                example,
                                                cc_shared_objs + [ link_libxed ]))
    # compile & link ild_examples
    if os.path.exists(env['link_libild']):
        for example in env.src_dir_join(ild_examples):
            example_exes.append(ex_compile_and_link(env_c,
                                                    examples_dag,
                                                    example,
                                                    [ env['link_libild'] ]))
            
    # compile & link small_examples
    for example in env.src_dir_join(small_examples):
        example_exes.append(ex_compile_and_link(env_c,
                                                examples_dag,
                                                example,
                                                [ link_libxed ]))
    
    for example in env.src_dir_join(enc2_examples):
        example_exes.append(ex_compile_and_link(  env_c,
                                                  examples_dag,
                                                  example,
                                                  env['xed_enc2_libs'] + [link_libxed]  ))

    mbuild.vmsgb(4, "ALL EXAMPLES", "\n\t".join(example_exes))

    examples_to_build   = example_exes
    env['example_exes'] = example_exes
    
    mbuild.msgb("BUILDING EXAMPLES")
    okay = work_queue.build(examples_dag,
                            targets=examples_to_build,
                            die_on_errors=env['die_on_errors'],
                            show_progress=True, 
                            show_output=True,
                            show_errors_only=_wk_show_errors_only())
    if not okay:
        xbc.cdie( "XED EXAMPLES build failed")
    mbuild.vmsgb(3, "XED EXAMPLES", "build succeeded")
    return 0