2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#!/usr/bin/env python
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Build the project on Travis CI.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from __future__ import print_function
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-24 08:03:22 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import errno, os, re, shutil, sys, tempfile, urllib
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								from subprocess import call, check_call, Popen, PIPE, STDOUT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								def rmtree_if_exists(dir):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  try:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    shutil.rmtree(dir)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  except OSError as e:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if e.errno == errno.ENOENT:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      pass
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								build = os.environ['BUILD']
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if build == 'Doc':
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  travis = 'TRAVIS' in os.environ
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Install dependencies.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if travis:
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-21 08:14:47 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_call('curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | ' +
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               'sudo apt-key add -', shell=True)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_call('echo "deb https://deb.nodesource.com/node_0.10 precise main" | ' +
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								               'sudo tee /etc/apt/sources.list.d/nodesource.list', shell=True)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-21 07:04:56 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_call(['sudo', 'apt-get', 'update'])
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-24 07:48:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_call(['sudo', 'apt-get', 'install', 'python-virtualenv', 'nodejs'])
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-21 08:26:36 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_call(['npm', 'install', '-g', 'less', 'less-plugin-clean-css'])
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-24 07:48:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    deb_file = 'doxygen_1.8.6-2_amd64.deb'
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-24 08:03:22 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    urllib.urlretrieve('http://mirrors.kernel.org/ubuntu/pool/main/d/doxygen/' +
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								                       deb_file, deb_file)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-24 07:48:06 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    check_call(['sudo', 'dpkg', '-i', deb_file])
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  cppformat_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  sys.path.insert(0, os.path.join(cppformat_dir, 'doc'))
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  import build
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  html_dir = build.build_docs()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  repo = 'cppformat.github.io'
							 | 
						
					
						
							
								
									
										
										
										
											2015-06-04 12:52:42 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  if travis and 'KEY' not in os.environ:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Don't update the repo if building on Travis from an account that doesn't
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # have push access.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    print('Skipping update of ' + repo)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    exit(0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Clone the cppformat.github.io repo.
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  rmtree_if_exists(repo)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:28:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  git_url = 'https://github.com/' if travis else 'git@github.com:'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  check_call(['git', 'clone', git_url + 'cppformat/{}.git'.format(repo)])
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Copy docs to the repo.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  target_dir = os.path.join(repo, 'dev')
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  rmtree_if_exists(target_dir)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:28:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  shutil.copytree(html_dir, target_dir, ignore=shutil.ignore_patterns('.*'))
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if travis:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_call(['git', 'config', '--global', 'user.name', 'amplbot'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_call(['git', 'config', '--global', 'user.email', 'viz@ampl.com'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Push docs to GitHub pages.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  check_call(['git', 'add', '--all'], cwd=repo)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  if call(['git', 'diff-index', '--quiet', 'HEAD'], cwd=repo):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    check_call(['git', 'commit', '-m', 'Update documentation'], cwd=repo)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:28:54 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    cmd = 'git push'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if travis:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      cmd += ' https://$KEY@github.com/cppformat/cppformat.github.io.git master'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, cwd=repo)
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-21 19:29:45 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # Print the output without the key.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    print(p.communicate()[0].replace(os.environ['KEY'], '$KEY'))
							 | 
						
					
						
							
								
									
										
										
										
											2015-05-20 08:06:12 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    if p.returncode != 0:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      raise CalledProcessError(p.returncode, cmd)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  exit(0)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								check_call(['git', 'submodule', 'update', '--init'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								check_call(['cmake', '-DCMAKE_BUILD_TYPE=' + build, '-DFMT_PEDANTIC=ON', '.'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								check_call(['make', '-j4'])
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								env = os.environ.copy()
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								env['CTEST_OUTPUT_ON_FAILURE'] = '1'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								if call(['make', 'test'], env=env):
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  with open('Testing/Temporary/LastTest.log', 'r') as f:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    print(f.read())
							 |