示例#1
0
    def testAppend(self):
        """Tests the Append function."""
        configurations = resources.VSConfigurations()

        configuration = resources.VSSolutionConfiguration(name='test',
                                                          platform='Win32')
        configurations.Append(configuration)
示例#2
0
    def testExtendWithX64(self):
        """Tests the ExtendWithX64 function."""
        configurations = resources.VSConfigurations()

        configuration = resources.VSSolutionConfiguration(name='test',
                                                          platform='Win32')
        configurations.Append(configuration)

        configurations.ExtendWithX64('2010')
示例#3
0
    def testGetSorted(self):
        """Tests the GetSorted function."""
        configurations = resources.VSConfigurations()

        configuration = resources.VSSolutionConfiguration(name='test',
                                                          platform='Win32')
        configurations.Append(configuration)

        sorted_configurations = list(configurations.GetSorted())
        self.assertEqual(len(sorted_configurations), 1)
示例#4
0
    def testGetByIdentifier(self):
        """Tests the GetByIdentifier function."""
        configurations = resources.VSConfigurations()

        configuration = resources.VSSolutionConfiguration(name='test',
                                                          platform='Win32')
        configurations.Append(configuration)

        configuration = configurations.GetByIdentifier('test', 'Win32')
        self.assertIsNotNone(configuration)
示例#5
0
文件: writers.py 项目: libyal/vstools
  def testWriteProjectConfigurations(self):
    """Tests the WriteProjectConfigurations function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteProjectConfigurations(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertEqual(output_data, b'')
示例#6
0
文件: writers.py 项目: libyal/vstools
  def testWriteOutIntDirConditions(self):
    """Tests the _WriteOutIntDirConditions function."""
    configuration_name = 'Release'
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2015ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteOutIntDirConditions(
        configuration_name, project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertEqual(output_data, b'')
示例#7
0
文件: writers.py 项目: libyal/vstools
  def testWriteProjectConfigurations(self):
    """Tests the WriteProjectConfigurations function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2010ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteProjectConfigurations(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'  <ItemGroup Label="ProjectConfigurations">\r\n'
        b'  </ItemGroup>\r\n')
    self.assertEqual(output_data, expected_output_data)
示例#8
0
文件: writers.py 项目: libyal/vstools
  def testWriteConfigurations(self):
    """Tests the WriteConfigurations function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2010ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteConfigurations(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertTrue(output_data.startswith(
        b'  <Import Project="$(VCTargetsPath)\\'
        b'Microsoft.Cpp.Default.props" />\r\n'))
    self.assertTrue(output_data.endswith(b'  </PropertyGroup>\r\n'))
示例#9
0
文件: writers.py 项目: libyal/vstools
  def testWriteOutIntDirPropertyGroups(self):
    """Tests the _WriteOutIntDirPropertyGroups function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2012ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer._WriteOutIntDirPropertyGroups(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'  <PropertyGroup>\r\n'
        b'    <_ProjectFileVersion>11.0.61030.0</_ProjectFileVersion>\r\n'
        b'  </PropertyGroup>\r\n')
    self.assertEqual(output_data, expected_output_data)
示例#10
0
文件: writers.py 项目: libyal/vstools
  def testWriteConfigurations(self):
    """Tests the WriteConfigurations function."""
    project_configurations = resources.VSConfigurations()

    file_writer = writers.VS2008ProjectFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteConfigurations(project_configurations)

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    self.assertTrue(output_data.startswith(b'\t<Configurations>\r\n'))
    self.assertTrue(output_data.endswith(
        b'\t</Configurations>\r\n'
        b'\t<References>\r\n'
        b'\t</References>\r\n'))
示例#11
0
文件: readers.py 项目: libyal/vstools
    def ReadConfigurations(self):
        """Reads the configurations.

    Returns:
      VSConfigurations: configurations or None if not available.
    """
        solution_configurations = resources.VSConfigurations()

        line = self._ReadLine(look_ahead=True)
        if not line or line != 'Global':
            return None

        found_section = False

        line = self._ReadLine()

        while line and line != 'EndGlobal':
            line = self._ReadLine()

            if found_section:
                if line == 'EndGlobalSection':
                    found_section = False

                else:
                    # For more than 1 match findall will return a list with a tuple.
                    values = re.findall(
                        '([^|]*)[|]([^ ]*) = ([^|]*)[|]([^ ]*)', line)

                    if len(values) == 1:
                        values = values[0]
                        if (len(values) == 4 and values[0] == values[2]
                                and values[1] == values[3]):
                            configuration = resources.VSSolutionConfiguration()
                            configuration.name = values[0]
                            configuration.platform = values[1]

                            solution_configurations.Append(configuration)

            elif line == ('GlobalSection(SolutionConfigurationPlatforms) = '
                          'preSolution'):
                found_section = True

        return solution_configurations
示例#12
0
文件: writers.py 项目: libyal/vstools
  def testWriteConfigurations(self):
    """Tests the WriteConfigurations function."""
    solution_configurations = resources.VSConfigurations()
    solution_project = resources.VSSolutionProject('name', 'filename', 'guid')

    file_writer = writers.VS2010SolutionFileWriter()

    file_writer._file = io.BytesIO()

    file_writer.WriteConfigurations(solution_configurations, [solution_project])

    file_writer._file.seek(0, os.SEEK_SET)
    output_data = file_writer._file.read()

    expected_output_data = (
        b'Global\r\n'
        b'\tGlobalSection(SolutionProperties) = preSolution\r\n'
        b'\t\tHideSolutionNode = FALSE\r\n'
        b'\tEndGlobalSection\r\n'
        b'EndGlobal\r\n')
    self.assertEqual(output_data, expected_output_data)
示例#13
0
 def testNumberOfConfigurations(self):
     """Tests the number_of_configurations property."""
     configurations = resources.VSConfigurations()
     self.assertEqual(configurations.number_of_configurations, 0)
示例#14
0
 def testInitialize(self):
     """Tests the __init__ function."""
     configurations = resources.VSConfigurations()
     self.assertIsNotNone(configurations)
示例#15
0
文件: libyal.py 项目: libyal/vstools
  def Convert(self, input_directory, output_version):
    """Converts a Visual Studio solution.

    Args:
      input_directory (str): path of the input directory.
      output_version (str): output Visual Studio version.

    Returns:
      bool: True if the conversion successful or False if not.
    """
    configure_ac_path = os.path.join(input_directory, 'configure.ac')
    if not os.path.exists(configure_ac_path):
      logging.warning('No such file: {0:s}.'.format(configure_ac_path))
      return False

    solution_name = None
    # pylint: disable=consider-using-with
    file_object = io.open(configure_ac_path, 'r', encoding='utf8')

    in_ac_init_section = False

    for line in file_object.readlines():
      line = line.strip()

      if in_ac_init_section:
        if line.startswith('[') and line.endswith('],'):
          solution_name = line[1:-2]
        break

      if line.startswith('AC_INIT('):
        in_ac_init_section = True

    file_object.close()

    if not solution_name:
      logging.warning('Unable to determine solution name.')
      return False

    # Use the existing msvscpp solution file to determine the project
    # GUID so that they can be reused.
    project_guids_by_name = {}

    input_sln_path = os.path.join(
        input_directory, 'msvscpp', '{0:s}.sln'.format(solution_name))
    if os.path.exists(input_sln_path):
      solution_reader = readers.VS2008SolutionFileReader()
      solution_reader.Open(input_sln_path)

      if not solution_reader.ReadHeader():
        logging.warning('Unable to read solution file: {0:s} header.'.format(
            input_sln_path))
        return False

      solution_projects = solution_reader.ReadProjects()
      solution_reader.Close()

      for solution_project in solution_projects:
        project_guids_by_name[solution_project.name] = solution_project.guid

    solution_projects = []
    projects_by_guid = {}

    for directory_entry in os.listdir(input_directory):
      if not os.path.isdir(directory_entry):
        continue

      if (not directory_entry.startswith('lib') and
          not directory_entry.startswith('py') and
          directory_entry not in ('src', 'tests') and
          not directory_entry.endswith('.net') and
          not directory_entry.endswith('tools')):
        continue

      # Ignore the Python version specific build directories.
      if (directory_entry.startswith('py') and (
          directory_entry.endswith('2') or
          directory_entry.endswith('3') or
          not self._generate_python_dll)):
        continue

      makefile_am_path = os.path.join(
          input_directory, directory_entry, 'Makefile.am')
      if not os.path.exists(makefile_am_path):
        logging.warning('No such file: {0:s}.'.format(makefile_am_path))
        continue

      if (directory_entry in ('src', 'tests') or
          directory_entry.endswith('tools')):
        project_names = self._ReadMakefilePrograms(makefile_am_path)
      else:
        project_names = [directory_entry]

      for project_name in project_names:
        project_filename = '{0:s}\\{0:s}'.format(project_name)

        project_guid = project_guids_by_name.get(project_name, '')
        if not project_guid:
          project_guid = project_guids_by_name.get(
              '{0:s}.dll'.format(project_name), '')
        if not project_guid:
          project_guid = str(uuid.uuid4())

        solution_project = resources.VSSolutionProject(
            project_name, project_filename, project_guid)

        solution_projects.append(solution_project)

        project_information = resources.VSProjectInformation()
        project_information.name = project_name
        project_information.guid = project_guid
        project_information.root_name_space = project_name

        if project_name == solution_name:
          release_project_configuration = ReleaseDllVSProjectConfiguration()
          debug_project_configuration = VSDebugDllVSProjectConfiguration()

        elif project_name.endswith('.net'):
          release_project_configuration = (
              ReleaseDotNetDllVSProjectConfiguration())
          debug_project_configuration = VSDebugDotNetDllVSProjectConfiguration()

        elif project_name.startswith('py'):
          release_project_configuration = (
              ReleasePythonDllVSProjectConfiguration(
                  python_path=self._python_path))
          debug_project_configuration = VSDebugPythonDllVSProjectConfiguration(
              python_path=self._python_path)

        elif project_name.startswith('lib'):
          release_project_configuration = ReleaseLibraryVSProjectConfiguration()
          debug_project_configuration = VSDebugLibraryVSProjectConfiguration()

        else:
          project_information.keyword = 'Win32Proj'

          release_project_configuration = ReleaseExeVSProjectConfiguration()
          debug_project_configuration = VSDebugExeVSProjectConfiguration()

        # TODO: determine autogenerated source.

        self._ReadMakefile(
            makefile_am_path, solution_name, project_information,
            release_project_configuration, debug_project_configuration)

        # TODO: add additional Python 3 project.

        project_information.configurations.Append(release_project_configuration)
        if debug_project_configuration:
          project_information.configurations.Append(debug_project_configuration)

        projects_by_guid[project_guid] = project_information

    self._CreateThirdPartyDependencies(
        solution_projects, projects_by_guid, project_guids_by_name)

    # Set-up the solution configurations.
    solution_configurations = resources.VSConfigurations()

    solution_configuration = resources.VSSolutionConfiguration(
        name='Release', platform='Win32')
    solution_configurations.Append(solution_configuration)

    solution_configuration = resources.VSSolutionConfiguration(
        name='VSDebug', platform='Win32')
    solution_configurations.Append(solution_configuration)

    if output_version not in ['2008']:
      # Add x64 as a platform.
      solution_configurations.ExtendWithX64(output_version)

    # Create some look-up dictionaries.
    solution_project_guids_by_name = {}
    solution_projects_by_guid = {}
    for solution_project in solution_projects:
      solution_project_guids_by_name[solution_project.name] = (
          solution_project.guid)
      solution_projects_by_guid[solution_project.guid] = solution_project

    # Set-up the solution dependencies.
    for guid, project_information in projects_by_guid.items():
      solution_project = solution_projects_by_guid[guid]

      for dependency in project_information.dependencies:
        if dependency in ['pthread']:
          continue

        dependency_guid = solution_project_guids_by_name.get(dependency, '')
        if not dependency_guid:
          logging.info('Missing GUID for dependency: {0:s}'.format(dependency))

        solution_project.AddDependency(dependency_guid)

    solution_filename = '{0:s}.sln'.format(solution_name)
    self._WriteSolution(
        solution_filename, output_version, solution_projects,
        solution_configurations)

    for solution_project in solution_projects:
      project_information = projects_by_guid[solution_project.guid]
      self._WriteProject(
          output_version, solution_project, project_information,
          solution_projects_by_guid)

    # Create the corresponding Makefile.am
    solution_project_filenames = []
    for solution_project in solution_projects:
      if output_version in ['2008']:
        solution_project_extension = 'vcproj'
      else:
        solution_project_extension = 'vcxproj'

      path_segments = solution_project.filename.split('\\')
      solution_project_filenames.append('\t{0:s}.{1:s} \\'.format(
          os.path.join(*path_segments), solution_project_extension))

    makefile_am_lines = ['MSVSCPP_FILES = \\']
    for solution_project_filename in sorted(solution_project_filenames):
      makefile_am_lines.append(solution_project_filename)

    makefile_am_lines.append('\t{0:s}'.format(solution_filename))

    makefile_am_lines.extend([
        '',
        'EXTRA_DIST = \\',
        '\t$(MSVSCPP_FILES)',
        '',
        'MAINTAINERCLEANFILES = \\',
        '\tMakefile.in',
        '',
        'distclean: clean',
        '\t/bin/rm -f Makefile',
        '',
        ''])

    filename = os.path.join('vs{0:s}'.format(output_version), 'Makefile.am')
    logging.info('Writing: {0:s}'.format(filename))

    with io.open(filename, 'w', encoding='utf8') as makefile_am:
      lines = '\n'.join(makefile_am_lines)
      makefile_am.write(lines)

    return True