<commit_before>#!/usr/bin/env python

# Copyright (c) 2014, <NAME>
# All rights reserved.

import argparse
import os
import re
import shutil
import subprocess
import sys
import detail.util

# Note: python 2.7 compatible (For jenkins plug-in)

parser = argparse.ArgumentParser(description="Script for building")
parser.add_argument(
    '--toolchain',
    choices=[
        'default',
        'libcxx',
        'xcode',
        'clang_libstdcxx',
        'gcc48',
        'gcc',
        'vs2013x64',
        'vs2013',
        'analyze',
        'sanitize_address',
        'sanitize_leak',
        'sanitize_memory',
        'sanitize_thread',
        'cygwin',
        'mingw',
        'ios',
        'ios-nocodesign',
        'nmake-vs2013-x64'
    ],
    help="CMake generator/toolchain",
)

parser.add_argument(
    '--config',
    help="CMake build type (Release, Debug, ...)",
)

parser.add_argument('--test', action='store_true', help="Run ctest after build")
parser.add_argument(
    '--nobuild', action='store_true', help="Do not build (only generate)"
)
parser.add_argument(
    '--open', action='store_true', help="Open generated project (for IDE)"
)
parser.add_argument('--verbose', action='store_true', help="Verbose output")
parser.add_argument('--install', action='store_true', help="Run install")
parser.add_argument(
    '--clear', action='store_true', help="Remove build and install dirs"
)
parser.add_argument(
    '--fwd',
    nargs='*',
    help="Arguments to cmake without '-D', like:\nBOOST_ROOT=/some/path"
)
parser.add_argument(
    '--iossim',
    action='store_true',
    help="Build for ios i386 simulator"
)

args = parser.parse_args()

generator = ''

"""Toolchain name"""
polly_toolchain = ''
if args.toolchain:
  polly_toolchain = args.toolchain
else:
  polly_toolchain = 'default'

if args.toolchain == 'vs2013x64':
  polly_toolchain = 'vs-12-2013-win64'
elif args.toolchain == 'vs2013':
  polly_toolchain = 'vs-12-2013'

"""Build directory tag"""
multi_config_dir = False
if args.toolchain == 'vs2013x64':
  multi_config_dir = True
elif args.toolchain == 'vs2013':
  multi_config_dir = True
elif args.toolchain == 'xcode':
  multi_config_dir = True

if args.config and not multi_config_dir:
  build_tag = "{}-{}".format(polly_toolchain, args.config)
else:
  build_tag = polly_toolchain

"""Generator"""
if args.toolchain == 'vs2013x64':
  generator = '-GVisual Studio 12 2013 Win64'
elif args.toolchain == 'vs2013':
  generator = '-GVisual Studio 12 2013'
elif args.toolchain == 'xcode':
  generator = '-GXcode'
elif args.toolchain == 'ios':
  generator = '-GXcode'
elif args.toolchain == 'ios-nocodesign':
  generator = '-GXcode'
elif args.toolchain == 'mingw':
  generator = '-GMinGW Makefiles'
elif args.toolchain == 'nmake-vs2013-x64':
  generator = '-GNMake Makefiles'

"""Tune environment"""
if args.toolchain == 'mingw':
  mingw_path = os.getenv("MINGW_PATH")
  if not mingw_path:
    sys.exit(
        "Please set environment variable MINGW_PATH "
        "to directory with mingw32-make.exe"
    )
  if not os.path.isdir(mingw_path):
    sys.exit("MINGW_PATH({}) is not a directory".format(mingw_path))

  mingw_make = os.path.join(mingw_path, 'mingw32-make.exe')
  if not os.path.isfile(mingw_make):
    sys.exit(
        "File mingw32-make.exe not found in "
        "directory `{}` (MINGW_PATH environment variable)".format(mingw_path)
    )
  os.environ['PATH'] = "{};{}".format(mingw_path, os.getenv('PATH'))

if args.toolchain == 'nmake-vs2013-x64':
  vs_path = os.getenv('VS120COMNTOOLS')
  if not vs_path:
    sys.exit(
        'Environment variable VS120COMNTOOLS is empty, '
        'looks like Visual Studio 2013 is not installed'
    )
  vcvarsall_dir = os.path.join(vs_path, '..', '..', 'VC')
  if not os.path.isdir(vcvarsall_dir):
    sys.exit(
        'Directory `{}` not exists '
        '(VS120COMNTOOLS environment variable)'.format(vcvarsall_dir)
    )
  vcvarsall_path = os.path.join(vcvarsall_dir, 'vcvarsall.bat')
  if not os.path.isfile(vcvarsall_path):
    sys.exit(
        'File vcvarsall.bat not found in directory '
        '`{}` (VS120COMNTOOLS_ environment variable)'.format(vcvarsall_dir)
    )
  new_env = detail.util.get_environment_from_batch_command([vcvarsall_path, 'amd64'])
  os.environ = new_env

cdir = os.getcwd()

# workaround for version less that 3.3
DEVNULL = open(os.devnull, 'w')

def call(call_args):
  try:
    print('Execute command: [')
    for i in call_args:
      print('  `{}`'.format(i))
    print(']')
    if not args.verbose:
      subprocess.check_call(
          call_args,
          stdout=DEVNULL,
          stderr=DEVNULL,
          universal_newlines=True,
          env=os.environ
      )
    else:
      subprocess.check_call(
          call_args,
          universal_newlines=True,
          env=os.environ
      )
  except subprocess.CalledProcessError as error:
    print(error)
    print(error.output)
    sys.exit(1)

call(['cmake', '--version'])

polly_root = os.getenv("POLLY_ROOT")
if not polly_root:
  sys.exit("Environment variable `POLLY_ROOT` is empty")

toolchain_path = os.path.join(polly_root, "{}.cmake".format(polly_toolchain))
toolchain_option = "-DCMAKE_TOOLCHAIN_FILE={}".format(toolchain_path)

build_dir = os.path.join(cdir, '_builds', build_tag)
build_dir_option = "-B{}".format(build_dir)

install_dir = os.path.join(cdir, '_install', polly_toolchain)
if args.install:
  install_dir_option = "-DCMAKE_INSTALL_PREFIX={}".format(install_dir)
<commit_msg>Print OSError<commit_after>#!/usr/bin/env python

# Copyright (c) 2014, <NAME>
# All rights reserved.

import argparse
import os
import re
import shutil
import subprocess
import sys
import detail.util

# Note: python 2.7 compatible (For jenkins plug-in)

parser = argparse.ArgumentParser(description="Script for building")
parser.add_argument(
    '--toolchain',
    choices=[
        'default',
        'libcxx',
        'xcode',
        'clang_libstdcxx',
        'gcc48',
        'gcc',
        'vs2013x64',
        'vs2013',
        'analyze',
        'sanitize_address',
        'sanitize_leak',
        'sanitize_memory',
        'sanitize_thread',
        'cygwin',
        'mingw',
        'ios',
        'ios-nocodesign',
        'nmake-vs2013-x64'
    ],
    help="CMake generator/toolchain",
)

parser.add_argument(
    '--config',
    help="CMake build type (Release, Debug, ...)",
)

parser.add_argument('--test', action='store_true', help="Run ctest after build")
parser.add_argument(
    '--nobuild', action='store_true', help="Do not build (only generate)"
)
parser.add_argument(
    '--open', action='store_true', help="Open generated project (for IDE)"
)
parser.add_argument('--verbose', action='store_true', help="Verbose output")
parser.add_argument('--install', action='store_true', help="Run install")
parser.add_argument(
    '--clear', action='store_true', help="Remove build and install dirs"
)
parser.add_argument(
    '--fwd',
    nargs='*',
    help="Arguments to cmake without '-D', like:\nBOOST_ROOT=/some/path"
)
parser.add_argument(
    '--iossim',
    action='store_true',
    help="Build for ios i386 simulator"
)

args = parser.parse_args()

generator = ''

"""Toolchain name"""
polly_toolchain = ''
if args.toolchain:
  polly_toolchain = args.toolchain
else:
  polly_toolchain = 'default'

if args.toolchain == 'vs2013x64':
  polly_toolchain = 'vs-12-2013-win64'
elif args.toolchain == 'vs2013':
  polly_toolchain = 'vs-12-2013'

"""Build directory tag"""
multi_config_dir = False
if args.toolchain == 'vs2013x64':
  multi_config_dir = True
elif args.toolchain == 'vs2013':
  multi_config_dir = True
elif args.toolchain == 'xcode':
  multi_config_dir = True

if args.config and not multi_config_dir:
  build_tag = "{}-{}".format(polly_toolchain, args.config)
else:
  build_tag = polly_toolchain

"""Generator"""
if args.toolchain == 'vs2013x64':
  generator = '-GVisual Studio 12 2013 Win64'
elif args.toolchain == 'vs2013':
  generator = '-GVisual Studio 12 2013'
elif args.toolchain == 'xcode':
  generator = '-GXcode'
elif args.toolchain == 'ios':
  generator = '-GXcode'
elif args.toolchain == 'ios-nocodesign':
  generator = '-GXcode'
elif args.toolchain == 'mingw':
  generator = '-GMinGW Makefiles'
elif args.toolchain == 'nmake-vs2013-x64':
  generator = '-GNMake Makefiles'

"""Tune environment"""
if args.toolchain == 'mingw':
  mingw_path = os.getenv("MINGW_PATH")
  if not mingw_path:
    sys.exit(
        "Please set environment variable MINGW_PATH "
        "to directory with mingw32-make.exe"
    )
  if not os.path.isdir(mingw_path):
    sys.exit("MINGW_PATH({}) is not a directory".format(mingw_path))

  mingw_make = os.path.join(mingw_path, 'mingw32-make.exe')
  if not os.path.isfile(mingw_make):
    sys.exit(
        "File mingw32-make.exe not found in "
        "directory `{}` (MINGW_PATH environment variable)".format(mingw_path)
    )
  os.environ['PATH'] = "{};{}".format(mingw_path, os.getenv('PATH'))

if args.toolchain == 'nmake-vs2013-x64':
  vs_path = os.getenv('VS120COMNTOOLS')
  if not vs_path:
    sys.exit(
        'Environment variable VS120COMNTOOLS is empty, '
        'looks like Visual Studio 2013 is not installed'
    )
  vcvarsall_dir = os.path.join(vs_path, '..', '..', 'VC')
  if not os.path.isdir(vcvarsall_dir):
    sys.exit(
        'Directory `{}` not exists '
        '(VS120COMNTOOLS environment variable)'.format(vcvarsall_dir)
    )
  vcvarsall_path = os.path.join(vcvarsall_dir, 'vcvarsall.bat')
  if not os.path.isfile(vcvarsall_path):
    sys.exit(
        'File vcvarsall.bat not found in directory '
        '`{}` (VS120COMNTOOLS_ environment variable)'.format(vcvarsall_dir)
    )
  new_env = detail.util.get_environment_from_batch_command([vcvarsall_path, 'amd64'])
  os.environ = new_env

cdir = os.getcwd()

# workaround for version less that 3.3
DEVNULL = open(os.devnull, 'w')

def call(call_args):
  try:
    print('Execute command: [')
    for i in call_args:
      print('  `{}`'.format(i))
    print(']')
    if not args.verbose:
      subprocess.check_call(
          call_args,
          stdout=DEVNULL,
          stderr=DEVNULL,
          universal_newlines=True,
          env=os.environ
      )
    else:
      subprocess.check_call(
          call_args,
          universal_newlines=True,
          env=os.environ
      )
  except subprocess.CalledProcessError as error:
    print(error)
    print(error.output)
    sys.exit(1)
  except OSError as error:
    print(error)
    sys.exit(1)

call(['cmake', '--version'])

polly_root = os.getenv("POLLY_ROOT")
if not polly_root:
  sys.exit("Environment variable `POLLY_ROOT` is empty")

toolchain_path = os.path.join(polly_root, "{}.cmake".format(polly_toolchain))
toolchain_option = "-DCMAKE_TOOLCHAIN_FILE={}".format(toolchain_path)

build_dir = os.path.join(cdir, '_builds', build_tag)
build_dir_option = "-B{}".format(build_dir)

install_dir = os.path.join(cdir, '_install', polly_toolchain)
if args.install:
  install_dir_option = "-DCMAKE_INSTALL_PREFIX={}".format(install_dir)

{'fraction_non_alphanumeric': 0.14435981138919116, 'fraction_numerical': 0.022578890097932534, 'mean_word_length': 3.536816125051419, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5058436', 'n_tokens_mistral': 4077, 'n_tokens_neox': 3866, 'n_words': 799}