<commit_before>{ xcodeWrapper, lib }:

#
# This is a collection of various utilities used throught this repo.
#

let
  RED = "\\033[0;31m";
  GREEN = "\\033[0;32m";
  NC = "\\033[0m";

  _xcodeToolsTest = ''
    xcode=0
    iPhoneSDK=0
    export PATH=${xcodeWrapper}/bin:$PATH
    xcrun xcodebuild -version && xcode=1
    [ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1
  '';
  _xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[√] ${tool-name}${RED}"'';
  _xcodeToolsReportScript = ''
    echo -e "${RED}There are some required tools missing in the system:"
    export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"}
    export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"}
  '';
  _xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name;

  enforceXCodeAvailable = ''
    ${_xcodeToolsTest}
    if [ $xcode -eq 0 ]; then
      ${_xcodeToolsReportScript}
      echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}"
      exit 1
    fi
  '';

  enforceiPhoneSDKAvailable = ''
    ${_xcodeToolsTest}
    if [ $iPhoneSDK -eq 0 ]; then
      ${_xcodeToolsReportScript}
      if [ $xcode -eq 1 ]; then
        echo -e "Please install the iPhone SDK in Xcode.${NC}""
      else
        echo -e "Please install Xcode ${_xcodeVersion} from the App Store, and then the iPhone SDK.${NC}""
      fi
      exit 1
    fi
  '';

  # paths don't like slashes in them
  dropSlashes = builtins.replaceStrings [ "/" ] [ "_" ];
  # if version doesn't match this it's probably a commit, it's lax semver
  versionRegex = "^v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+[[:alnum:]_.-]*$";
  sanitizeVersion = version:
    if (builtins.match versionRegex version) != null
    # Geth forces a 'v' prefix for all versions
    then lib.removePrefix "v" (dropSlashes version) 
    # reduce metrics cardinality in Prometheus<commit_msg>nix: make status-go version regex even more lax<commit_after>{ xcodeWrapper, lib }:

#
# This is a collection of various utilities used throught this repo.
#

let
  RED = "\\033[0;31m";
  GREEN = "\\033[0;32m";
  NC = "\\033[0m";

  _xcodeToolsTest = ''
    xcode=0
    iPhoneSDK=0
    export PATH=${xcodeWrapper}/bin:$PATH
    xcrun xcodebuild -version && xcode=1
    [ $xcode -eq 1 ] && xcrun --sdk iphoneos --show-sdk-version > /dev/null && iPhoneSDK=1
  '';
  _xcodeToolReportScript = tool-name: ''[ $SELECTED -eq 0 ] && echo -e "${NC}- ${RED}[ ] ${tool-name}" || echo -e "${NC}- ${GREEN}[√] ${tool-name}${RED}"'';
  _xcodeToolsReportScript = ''
    echo -e "${RED}There are some required tools missing in the system:"
    export SELECTED=$xcode; ${_xcodeToolReportScript "Xcode ${_xcodeVersion}"}
    export SELECTED=$iPhoneSDK; ${_xcodeToolReportScript "iPhone SDK"}
  '';
  _xcodeVersion = builtins.replaceStrings ["xcode-wrapper-"] [""] xcodeWrapper.name;

  enforceXCodeAvailable = ''
    ${_xcodeToolsTest}
    if [ $xcode -eq 0 ]; then
      ${_xcodeToolsReportScript}
      echo -e "Please install Xcode ${_xcodeVersion} from the App Store.${NC}"
      exit 1
    fi
  '';

  enforceiPhoneSDKAvailable = ''
    ${_xcodeToolsTest}
    if [ $iPhoneSDK -eq 0 ]; then
      ${_xcodeToolsReportScript}
      if [ $xcode -eq 1 ]; then
        echo -e "Please install the iPhone SDK in Xcode.${NC}""
      else
        echo -e "Please install Xcode ${_xcodeVersion} from the App Store, and then the iPhone SDK.${NC}""
      fi
      exit 1
    fi
  '';

  # paths don't like slashes in them
  dropSlashes = builtins.replaceStrings [ "/" ] [ "_" ];
  # if version doesn't match this it's probably a commit, it's lax semver
  versionRegex = "^v?[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+[[:alnum:]+_.-]*$";
  sanitizeVersion = version:
    if (builtins.match versionRegex version) != null
    # Geth forces a 'v' prefix for all versions
    then lib.removePrefix "v" (dropSlashes version) 
    # reduce metrics cardinality in Prometheus
{'fraction_non_alphanumeric': 0.15622678880911117, 'fraction_numerical': 0.01336964595196831, 'mean_word_length': 3.248159831756046, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2054121', 'n_tokens_mistral': 1445, 'n_tokens_neox': 1353, 'n_words': 386}