Ejemplo n.º 1
0
    def test_init_files(self):
        """Data Converter Init Files"""

        data_test = {
            'cmake': None,
            'cmake_output': None,
            'vcxproj': None,
            'dependencies': None,
            'includes': None,
            'additional_code': None,
        }

        under_test = DataConverter(data_test)

        self.assertTrue(under_test.data)
        self.assertIsNone(under_test.data['cmake'])
        self.assertIsNone(under_test.data['vcxproj'])

        under_test.init_files(self.vs_project, './')

        self.assertIsNotNone(under_test.data['cmake'])
        self.assertIsNotNone(under_test.data['vcxproj'])

        self.assertTrue('ns' in under_test.data['vcxproj'])
        self.assertTrue('tree' in under_test.data['vcxproj'])
Ejemplo n.º 2
0
    def test_init_files(self):
        """Data Converter Init Files"""

        data_test = {
            'cmake': None,
            'cmake_output': None,
            'vcxproj': None,
            'dependencies': None,
            'includes': None,
            'additional_code': None,
            'std': None,
        }

        under_test = DataConverter(data_test)

        self.assertTrue(under_test.data)
        self.assertIsNone(under_test.data['cmake'])
        self.assertIsNone(under_test.data['vcxproj'])

        under_test.init_files(self.vs_project, self.cur_dir)
        under_test.close_cmake_file()

        self.assertIsNotNone(under_test.data['cmake'])
        self.assertIsNotNone(under_test.data['vcxproj'])

        self.assertTrue('ns' in under_test.data['vcxproj'])
        self.assertTrue('tree' in under_test.data['vcxproj'])
Ejemplo n.º 3
0
 def setUp(self):
     cur_dir = os.path.dirname(os.path.realpath(__file__))
     context = Context()
     context.verbose = False
     vs_project = '{}/datatest/foo.vcxproj'.format(cur_dir)
     context.cmake = './'
     converter = DataConverter()
     converter.convert_project(context, vs_project, cur_dir)
    def test_inclusion_of_cmake_is_written(self):
        """Inclusion of ".cmake" File is Written"""

        data_test = {
            'cmake': './',
            'cmakeoutput': '',
            'vcxproj': self.vs_project,
            'project': self.vs_project,
            'dependencies': [],
            'include': '../../test.txt',
            'includecmake': '../../test.cmake',
            'additional': '',
            'std': '',
        }
        under_test = DataConverter(data_test)
        under_test.init_files(self.vs_project, '.')
        under_test.data['cmake'] = get_cmake_lists('./')

        under_test.create_data()
        under_test.close_cmake_file()

        cmakelists_test = open('CMakeLists.txt')

        content_test = cmakelists_test.read()

        # Includes are added
        self.assertTrue('Include files and directories' in content_test)
        self.assertTrue('../../test.cmake' in content_test)

        # File "test.txt" is not added because it does not exist
        self.assertTrue('../../test.txt' not in content_test)

        cmakelists_test.close()
    def test_receive_wrong_cmake_path(self):
        """Wrong CMake Path Write in Current Directory"""

        data_test = {
            'cmake': None,
            'cmake_output': None,
            'vcxproj': None,
            'dependencies': None,
            'includes': None,
            'include_cmake': None,
            'additional_code': None,
            'std': None,
        }
        under_test = DataConverter(data_test)
        under_test.init_files(self.vs_project, '/wrong/path/to/cmake')

        # CMakeLists.txt is created in the current directory
        self.assertEqual('CMakeLists.txt', under_test.data['cmake'].name)
    def test_close_cmake_file(self):
        """Close CMake File"""

        under_test = DataConverter(self.data_test)

        under_test.init_files(self.vs_project, '')
        under_test.create_data()

        self.assertFalse(under_test.data['cmake'].closed)

        under_test.close_cmake_file()

        self.assertTrue(under_test.data['cmake'].closed)
Ejemplo n.º 7
0
    def test_create_data(self):
        """Data Converter Create Data"""

        data_test = {
            'cmake': None,
            'cmake_output': None,
            'vcxproj': None,
            'dependencies': None,
            'includes': None,
            'additional_code': None,
        }

        under_test = DataConverter(data_test)
        self.assertTrue(under_test.data)

        under_test.init_files(self.vs_project, '')

        old_cmake = open('CMakeLists.txt', 'r')

        under_test.create_data()

        new_cmake = open('CMakeLists.txt', 'r')

        # Assert content is not the same after
        self.assertEqual(old_cmake.read(), new_cmake.read())

        old_cmake.close()
        new_cmake.close()
Ejemplo n.º 8
0
    def test_create_data(self):
        """Data Converter Create Data"""

        # FIXME: No such file or directory: 'CMakeLists.txt'
        return

        under_test = DataConverter()

        context = VSContext()
        context.init(self.vs_project, self.cur_dir)

        old_cmake = open('CMakeLists.txt', 'r')

        under_test.convert(context)

        new_cmake = open('CMakeLists.txt', 'r')

        # Assert content is not the same after
        self.assertEqual(old_cmake.read(), new_cmake.read())

        old_cmake.close()
        new_cmake.close()
Ejemplo n.º 9
0
    def test_close_cmake_file(self):
        """Close CMake File"""

        under_test = DataConverter(self.data_test)

        under_test.init_files(self.vs_project, '')
        under_test.create_data()

        self.assertFalse(under_test.data['cmake'].closed)

        under_test.close_cmake_file()

        self.assertTrue(under_test.data['cmake'].closed)
    def test_create_data(self):
        """Data Converter Create Data"""

        under_test = DataConverter(self.data_test)
        self.assertTrue(under_test.data)

        under_test.init_files(self.vs_project, self.cur_dir)

        old_cmake = open('CMakeLists.txt', 'r')

        under_test.create_data()
        under_test.close_cmake_file()

        new_cmake = open('CMakeLists.txt', 'r')

        # Assert content is not the same after
        self.assertEqual(old_cmake.read(), new_cmake.read())

        old_cmake.close()
        new_cmake.close()
Ejemplo n.º 11
0
    def test_close_cmake_file(self):
        """Close CMake File"""

        data_test = {
            'cmake': None,
            'cmake_output': None,
            'vcxproj': None,
            'dependencies': None,
            'includes': None,
            'additional_code': None,
        }
        under_test = DataConverter(data_test)

        under_test.init_files(self.vs_project, '')
        under_test.create_data()

        self.assertFalse(under_test.data['cmake'].closed)

        under_test.close_cmake_file()

        self.assertTrue(under_test.data['cmake'].closed)
Ejemplo n.º 12
0
    def test_create_data(self):
        """Data Converter Create Data"""

        under_test = DataConverter(self.data_test)
        self.assertTrue(under_test.data)

        under_test.init_files(self.vs_project, self.cur_dir)

        old_cmake = open('CMakeLists.txt', 'r')

        under_test.create_data()
        under_test.close_cmake_file()

        new_cmake = open('CMakeLists.txt', 'r')

        # Assert content is not the same after
        self.assertEqual(old_cmake.read(), new_cmake.read())

        old_cmake.close()
        new_cmake.close()
Ejemplo n.º 13
0
def convert_project(data, vcxproj, cmake_lists):
    """
    Convert a ``vcxproj`` to a ``CMakeLists.txt``

    :param data: input data of user
    :type data: dict
    :param vcxproj: input vcxproj
    :type vcxproj: str
    :param cmake_lists: destinaton folder of CMakeLists.txt
    :type cmake_lists: str
    """

    _, proj = os.path.split(vcxproj)
    message('---> Convert a new project: [%s] ---' % proj, 'done')

    # Give data to DataConverter()
    data_converter = DataConverter(data)
    data_converter.init_files(vcxproj, cmake_lists)
    data_converter.create_data()

    # Close CMake file
    data_converter.close_cmake_file()

    message('---> Project [%s] is converted ! ---\n' % proj, 'ok')
Ejemplo n.º 14
0
def main():  # pragma: no cover
    """
    Define arguments and send to DataConverter()

    """

    data = {
        'vcxproj': None,
        'cmake': None,
        'additional_code': None,
        'includes': None,
        'dependencies': None,
        'cmake_output': None,
        'data': None,
        'std': None
    }

    usage = "cmake-converter -p <vcxproj>"
    # Init parser
    parser = argparse.ArgumentParser(
        usage=usage,
        description=
        'Convert Visual Studio projects (.vcxproj) to CMakeLists.txt')
    parser.add_argument(
        '-p',
        '--project',
        help='[required] valid vcxproj file. i.e.: ../../mylib.vcxproj',
        dest='project')
    parser.add_argument('-c',
                        '--cmake',
                        help='define output of CMakeLists.txt file',
                        dest='cmake')
    parser.add_argument(
        '-a',
        '--additional',
        help='import cmake code from file.cmake to your final CMakeLists.txt',
        dest='additional')
    parser.add_argument(
        '-D',
        '--dependencies',
        help='replace dependencies found in .vcxproj, separated by colons. '
        'i.e.: external/zlib/cmake/:../../external/g3log/cmake/',
        dest='dependencies')
    parser.add_argument('-O',
                        '--cmakeoutput',
                        help='define output of artefact produces by CMake.',
                        dest='cmakeoutput')
    parser.add_argument(
        '-i',
        '--include',
        help='add include directories in CMakeLists.txt. Default : False',
        dest='include',
        action="store_true",
        default=False)
    parser.add_argument('-std',
                        '--std',
                        help='choose your C++ std version. Default : c++11',
                        dest='std')

    # Get args
    args = parser.parse_args()

    # Prepare data
    if not args.project:
        parser.print_help()
        exit(0)

    data['additional_code'] = args.additional
    if args.dependencies is not None:
        data['dependencies'] = args.dependencies.split(':')
    data['cmake_output'] = args.cmakeoutput
    data['includes'] = args.include

    if args.std:
        data['std'] = args.std

    # Give data to ConvertData()
    data_converter = DataConverter(data)
    data_converter.init_files(args.project, args.cmake)
    data_converter.create_data()

    # Close CMake file
    data_converter.close_cmake_file()