Ejemplo n.º 1
0
    def define_group_properties(self):
        """
        Define the PropertyGroups and DefinitionGroups of XML properties

        """

        # PropertyGroup
        self.propertygroup['debug']['x86'] = get_propertygroup(
            'debug', 'x86', ' and @Label="Configuration"')
        self.propertygroup['debug']['x64'] = get_propertygroup(
            'debug', 'x64', ' and @Label="Configuration"')
        self.propertygroup['release']['x86'] = get_propertygroup(
            'release', 'x86', ' and @Label="Configuration"')
        self.propertygroup['release']['x64'] = get_propertygroup(
            'release', 'x64', ' and @Label="Configuration"')

        # ItemDefinitionGroup
        self.definitiongroups['debug']['x86'] = get_definitiongroup(
            'debug', 'x86')
        self.definitiongroups['debug']['x64'] = get_definitiongroup(
            'debug', 'x64')
        self.definitiongroups['release']['x86'] = get_definitiongroup(
            'release', 'x86')
        self.definitiongroups['release']['x64'] = get_definitiongroup(
            'release', 'x64')
Ejemplo n.º 2
0
    def define_group_properties(self):
        """
        Define the PropertyGroups and DefinitionGroups of XML properties

        """

        # PropertyGroup
        self.propertygroup['debug']['x86'] = get_propertygroup(
            'debug', 'x86', ' and @Label="Configuration"'
        )
        self.propertygroup['debug']['x64'] = get_propertygroup(
            'debug', 'x64', ' and @Label="Configuration"'
        )
        self.propertygroup['release']['x86'] = get_propertygroup(
            'release', 'x86', ' and @Label="Configuration"'
        )
        self.propertygroup['release']['x64'] = get_propertygroup(
            'release', 'x64', ' and @Label="Configuration"'
        )

        # ItemDefinitionGroup
        self.definitiongroups['debug']['x86'] = get_definitiongroup('debug', 'x86')
        self.definitiongroups['debug']['x64'] = get_definitiongroup('debug', 'x64')
        self.definitiongroups['release']['x86'] = get_definitiongroup('release', 'x86')
        self.definitiongroups['release']['x64'] = get_definitiongroup('release', 'x64')
Ejemplo n.º 3
0
    def test_get_propertygroup(self):
        """Get Property Group"""

        under_test = get_propertygroup(('Release', 'x64'), 'and @Label="Configuration"')

        self.assertTrue('PropertyGroup' in under_test)
        self.assertTrue('Release|x64' in under_test)
Ejemplo n.º 4
0
    def define_group_properties(self):
        """
        Define the PropertyGroups and DefinitionGroups of XML properties

        """

        for setting in self.settings:
            self.propertygroup[setting] = get_propertygroup(
                setting, ' and @Label="Configuration"')

        # ItemDefinitionGroup
        for setting in self.settings:
            self.definitiongroups[setting] = get_definitiongroup(setting)
Ejemplo n.º 5
0
    def test_get_propertygroup(self):
        """Get Property Group"""

        under_test = get_propertygroup('debug', 'x86')
        self.assertTrue('PropertyGroup' in under_test)

        self.assertTrue('Debug' in under_test)
        self.assertTrue('Win32' in under_test)

        under_test = get_propertygroup('debug', 'x64')

        self.assertTrue('Debug' in under_test)
        self.assertTrue('x64' in under_test)

        under_test = get_propertygroup('release', 'x86')

        self.assertTrue('Release' in under_test)
        self.assertTrue('Win32' in under_test)

        under_test = get_propertygroup('release', 'x64')

        self.assertTrue('Release' in under_test)
        self.assertTrue('x64' in under_test)
Ejemplo n.º 6
0
    def test_get_propertygroup(self):
        """Get Property Group"""

        under_test = get_propertygroup('debug', 'x86')
        self.assertTrue('PropertyGroup' in under_test)

        self.assertTrue('Debug' in under_test)
        self.assertTrue('Win32' in under_test)

        under_test = get_propertygroup('debug', 'x64')

        self.assertTrue('Debug' in under_test)
        self.assertTrue('x64' in under_test)

        under_test = get_propertygroup('release', 'x86')

        self.assertTrue('Release' in under_test)
        self.assertTrue('Win32' in under_test)

        under_test = get_propertygroup('release', 'x64')

        self.assertTrue('Release' in under_test)
        self.assertTrue('x64' in under_test)
Ejemplo n.º 7
0
    def apply_target_dependency_packages(self, context):
        """
        Trying to apply settings and use Nuget Packages

        :param context:
        :return:
        """
        if not context.packages_config_path:
            return

        packages_xml_data = self.__get_info_from_packages_config(context)
        if packages_xml_data is None:
            return

        for targets_file_path in context.import_projects:
            package_id = ''
            package_version = ''
            id_version = ''
            for id_version_i in packages_xml_data:
                if id_version_i in targets_file_path:
                    id_version = id_version_i
                    package_id = packages_xml_data[id_version_i][0]
                    package_version = packages_xml_data[id_version_i][1]
                    break

            if context.import_projects and not id_version:
                message(
                    context,
                    'can not find package version in {} by {} path'.format(
                        context.packages_config_path,
                        targets_file_path,
                    ), 'warn')
                continue

            ext_properties = self.__parse_targets_file_of_nuget_package(
                context, targets_file_path)
            context.packages.append(
                [package_id, package_version, ext_properties])

            for ext_property in ext_properties:
                for setting in context.settings:
                    if None in setting:
                        continue
                    if 'packages' not in context.settings[setting]:
                        context.settings[setting]['packages'] = {}
                    ext_property_node = context.xml_data['tree'].xpath(
                        '{}/ns:{}'.format(get_propertygroup(setting),
                                          ext_property),
                        namespaces=context.xml_data['ns'])
                    if ext_property_node:
                        if id_version not in context.settings[setting][
                                'packages']:
                            context.settings[setting]['packages'][
                                id_version] = {}
                        context.settings[setting]['packages'][id_version][ext_property] = \
                            [ext_property_node[0].text]
                        message(
                            context,
                            '{} property of {} {} for {} is {}'.format(
                                ext_property, package_id, package_version,
                                setting, ext_property_node[0].text), '')

            message(context,
                    'Used package {} {}.'.format(package_id,
                                                 package_version), '')
    def add_project_variables(self):
        """
        Add main CMake project variables

        """

        # CMake Minimum required.
        self.cmake.write(
            'cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR)\n\n')

        # Project Name
        self.cmake.write(
            '################### Variables. ####################\n'
            '# Change if you want modify path or other values. #\n'
            '###################################################\n\n')
        root_projectname = self.tree.xpath('//ns:RootNamespace',
                                           namespaces=self.ns)
        project = False
        if root_projectname:
            projectname = root_projectname[0]
            if projectname.text:
                self.cmake.write('set(PROJECT_NAME ' + projectname.text +
                                 ')\n')
                project = True
        if not project:  # pragma: no cover
            self.cmake.write(
                'set(PROJECT_NAME <PLEASE SET YOUR PROJECT NAME !!>)\n')
            send(
                'No PROJECT NAME found or define. '
                'Please set [PROJECT_NAME] variable in CMakeLists.txt.',
                'error')

        # PropertyGroup
        prop_deb_x86 = get_propertygroup('debug', 'x86')
        prop_deb_x64 = get_propertygroup('debug', 'x64')
        prop_rel_x86 = get_propertygroup('release', 'x86')
        prop_rel_x64 = get_propertygroup('release', 'x64')

        if not self.vs_outputs['debug']['x86']:
            self.vs_outputs['debug']['x86'] = self.tree.find(
                '%s//ns:OutDir' % prop_deb_x86, namespaces=self.ns)
            if self.vs_outputs['debug']['x86'] is None:
                vs_output_debug_x86 = self.tree.xpath(
                    '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir',
                    namespaces=self.ns)
                if vs_output_debug_x86:
                    self.vs_outputs['debug']['x86'] = vs_output_debug_x86[0]
        if not self.vs_outputs['debug']['x64']:
            self.vs_outputs['debug']['x64'] = self.tree.find(
                '%s/ns:OutDir' % prop_deb_x64, namespaces=self.ns)
            if self.vs_outputs['debug']['x64'] is None:
                vs_output_debug_x64 = self.tree.xpath(
                    '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir',
                    namespaces=self.ns)
                if vs_output_debug_x64:
                    self.vs_outputs['debug']['x64'] = vs_output_debug_x64[0]
        if not self.vs_outputs['release']['x86']:
            self.vs_outputs['release']['x86'] = self.tree.find(
                '%s//ns:OutDir' % prop_rel_x86, namespaces=self.ns)
            if self.vs_outputs['release']['x86'] is None:
                vs_output_release_x86 = self.tree.xpath(
                    '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir',
                    namespaces=self.ns)
                if vs_output_release_x86:
                    self.vs_outputs['release']['x86'] = vs_output_release_x86[
                        0]
        if not self.vs_outputs['release']['x64']:
            self.vs_outputs['release']['x64'] = self.tree.find(
                '%s//ns:OutDir' % prop_rel_x64, namespaces=self.ns)
            if self.vs_outputs['release']['x64'] is None:
                vs_output_release_x64 = self.tree.xpath(
                    '//ns:PropertyGroup[@Label="UserMacros"]/ns:OutDir',
                    namespaces=self.ns)
                if vs_output_release_x64:
                    self.vs_outputs['release']['x64'] = vs_output_release_x64[
                        0]
    def add_output_variables(self):
        """
        Add output variables

        """

        if not self.output:
            # Get configurations
            configuration_nodes = self.tree.xpath('//ns:ProjectConfiguration',
                                                  namespaces=self.ns)
            target_plaforms = []
            if configuration_nodes:
                for configuration_node in configuration_nodes:
                    configuration_data = str(configuration_node.get('Include'))
                    target_plaforms.append(configuration_data)

            for target_platform in target_plaforms:
                property_grp = get_propertygroup(target_platform)
                output = self.tree.find('%s//ns:OutDir' % property_grp,
                                        namespaces=self.ns)
                if output is not None:
                    output = output.text.replace('$(ProjectDir)',
                                                 '').replace('\\', '/')
                    output = self.cleaning_output(output)
                    self.cmake_outputs[target_platform] = output
        else:
            # Remove slash/backslash if needed
            if self.output.endswith('/') or self.output.endswith('\\'):
                self.output = self.output[0:-1]
            # Define only output for x64
            self.cmake_outputs['Debug|x64'] = '/'.join(
                [self.output, '${PROJECT_DIR}'])
            self.cmake_outputs['Release|x64'] = '/'.join(
                [self.output, '${PROJECT_DIR}'])

        output_debug = ''
        output_release = ''

        for output in self.cmake_outputs:
            if 'Debug' in output:
                if 'x64' in output:
                    output_debug = self.cmake_outputs[output]
                if 'Win32' in output and not output_debug:
                    output_debug = self.cmake_outputs[output]
            if 'Release' in output:
                if 'x64' in output:
                    output_release = self.cmake_outputs[output]
                if 'Win32' in output and not output_release:
                    output_release = self.cmake_outputs[output]

        # In case converter can't find output, assign default
        if not output_debug:
            output_debug = '${PROJECT_DIR}/bin'
        if not output_release:
            output_release = '${PROJECT_DIR}/bin'

        self.cmake.write('# Outputs\n')
        self.cmake.write('set(OUTPUT_DEBUG %s)\n' % output_debug)
        self.cmake.write('set(OUTPUT_RELEASE %s)\n' % output_release)

        message('Following output define for Release: %s' % output_release,
                'INFO')
        message('Following output define for Debug: %s' % output_debug, 'INFO')