<commit_before># ome - Object Message Expressions
# Copyright (c) 2015-2016 <NAME> <<EMAIL>>

import os
import platform
from ...error import OmeError
from ...util import temporary_file

def find_musl_path(path):
    if path:
        return path
    path = os.environ.get('MUSL_PATH')
    if path:
        return path
    for path in ['/usr/local/lib/musl', '/usr/lib/musl']:
        if os.path.isdir(path):
            return path
    raise OmeError('could not find musl path, please specify with --musl-path')

class CCArgsBuilder(object):
    cc_args = []
    link_args = []
    variant_cc_args = {'release': [], 'fast': [], 'debug': []}
    variant_link_args = {'release': [], 'fast': [], 'debug': []}

    def get_musl_args(self, build_options, musl_path):
        raise OmeError("musl is not supported for this backend")

    def __call__(self, build_options, infile, outfile, linking):
        if build_options.static and build_options.platform == 'darwin':
            raise OmeError('macOS does not support static linking')
        args = []
        tail_args = []
        if build_options.use_musl:
            musl_path = find_musl_path(build_options.musl_path)
            args, tail_args = self.get_musl_args(build_options, musl_path, linking)
        args.append('-pipe')
        if build_options.verbose_backend:
            args.append('-v')
        if not linking:
            args.append('-c')
            args.extend(self.cc_args)
            args.extend(self.variant_cc_args.get(build_options.variant, []))
            for name, value in build_options.defines:
                args.append('-D{}={}'.format(name, value) if value else '-D' + name)
            for include_dir in build_options.include_dirs:
                args.append('-I' + include_dir)
            args.append(infile)
        else:
            args.append('-static' if build_options.static else '-pie')
            args.extend(self.link_args)
            args.extend(self.variant_link_args.get((build_options.platform, build_options.variant), []))
            args.append(infile)
            for obj in build_options.objects:
                args.append(obj)
            for lib_dir in build_options.library_dirs:
                args.append('-L' + lib_dir)
            for lib in build_options.libraries:
                args.append('-l' + lib)
        args.extend(tail_args)
        args.append('-o')
        args.append(outfile)
        return args

class CCBuilder(object):
    obj_extension = '.o'
    lib_extension = '.a'
    exe_extension = ''

    def __init__(self, command):
        self.command = command

    def output_name(self, infile, build_options):
        return os.path.splitext(infile)[0] + (self.exe_extension if build_options.link else self.obj_extension)

    def build_file(self, shell, infile, outfile, build_options):
        if build_options.link:
            with temporary_file(prefix='.ome-build.', suffix='.o') as objfile:
                shell.run([self.command] + self.get_build_args(build_options, infile, objfile, False))
                if build_options.link:
                    shell.run([self.command] + self.get_build_args(build_options, objfile, outfile, True))
                    if build_options.release and platform.system() == 'Linux':
                        shell.run('strip', '--strip-all', '--remove-section=.comment', '--remove-section=.note', outfile)
        else:
            shell.run([self.command] + self.get_build_args(build_options, infile, outfile, False))

    def build_string(self, shell, code, outfile, build_options):
        if build_options.link:
            with temporary_file(prefix='.ome-build.', suffix='.o') as objfile:
                shell.run([self.command] + self.get_build_args(build_options, '-', objfile, False), input=code)
                if build_options.link:
                    shell.run([self.command] + self.get_build_args(build_options, objfile, outfile, True))
                    if build_options.release and platform.system() == 'Linux':
                        shell.run('strip', '--strip-all', '--remove-section=.comment', '--remove-section=.note', outfile)
        else:
            shell.run([self.command] + self.get_build_args(build_options, '-', outfile, False), input=code)<commit_msg>Define build_string in terms of build_file to eliminate duplicated code.<commit_after># ome - Object Message Expressions
# Copyright (c) 2015-2016 <NAME> <<EMAIL>>

import os
import platform
from ...error import OmeError
from ...util import temporary_file

def find_musl_path(path):
    if path:
        return path
    path = os.environ.get('MUSL_PATH')
    if path:
        return path
    for path in ['/usr/local/lib/musl', '/usr/lib/musl']:
        if os.path.isdir(path):
            return path
    raise OmeError('could not find musl path, please specify with --musl-path')

class CCArgsBuilder(object):
    cc_args = []
    link_args = []
    variant_cc_args = {'release': [], 'fast': [], 'debug': []}
    variant_link_args = {'release': [], 'fast': [], 'debug': []}

    def get_musl_args(self, build_options, musl_path):
        raise OmeError("musl is not supported for this backend")

    def __call__(self, build_options, infile, outfile, linking):
        if build_options.static and build_options.platform == 'darwin':
            raise OmeError('macOS does not support static linking')
        args = []
        tail_args = []
        if build_options.use_musl:
            musl_path = find_musl_path(build_options.musl_path)
            args, tail_args = self.get_musl_args(build_options, musl_path, linking)
        args.append('-pipe')
        if build_options.verbose_backend:
            args.append('-v')
        if not linking:
            args.append('-c')
            args.extend(self.cc_args)
            args.extend(self.variant_cc_args.get(build_options.variant, []))
            for name, value in build_options.defines:
                args.append('-D{}={}'.format(name, value) if value else '-D' + name)
            for include_dir in build_options.include_dirs:
                args.append('-I' + include_dir)
            args.append(infile)
        else:
            args.append('-static' if build_options.static else '-pie')
            args.extend(self.link_args)
            args.extend(self.variant_link_args.get((build_options.platform, build_options.variant), []))
            args.append(infile)
            for obj in build_options.objects:
                args.append(obj)
            for lib_dir in build_options.library_dirs:
                args.append('-L' + lib_dir)
            for lib in build_options.libraries:
                args.append('-l' + lib)
        args.extend(tail_args)
        args.append('-o')
        args.append(outfile)
        return args

class CCBuilder(object):
    obj_extension = '.o'
    lib_extension = '.a'
    exe_extension = ''

    def __init__(self, command):
        self.command = command

    def output_name(self, infile, build_options):
        return os.path.splitext(infile)[0] + (self.exe_extension if build_options.link else self.obj_extension)

    def build_file(self, shell, infile, outfile, build_options, input=None):
        if build_options.link:
            with temporary_file(prefix='.ome-build.', suffix='.o') as objfile:
                shell.run([self.command] + self.get_build_args(build_options, infile, objfile, False), input=input)
                if build_options.link:
                    shell.run([self.command] + self.get_build_args(build_options, objfile, outfile, True))
                    if build_options.release and platform.system() == 'Linux':
                        shell.run('strip', '--strip-all', '--remove-section=.comment', '--remove-section=.note', outfile)
        else:
            shell.run([self.command] + self.get_build_args(build_options, infile, outfile, False), input=input)

    def build_string(self, shell, code, outfile, build_options):
        self.build_file(shell, '-', outfile, build_options, input=code)
{'fraction_non_alphanumeric': 0.12503116429818, 'fraction_numerical': 0.002243829468960359, 'mean_word_length': 2.4566996984058593, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055605', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2375, 'n_words': 524}