<commit_before>"""
SOLVCON Tool for SCons
"""

import sys
import os

def has_sse4(env):
    if not sys.platform.startswith('linux'):
        return False
    entries = [line.split(':') for line in
        open('/proc/cpuinfo').read().strip().split('\n') if len(line) > 0]
    cpuinfo = dict([(entry[0].strip(), entry[1].strip()) for entry in entries])
    if 'sse4' in cpuinfo['flags']:
        return True
    return False

def get_scdata(env, url, datapath):
    if os.path.exists(datapath):
        orig = os.getcwd()
        os.chdir(datapath)
        os.system('hg pull -u')
        os.chdir(orig)
    else:
        os.system('hg clone %s %s' % (url, datapath))

def solvcon_shared(env, sdirs, libname, ndim=None, ext=None, fptype=None,
        srcdir='src', prepends=None):
    """
    I need SCBUILDDIR, SCLIBDIR, and SCLIBPREFIX set in env.
    """
    # clone the environment to avoid polution.
    env = env.Clone()
    # prepend custom environment variables.
    prepends = {} if prepends is None else prepends
    for key in prepends:
        env.Prepend(key=prepends[key])
    # prepare file lists.
    ddsts = list()
    for dsrc in sdirs:
        # craft source directory name.
        dsrc = '%s/%s' % (srcdir, str(dsrc))
        # skip non-directory.
        if not os.path.isdir(dsrc):
            continue
        # craft destination directory name.
        ddst = '%s/%s' % (env['SCBUILDDIR'], os.path.basename(dsrc))
        if ndim is not None:
            ddst += '%dd' % ndim
        if ext is not None:
            ddst += '_%s' % ext
        if fptype is not None:
            ddst += '_%s' % {'float': 's', 'double': 'd'}[fptype]
        # copy source.
        env.VariantDir(ddst, dsrc, duplicate=1)
        # collect source files.
        ddsts.extend(env.Glob('%s/*.%s' % (ddst, 'c' if ext is None else ext)))
    ddsts = env.Flatten(ddsts)
    # craft library file name.
    filename = '%s/%s_%s' % (env['SCLIBDIR'], env['SCLIBPREFIX'], libname)
    if ndim is not None:
        env.Prepend(CCFLAGS=['-DNDIM=%d'%ndim])<commit_msg>Fix library-linking bug in SCons scripts.<commit_after>"""
SOLVCON Tool for SCons
"""

import sys
import os

def has_sse4(env):
    if not sys.platform.startswith('linux'):
        return False
    entries = [line.split(':') for line in
        open('/proc/cpuinfo').read().strip().split('\n') if len(line) > 0]
    cpuinfo = dict([(entry[0].strip(), entry[1].strip()) for entry in entries])
    if 'sse4' in cpuinfo['flags']:
        return True
    return False

def get_scdata(env, url, datapath):
    if os.path.exists(datapath):
        orig = os.getcwd()
        os.chdir(datapath)
        os.system('hg pull -u')
        os.chdir(orig)
    else:
        os.system('hg clone %s %s' % (url, datapath))

def solvcon_shared(env, sdirs, libname, ndim=None, ext=None, fptype=None,
        srcdir='src', prepends=None):
    """
    I need SCBUILDDIR, SCLIBDIR, and SCLIBPREFIX set in env.
    """
    # clone the environment to avoid polution.
    env = env.Clone()
    # prepend custom environment variables.
    prepends = {} if prepends is None else prepends
    for key in prepends:
        if prepends[key] is not None:
            env.Prepend(**{key: prepends[key]}) # weird treatment for Prepend.
    # prepare file lists.
    ddsts = list()
    for dsrc in sdirs:
        # craft source directory name.
        dsrc = '%s/%s' % (srcdir, str(dsrc))
        # skip non-directory.
        if not os.path.isdir(dsrc):
            continue
        # craft destination directory name.
        ddst = '%s/%s' % (env['SCBUILDDIR'], os.path.basename(dsrc))
        if ndim is not None:
            ddst += '%dd' % ndim
        if ext is not None:
            ddst += '_%s' % ext
        if fptype is not None:
            ddst += '_%s' % {'float': 's', 'double': 'd'}[fptype]
        # copy source.
        env.VariantDir(ddst, dsrc, duplicate=1)
        # collect source files.
        ddsts.extend(env.Glob('%s/*.%s' % (ddst, 'c' if ext is None else ext)))
    ddsts = env.Flatten(ddsts)
    # craft library file name.
    filename = '%s/%s_%s' % (env['SCLIBDIR'], env['SCLIBPREFIX'], libname)
    if ndim is not None:
        env.Prepend(CCFLAGS=['-DNDIM=%d'%ndim])
{'fraction_non_alphanumeric': 0.14829706717123936, 'fraction_numerical': 0.002838221381267739, 'mean_word_length': 2.394060995184591, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7298399', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1463, 'n_words': 402}