<commit_before>import os, strutils

import nimblepkg/[version, cli, tools]

import options, download, utils

proc buildFromCSources() =
  when defined(windows):
    doCmd("build.bat")
    # TODO: How should we handle x86 vs amd64?
  else:
    doCmd("sh build.sh")

proc buildCompiler() =
  ## Assumes that CWD contains the compiler (``build`` should have changed it).
  let binDir = getCurrentDir() / "bin"
  if fileExists(binDir / "nim".addFileExt(ExeExt)):
    display("Compiler: ", "Already built", priority = HighPriority)
    return

  if fileExists(getCurrentDir() / "build.sh"):
    buildFromCSources()
  else:
    display("Warning:", "Building from latest C sources. They may not be " &
                        "compatible with the Nim version you have chosen to " &
                        "install.", Warning, HighPriority)
    let path = downloadCSources()
    let extractDir = getCurrentDir() / "csources"
    extract(path, extractDir)

    display("Building", "C sources", priority = HighPriority)
    setCurrentDir(extractDir) # cd csources
    buildFromCSources() # sh build.sh
    setCurrentDir(extractDir.parentDir()) # cd ..
    when defined(windows):
      display("Building", "koch", priority = HighPriority)
      doCmd("bin/nim.exe c koch")
      display("Building", "Nim", priority = HighPriority)
      doCmd("koch.exe boot -d:release")
    else:
      display("Building", "koch", priority = HighPriority)
      doCmd("./bin/nim c koch")
      display("Building", "Nim", priority = HighPriority)
      doCmd("./koch boot -d:release")

proc buildTools() =
  ## Assumes that CWD contains the compiler.
  let binDir = getCurrentDir() / "bin"
  # TODO: I guess we should check for the other tools too?
  if fileExists(binDir / "nimble".addFileExt(ExeExt)):
    display("Tools: ", "Already built", priority = HighPriority)
    return

  if fileExists(getCurrentDir() / "build.sh"):
    when defined(windows):
      doCmd("bin/nim c koch")
      doCmd("koch tools")
    else:
      doCmd("./bin/nim c koch")
      doCmd("./koch tools")

proc build*(extractDir: string, version: Version) =
  let currentDir = getCurrentDir()
  setCurrentDir(extractDir)
  defer:
    setCurrentDir(currentDir)

  display("Building", "Nim " & $version, priority = HighPriority)
  buildCompiler()
  buildTools()


<commit_msg>Build tools when building from GitHub too.<commit_after>import os, strutils

import nimblepkg/[version, cli, tools]

import options, download, utils

proc buildFromCSources() =
  when defined(windows):
    doCmd("build.bat")
    # TODO: How should we handle x86 vs amd64?
  else:
    doCmd("sh build.sh")

proc buildCompiler() =
  ## Assumes that CWD contains the compiler (``build`` should have changed it).
  let binDir = getCurrentDir() / "bin"
  if fileExists(binDir / "nim".addFileExt(ExeExt)):
    display("Compiler: ", "Already built", priority = HighPriority)
    return

  if fileExists(getCurrentDir() / "build.sh"):
    buildFromCSources()
  else:
    display("Warning:", "Building from latest C sources. They may not be " &
                        "compatible with the Nim version you have chosen to " &
                        "install.", Warning, HighPriority)
    let path = downloadCSources()
    let extractDir = getCurrentDir() / "csources"
    extract(path, extractDir)

    display("Building", "C sources", priority = HighPriority)
    setCurrentDir(extractDir) # cd csources
    buildFromCSources() # sh build.sh
    setCurrentDir(extractDir.parentDir()) # cd ..
    when defined(windows):
      display("Building", "koch", priority = HighPriority)
      doCmd("bin/nim.exe c koch")
      display("Building", "Nim", priority = HighPriority)
      doCmd("koch.exe boot -d:release")
    else:
      display("Building", "koch", priority = HighPriority)
      doCmd("./bin/nim c koch")
      display("Building", "Nim", priority = HighPriority)
      doCmd("./koch boot -d:release")

proc buildTools() =
  ## Assumes that CWD contains the compiler.
  let binDir = getCurrentDir() / "bin"
  # TODO: I guess we should check for the other tools too?
  if fileExists(binDir / "nimble".addFileExt(ExeExt)):
    display("Tools: ", "Already built", priority = HighPriority)
    return

  let msg = "tools (nimble, nimgrep, nimsuggest)"
  display("Building", msg, priority = HighPriority)
  if fileExists(getCurrentDir() / "build.sh"):
    when defined(windows):
      doCmd("bin/nim c koch")
      doCmd("koch.exe tools -d:release")
    else:
      doCmd("./bin/nim c koch")
      doCmd("./koch tools -d:release")
  else:
    when defined(windows):
      doCmd("koch.exe tools -d:release")
    else:
      doCmd("./koch tools -d:release")

proc build*(extractDir: string, version: Version) =
  let currentDir = getCurrentDir()
  setCurrentDir(extractDir)
  defer:
    setCurrentDir(currentDir)

  display("Building", "Nim " & $version, priority = HighPriority)
  buildCompiler()
  buildTools()



{'fraction_non_alphanumeric': 0.13027597402597402, 'fraction_numerical': 0.0016233766233766235, 'mean_word_length': 3.3852313167259784, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3483881', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1496, 'n_words': 426}