예제 #1
0
def main():
    args = sys.argv[1:]
    plugin_args, args = get_plugin_args(args)
    
    if '-c' not in args:
        return ldmodwrap_main(args)

    c_index = -1
    for i, p in enumerate(args):
        if p.endswith('.c') or p.endswith("cpp"):
            c_index = i
            break

    if c_index == -1:
        ret = spawn(args)
        return ret

    cpp_args = list(args)
    cpp_args[args.index('-c')] = '-E'
    c_file = args[c_index]
    cflags = get_cflags(args)
    if p.endswith('cpp'):
        language = 'c++'
    else:
        language = 'c'

    if '-o' not in args:
        o_file = c_file + '.o'
        pp_file = o_file + '.pp'
        cpp_args.append('-o')
        cpp_args.append(pp_file)
    else:
        o_index = args.index('-o') + 1
        o_file = cpp_args[o_index]
        pp_file = o_file + '.pp'
        cpp_args[o_index] = pp_file

    # Hack for dealing with sources that use _GNU_SOURCE
    if '#define _GNU_SOURCE' in file(c_file).read():
        cpp_args.extend(["-w", "-D", "_GNU_SOURCE"])

    cpp_args.extend(["-D", "__TRACE_INSTRUMENTATION"])
    va_arg_pack_def_file = _create_va_arg_pack_def_file()

    cpp_args.extend(["-include", va_arg_pack_def_file])
    cpp_args.extend(["-include", os.path.join(os.path.dirname(sys.argv[0]),  "trace_user.h")])

    out_pp_file = pp_file + ".i"
    ret = spawn(cpp_args)
    if ret:
        return ret
    clang_ret = 0;

    try:
        clang_ret = maybe_translate(pp_file, out_pp_file, language, cflags, plugin_args)
        if clang_ret != 0:
            return -1

        comp_args = []
        comp_args.extend(list(args))
        if '-o' not in comp_args:
            o_file = os.path.splitext(c_file)[0] + '.o'
            comp_args.extend(['-o', o_file])

        comp_args[c_index] = out_pp_file
        ret = spawn(comp_args)
        return ret;
    finally:
        os.unlink(va_arg_pack_def_file)
        os.unlink(pp_file)
        if os.getenv("TRACE_NO_UNLINK_PPFILE", "") == "":
            # Delete the pp.i file only if the clang invocation was successful
            if clang_ret == 0:
                os.unlink(out_pp_file)
예제 #2
0
def main():
    args = sys.argv[1:]
    plugin_args, args = get_plugin_args(args)

    if '-c' not in args:
        return ldmodwrap_main(args)

    c_index = -1
    for i, p in enumerate(args):
        if p.endswith('.c') or p.endswith("cpp"):
            c_index = i
            break

    if c_index == -1:
        ret = spawn(args)
        return ret

    cpp_args = list(args)
    cpp_args[args.index('-c')] = '-E'
    c_file = args[c_index]
    cflags = get_cflags(args)
    if p.endswith('cpp'):
        language = 'c++'
    else:
        language = 'c'

    if '-o' not in args:
        o_file = c_file + '.o'
        pp_file = o_file + '.pp'
        cpp_args.append('-o')
        cpp_args.append(pp_file)
    else:
        o_index = args.index('-o') + 1
        o_file = cpp_args[o_index]
        pp_file = o_file + '.pp'
        cpp_args[o_index] = pp_file

    # Hack for dealing with sources that use _GNU_SOURCE
    if '#define _GNU_SOURCE' in file(c_file).read():
        cpp_args.extend(["-w", "-D", "_GNU_SOURCE"])

    cpp_args.extend(["-D", "__TRACE_INSTRUMENTATION"])
    va_arg_pack_def_file = _create_va_arg_pack_def_file()

    cpp_args.extend(["-include", va_arg_pack_def_file])
    cpp_args.extend([
        "-include",
        os.path.join(os.path.dirname(sys.argv[0]), "trace_user.h")
    ])

    out_pp_file = pp_file + ".i"
    ret = spawn(cpp_args)
    if ret:
        return ret
    clang_ret = 0

    try:
        clang_ret = maybe_translate(pp_file, out_pp_file, language, cflags,
                                    plugin_args)
        if clang_ret != 0:
            return -1

        comp_args = []
        comp_args.extend(list(args))
        if '-o' not in comp_args:
            o_file = os.path.splitext(c_file)[0] + '.o'
            comp_args.extend(['-o', o_file])

        comp_args[c_index] = out_pp_file
        ret = spawn(comp_args)
        return ret
    finally:
        try:
            os.unlink(va_arg_pack_def_file)
            os.unlink(pp_file)
            if os.getenv("TRACE_NO_UNLINK_PPFILE", "") == "":
                # Delete the pp.i file only if the clang invocation was successful
                if clang_ret == 0:
                    os.unlink(out_pp_file)
        except OSError:
            pass
예제 #3
0
def main():
    args = sys.argv[1:]
    if '-c' not in args:
        return ldmodwrap_main()

    c_index = -1
    for i, p in enumerate(args):
        if p.endswith('.c') or p.endswith('cpp'):
            c_index = i
            break

    if c_index == -1:
        ret = spawn(args)
        return ret

    cpp_args = list(args)
    cpp_args[args.index('-c')] = '-E'
    o_index = None
    if '-o' not in args:
        o_file = c_file + '.o'
        pp_file = o_file + '.pp'
        cpp_args.append('-o')
        cpp_args.append(pp_file)
    else:
        o_index = args.index('-o') + 1
        o_file = cpp_args[o_index]
        pp_file = o_file + '.pp'
        cpp_args[o_index] = pp_file

    handle_dependency_option(cpp_args, c_index, o_index, o_file)    
    c_file = args[c_index]
    source_data = file(c_file).read()
    if 'ANDROID_SINGLETON_STATIC_INSTANCE' in source_data:
        return spawn(args)

    # Hack for dealing with sources that use _GNU_SOURCE
    if '#define _GNU_SOURCE' in source_data:
        cpp_args.extend(["-w", "-D", "_GNU_SOURCE"])
        
    cflags = get_cflags(args)
    if p.endswith('cpp'):
        language = 'c++'
    else:
        language = 'c'

        
    cpp_args.extend(["-D", "__TRACE_INSTRUMENTATION"])
    cpp_args.extend(["-include", os.path.join(os.path.dirname(sys.argv[0]),  "include/trace_lib.h")])
    cpp_args.extend(["-include", os.path.join(os.path.dirname(sys.argv[0]),  "include/trace_user.h")])

    out_pp_file = pp_file + ".i"
    ret = spawn(cpp_args)
    if ret:
        return ret
    clang_ret = 0;

    try:
        clang_ret = maybe_translate(pp_file, out_pp_file, language, get_arch_triplet(args[0]), cflags)
        if clang_ret != 0:
            return -1

        comp_args = []
        comp_args.extend(list(args))
        if '-o' not in comp_args:
            o_file = os.path.splitext(c_file)[0] + '.o'
            comp_args.extend(['-o', o_file])

        comp_args[c_index] = out_pp_file
        ret = spawn(comp_args)
        return ret;
    finally:
        os.unlink(pp_file)
        if os.getenv("TRACE_NO_UNLINK_PPFILE", "") == "":
            # Delete the pp.i file only if the clang invocation was successful
            if clang_ret == 0:
               os.unlink(out_pp_file)