<commit_before>__all__ = ["MsvcCompiler"]

import os
import os.path
import subprocess
import tempfile
import re
import threading

import cake.filesys
import cake.path
from cake.tools.compilers import Compiler, makeCommand
from cake.tools import memoise
from cake.task import Task
from cake.msvs import getMsvcProductDir, getMsvsInstallDir, getPlatformSdkDir

def findCompiler(architecture='x86'):
  """Returns an MSVC compiler given an architecture.
  
  Raises an EnvironmentError if a compiler or matching platform SDK
  cannot be found.
  
  @param architecture: The machine architecture to compile for.
  """
  versions = [
    r'VisualStudio\8.0',
    r'VCExpress\9.0',
    ]
  
  for version in versions:
    try:
      msvcProductDir = getMsvcProductDir(version)
      msvsInstallDir = getMsvsInstallDir(version)
    
      # Use the compilers platform SDK if installed
      platformSdkDir = cake.path.join(msvcProductDir, "PlatformSDK")
      if not cake.filesys.isDirectory(platformSdkDir):
        platformSdkDir = getPlatformSdkDir()

      # Break when we find the compiler dirs
      break
    except WindowsError:
      if version is versions[-1]:
        raise EnvironmentError(
          "Could not find Microsoft Visual Studio C++ compiler."
          )
  
  clExe = cake.path.join(msvcProductDir, "bin", "cl.exe")
  libExe = cake.path.join(msvcProductDir, "bin", "lib.exe")
  linkExe = cake.path.join(msvcProductDir, "bin", "link.exe")
  dllPaths = [msvsInstallDir]
    
  compiler = MsvcCompiler(
    clExe,
    libExe,
    linkExe,
    dllPaths,
    architecture<commit_msg>updated findCompiler() to allow finding a specific version<commit_after>__all__ = ["MsvcCompiler"]

import os
import os.path
import subprocess
import tempfile
import re
import threading

import cake.filesys
import cake.path
from cake.tools.compilers import Compiler, makeCommand
from cake.tools import memoise
from cake.task import Task
from cake.msvs import getMsvcProductDir, getMsvsInstallDir, getPlatformSdkDir

def findCompiler(version=None, architecture='x86'):
  """Returns an MSVC compiler given a version and architecture.
  
  Raises an EnvironmentError if a compiler or matching platform SDK
  cannot be found.
  
  @param version: The specific version to find. If version is None the
  latest version is found instead. 
  @param architecture: The machine architecture to compile for.
  """
  if version is not None:
    versions = [version]
  else:
    # Prefer later versions over earlier ones
    versions = [
      '9.0',
      '8.0',
      ]

  # Prefer Enterprise edition over Express
  editions = [
    'VisualStudio',
    'VCExpress',
    ]

  for v in versions:
    found = False
    for e in editions:
      try:
        registryPath = e + '\\' + v
        msvcProductDir = getMsvcProductDir(registryPath)
        msvsInstallDir = getMsvsInstallDir(registryPath)
      
        # Use the compilers platform SDK if installed
        platformSdkDir = cake.path.join(msvcProductDir, "PlatformSDK")
        if not cake.filesys.isDirectory(platformSdkDir):
          platformSdkDir = getPlatformSdkDir()

        # Break when we have found all compiler dirs
        found = True
        break
      except WindowsError:
        # Try the next version/edition
        continue
    if found:
      break
  else:
    raise EnvironmentError(
      "Could not find Microsoft Visual Studio C++ compiler."
      )
  
  clExe = cake.path.join(msvcProductDir, "bin", "cl.exe")
  libExe = cake.path.join(msvcProductDir, "bin", "lib.exe")
  linkExe = cake.path.join(msvcProductDir, "bin", "link.exe")
  dllPaths = [msvsInstallDir]
    
  compiler = MsvcCompiler(
    clExe,
    libExe,
    linkExe,
    dllPaths,
    architecture
{'fraction_non_alphanumeric': 0.07937784928935371, 'fraction_numerical': 0.0034861893268972916, 'mean_word_length': 3.1629464285714284, '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': '500626', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1110, 'n_words': 345}