<commit_before>import os
import sys
import subprocess
from subprocess import CalledProcessError

import CoreFoundation

class xcrun(object):
    """
    This class exists to execute 'xcrun' tools.
    """
    
    @classmethod
    def BuildLocation(cls, project, sym_root):
        build_dir_path = '';
        default_dd_path = os.path.expanduser("~/Library/Developer/Xcode/DerivedData/");
        relative_dd_path = False;
        derived_data = CoreFoundation.CFPreferencesCopyAppValue('IDECustomDerivedDataLocation', 'com.apple.dt.Xcode');
        if derived_data == None:
            derived_data = default_dd_path;
        else:
            if derived_data[0] != '/':
                derived_data = os.path.join(project.path, derived_data);
        
        location_style = CoreFoundation.CFPreferencesCopyAppValue('IDEBuildLocationStyle', 'com.apple.dt.Xcode');
        if location_style == 'Unique':
            # this needs to be generated
            unique_path = '';
            build_dir_path = os.path.join(derived_data, unique_path);
        elif location_style == 'Shared':
            shared_path = CoreFoundation.CFPreferencesCopyAppValue('IDESharedBuildFolderName', 'com.apple.dt.Xcode');
            build_dir_path = os.path.join(derived_data, shared_path);
        elif location_style == 'Custom':
            location_type = CoreFoundation.CFPreferencesCopyAppValue('IDECustomBuildLocationType', 'com.apple.dt.Xcode');
            custom_path = CoreFoundation.CFPreferencesCopyAppValue('IDECustomBuildProductsPath', 'com.apple.dt.Xcode');
            if location_type == 'RelativeToDerivedData':
                build_dir_path = os.path.join(derived_data, custom_path);
            elif location_type == 'RelativeToWorkspace':
                build_dir_path = os.path.join(project.path.base_path, custom_path);
            elif location_type == 'Absolute':
                build_dir_path = custom_path;
        elif location_style == 'DeterminedByTargets':
            build_dir_path = os.path.join(project.projectRoot.obj_path, sym_root);
        <commit_msg>adding unique build location hashing function<commit_after>import os
import sys
import subprocess
from subprocess import CalledProcessError
import hashlib
import CoreFoundation
import array

class xcrun(object):
    """
    This class exists to execute 'xcrun' tools.
    """
    
    @classmethod
    def hashStringForPath(cls, path):
        hash_context = hashlib.md5();
        hash_context.update(path);
        md5_digest_hex = hash_context.digest();
        
        hash_path = [None] * 28;
        
        first_value = int(''.join('{:02x}'.format(ord(c)) for c in md5_digest_hex[0:8]), 16);
        
        counter = 13;
        while counter >= 0:
            hash_path[counter] = chr((first_value % 26) + ord('a'));
            first_value = first_value / 26;
            counter -= 1;
        
        second_value = int(''.join('{:02x}'.format(ord(c)) for c in md5_digest_hex[8:16]), 16);
        
        counter = 27;
        while counter > 13:
            hash_path[counter] = chr((second_value % 26) + ord('a'));
            second_value = second_value / 26;
            counter -= 1;
        
        hash_path = ''.join(hash_path);
        
        return hash_path;
    
    @classmethod
    def BuildLocation(cls, project, sym_root):
        build_dir_path = '';
        default_dd_path = os.path.expanduser("~/Library/Developer/Xcode/DerivedData/");
        relative_dd_path = False;
        derived_data = CoreFoundation.CFPreferencesCopyAppValue('IDECustomDerivedDataLocation', 'com.apple.dt.Xcode');
        if derived_data == None:
            derived_data = default_dd_path;
        else:
            if derived_data[0] != '/':
                derived_data = os.path.join(project.path, derived_data);
        
        location_style = CoreFoundation.CFPreferencesCopyAppValue('IDEBuildLocationStyle', 'com.apple.dt.Xcode');
        if location_style == 'Unique':
            # this needs to be generated
            xcodeproj_path = os.path.join(project.projectRoot.obj_path, project.name);
            unique_path = xcrun.hashStringForPath(xcodeproj_path);
            project_dir_name = os.path.splitext(project.name)[0]+'-'+unique_path+'/Build/Products/';
            build_dir_path = os.path.join(derived_data, project_dir_name);
        elif location_style == 'Shared':
            shared_path = CoreFoundation.CFPreferencesCopyAppValue('IDESharedBuildFolderName', 'com.apple.dt.Xcode');
            build_dir_path = os.path.join(derived_data, shared_path);
        elif location_style == 'Custom':
            location_type = CoreFoundation.CFPreferencesCopyAppValue('IDECustomBuildLocationType', 'com.apple.dt.Xcode');
            custom_path = CoreFoundation.CFPreferencesCopyAppValue('IDECustomBuildProductsPath', 'com.apple.dt.Xcode');
            if location_type == 'RelativeToDerivedData':
                build_dir_path = os.path.join(derived_data, custom_path);
            elif location_type == 'RelativeToWorkspace':
                build_dir_path = os.path.join(project.path.base_path, custom_path);
            elif location_type == 'Absolute':
                build_dir_path = custom_path;
        elif location_style == 'DeterminedByTargets':
            build_dir_path = os.path.join(project.projectRoot.obj_path, sym_root);
        
{'fraction_non_alphanumeric': 0.10728254796051406, 'fraction_numerical': 0.007263922518159807, 'mean_word_length': 2.6983471074380163, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5030553', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1542, 'n_words': 275}