]> git.proxmox.com Git - ceph.git/blob - ceph/src/fmt/support/travis-build.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / fmt / support / travis-build.py
1 #!/usr/bin/env python
2 # Build the project on Travis CI.
3
4 from __future__ import print_function
5 import errno, os, shutil, subprocess, sys, urllib
6 from subprocess import call, check_call, Popen, PIPE, STDOUT
7
8 def rmtree_if_exists(dir):
9 try:
10 shutil.rmtree(dir)
11 except OSError as e:
12 if e.errno == errno.ENOENT:
13 pass
14
15 def makedirs_if_not_exist(dir):
16 try:
17 os.makedirs(dir)
18 except OSError as e:
19 if e.errno != errno.EEXIST:
20 raise
21
22 def install_dependencies():
23 branch = os.environ['TRAVIS_BRANCH']
24 if branch != 'master':
25 print('Branch: ' + branch)
26 exit(0) # Ignore non-master branches
27 check_call('curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key ' +
28 '| sudo apt-key add -', shell=True)
29 check_call('echo "deb https://deb.nodesource.com/node_0.10 precise main" ' +
30 '| sudo tee /etc/apt/sources.list.d/nodesource.list', shell=True)
31 check_call(['sudo', 'apt-get', 'update'])
32 check_call(['sudo', 'apt-get', 'install', 'python-virtualenv', 'nodejs'])
33 check_call(['sudo', 'npm', 'install', '-g', 'less@2.6.1', 'less-plugin-clean-css'])
34 deb_file = 'doxygen_1.8.6-2_amd64.deb'
35 urllib.urlretrieve('http://mirrors.kernel.org/ubuntu/pool/main/d/doxygen/' +
36 deb_file, deb_file)
37 check_call(['sudo', 'dpkg', '-i', deb_file])
38
39 fmt_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
40
41 build = os.environ['BUILD']
42 if build == 'Doc':
43 travis = 'TRAVIS' in os.environ
44 if travis:
45 install_dependencies()
46 sys.path.insert(0, os.path.join(fmt_dir, 'doc'))
47 import build
48 build.create_build_env()
49 html_dir = build.build_docs()
50 repo = 'fmtlib.github.io'
51 if travis and 'KEY' not in os.environ:
52 # Don't update the repo if building on Travis from an account that
53 # doesn't have push access.
54 print('Skipping update of ' + repo)
55 exit(0)
56 # Clone the fmtlib.github.io repo.
57 rmtree_if_exists(repo)
58 git_url = 'https://github.com/' if travis else 'git@github.com:'
59 check_call(['git', 'clone', git_url + 'fmtlib/{}.git'.format(repo)])
60 # Copy docs to the repo.
61 target_dir = os.path.join(repo, 'dev')
62 rmtree_if_exists(target_dir)
63 shutil.copytree(html_dir, target_dir, ignore=shutil.ignore_patterns('.*'))
64 if travis:
65 check_call(['git', 'config', '--global', 'user.name', 'amplbot'])
66 check_call(['git', 'config', '--global', 'user.email', 'viz@ampl.com'])
67 # Push docs to GitHub pages.
68 check_call(['git', 'add', '--all'], cwd=repo)
69 if call(['git', 'diff-index', '--quiet', 'HEAD'], cwd=repo):
70 check_call(['git', 'commit', '-m', 'Update documentation'], cwd=repo)
71 cmd = 'git push'
72 if travis:
73 cmd += ' https://$KEY@github.com/fmtlib/fmtlib.github.io.git master'
74 p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, cwd=repo)
75 # Print the output without the key.
76 print(p.communicate()[0].replace(os.environ['KEY'], '$KEY'))
77 if p.returncode != 0:
78 raise subprocess.CalledProcessError(p.returncode, cmd)
79 exit(0)
80
81 standard = os.environ['STANDARD']
82 install_dir = os.path.join(fmt_dir, "_install")
83 build_dir = os.path.join(fmt_dir, "_build")
84 test_build_dir = os.path.join(fmt_dir, "_build_test")
85
86 # Configure the library.
87 makedirs_if_not_exist(build_dir)
88 cmake_flags = [
89 '-DCMAKE_INSTALL_PREFIX=' + install_dir, '-DCMAKE_BUILD_TYPE=' + build,
90 '-DCMAKE_CXX_STANDARD=' + standard
91 ]
92
93 # Make sure the fuzzers still compile.
94 main_cmake_flags = list(cmake_flags)
95 if 'ENABLE_FUZZING' in os.environ:
96 main_cmake_flags += ['-DFMT_FUZZ=ON', '-DFMT_FUZZ_LINKMAIN=On']
97
98 check_call(['cmake', '-DFMT_DOC=OFF', '-DFMT_PEDANTIC=ON', '-DFMT_WERROR=ON', fmt_dir] +
99 main_cmake_flags, cwd=build_dir)
100
101 # Build the library.
102 check_call(['cmake', '--build','.'], cwd=build_dir)
103
104 # Test the library.
105 env = os.environ.copy()
106 env['CTEST_OUTPUT_ON_FAILURE'] = '1'
107 if call(['make', 'test'], env=env, cwd=build_dir):
108 with open(os.path.join(build_dir, 'Testing', 'Temporary', 'LastTest.log'), 'r') as f:
109 print(f.read())
110 sys.exit(-1)
111
112 # Install the library.
113 check_call(['make', 'install'], cwd=build_dir)
114
115 # Test installation.
116 makedirs_if_not_exist(test_build_dir)
117 check_call(['cmake', os.path.join(fmt_dir, "test", "find-package-test")] +
118 cmake_flags, cwd=test_build_dir)
119 check_call(['make', '-j4'], cwd=test_build_dir)