<commit_before>import os
import subprocess
import shutil
import logging

from .. import project
from ..cd import cd
from ..process import command_output

from .source import SourceProject


class XcodeProject(project.Project):

    @staticmethod
    def identifier():
        return 'xcode'

    @staticmethod
    def is_valid_project(definition, needy):
        if definition.target.platform.identifier() not in ['osx', 'ios', 'iossimulator', 'tvos', 'tvossimulator']:
            return False

        xcodebuild_args = []

        if 'xcode-project' in definition.configuration:
            xcodebuild_args.extend(['-project', definition.configuration['xcode-project']])

        try:
            with cd(definition.directory):
                command_output(['xcodebuild', '-list'] + xcodebuild_args, logging.DEBUG)
        except subprocess.CalledProcessError:
            return False
        except OSError:
            return False
        return True

    @staticmethod
    def configuration_keys():
        return ['xcode-project']

    def build(self, output_directory):
        xcodebuild_args = ['-parallelizeTargets', 'ONLY_ACTIVE_ARCH=YES', 'USE_HEADER_SYMLINKS=YES']

        if self.configuration('xcode-project'):
            xcodebuild_args.extend(['-project', self.configuration('xcode-project')])

        xcodebuild_args.extend(['-sdk', self.target().platform.sdk()])

        if self.target().architecture:
            xcodebuild_args.extend(['-arch', self.target().architecture])

        extras_build_dir = os.path.join(output_directory, 'extras')
        include_directory = os.path.join(output_directory, 'include')

        self.command(['xcodebuild'] + xcodebuild_args + [
            'INSTALL_PATH=%s' % extras_build_dir,
            'INSTALL_ROOT=/',
            'SKIP_INSTALL=NO',
            'PUBLIC_HEADERS_FOLDER_PATH=%s' % include_directory,
            'PRIVATE_HEADERS_FOLDER_PATH=%s' % include_directory,
            'install', 'installhdrs'
        ])

        lib_extensions = ['.a', '.dylib', '.so', '.la']
        lib_directory = os.path.join(output_directory, 'lib')

        if not os.path.exists(lib_directory):
            os.makedirs(lib_directory)

        for file in os.listdir(extras_build_dir):
            name, extension = os.path.splitext(file)
            if extension in lib_extensions:
                shutil.move(os.path.join(extras_build_dir, file), lib_directory)

        if not os.listdir(extras_build_dir):
            os.rmdir(extras_build_dir)

        if not os.path.exists(include_directory):
            SourceProject.copy_headers(self.directory(), self.configuration(), include_directory)<commit_msg>xcode project header copying fix<commit_after>import os
import subprocess
import shutil
import logging

from .. import project
from ..cd import cd
from ..process import command_output

from .source import SourceProject


class XcodeProject(project.Project):

    @staticmethod
    def identifier():
        return 'xcode'

    @staticmethod
    def is_valid_project(definition, needy):
        if definition.target.platform.identifier() not in ['osx', 'ios', 'iossimulator', 'tvos', 'tvossimulator']:
            return False

        xcodebuild_args = []

        if 'xcode-project' in definition.configuration:
            xcodebuild_args.extend(['-project', definition.configuration['xcode-project']])

        try:
            with cd(definition.directory):
                command_output(['xcodebuild', '-list'] + xcodebuild_args, logging.DEBUG)
        except subprocess.CalledProcessError:
            return False
        except OSError:
            return False
        return True

    @staticmethod
    def configuration_keys():
        return ['xcode-project']

    def build(self, output_directory):
        xcodebuild_args = ['-parallelizeTargets', 'ONLY_ACTIVE_ARCH=YES', 'USE_HEADER_SYMLINKS=YES']

        if self.configuration('xcode-project'):
            xcodebuild_args.extend(['-project', self.configuration('xcode-project')])

        xcodebuild_args.extend(['-sdk', self.target().platform.sdk()])

        if self.target().architecture:
            xcodebuild_args.extend(['-arch', self.target().architecture])

        extras_build_dir = os.path.join(output_directory, 'extras')
        include_directory = os.path.join(output_directory, 'include')

        self.command(['xcodebuild'] + xcodebuild_args + [
            'INSTALL_PATH=%s' % extras_build_dir,
            'INSTALL_ROOT=/',
            'SKIP_INSTALL=NO',
            'PUBLIC_HEADERS_FOLDER_PATH=%s' % include_directory,
            'PRIVATE_HEADERS_FOLDER_PATH=%s' % include_directory,
            'install', 'installhdrs'
        ])

        lib_extensions = ['.a', '.dylib', '.so', '.la']
        lib_directory = os.path.join(output_directory, 'lib')

        if not os.path.exists(lib_directory):
            os.makedirs(lib_directory)

        for file in os.listdir(extras_build_dir):
            name, extension = os.path.splitext(file)
            if extension in lib_extensions:
                shutil.move(os.path.join(extras_build_dir, file), lib_directory)

        if not os.listdir(extras_build_dir):
            os.rmdir(extras_build_dir)

        if not os.listdir(include_directory):
            SourceProject.copy_headers(self.directory(), self.configuration(), include_directory)
{'fraction_non_alphanumeric': 0.11554974799327983, 'fraction_numerical': 0.0, 'mean_word_length': 2.7626404494382024, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3590238', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1515, 'n_words': 293}