blob: 43f5bb4f6a233bbbd8f719ef0b33d0a88b91bb68 [file] [log] [blame]
Martin Hořeňovskýac369b72017-04-11 17:25:04 +02001#!/usr/bin/env python
2
3import io, os, re, sys, subprocess
4import hashlib
5
6from scriptCommon import catchPath
7from releaseCommon import Version
8
9print(catchPath)
10
11default_path = '../vcpkg/ports/catch/'
12
13def adjusted_path(path):
14 return os.path.join(catchPath, path)
15
16def get_hash(path):
17 BUFF_SIZE = 65536
18 sha512 = hashlib.sha512()
19 # The newlines should be normalized into \n, which is what we want
20 # If reused use 'rb' with a file written with io.open(newline='\n')
21 with open(path, 'r') as f:
22 while True:
23 data = f.read(BUFF_SIZE)
24 if not data:
25 break
26 if sys.version_info[0] < 3:
27 sha512.update(data)
28 else:
29 sha512.update(data.encode('utf-8'))
30 return sha512.hexdigest()
31
32def update_control(path):
33 v = Version()
34 ver_string = v.getVersionString()
35
36 # Update control
37 lines = []
38 control_path = os.path.join(path, 'CONTROL')
39 with open(control_path, 'r') as f:
40 for line in f:
41 lines.append(line)
42 with open(control_path, 'w') as f:
43 for line in lines:
44 if 'Version: ' in line:
45 line = 'Version: {}\n'.format(v.getVersionString())
46 f.write(line)
47
48def update_portfile(path, header_hash, licence_hash):
49 print('Updating portfile')
50 v = Version()
51 ver_string = v.getVersionString()
52
53 # Update portfile
54 lines = []
55 portfile_path = os.path.join(path, 'portfile.cmake')
56 with open(portfile_path, 'r') as f:
57 for line in f:
58 lines.append(line)
59 with open(portfile_path, 'w') as f:
Martin Hořeňovský92d714e2017-08-08 23:04:39 +020060 # There are three things we need to change/update
61 # 1) CATCH_VERSION cmake variable
62 # 2) Hash of header
63 # 3) Hash of licence
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020064 # We could assume licence never changes, but where is the fun in that?
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020065 for line in lines:
Martin Hořeňovský92d714e2017-08-08 23:04:39 +020066 # Update the version
67 if 'set(CATCH_VERSION' in line:
Martin Hořeňovský784f6df2017-08-27 11:43:55 +020068 line = 'set(CATCH_VERSION v{})\n'.format(v.getVersionString())
Martin Hořeňovský92d714e2017-08-08 23:04:39 +020069
70 # Determine which file we are updating
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020071 if 'vcpkg_download_distfile' in line:
72 kind = line.split('(')[-1].strip()
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020073
Martin Hořeňovský92d714e2017-08-08 23:04:39 +020074 # Update the hashes
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020075 if 'SHA512' in line and kind == 'HEADER':
76 line = ' SHA512 {}\n'.format(header_hash)
77 if 'SHA512' in line and kind == 'LICENSE':
78 line = ' SHA512 {}\n'.format(licence_hash)
79 f.write(line)
80
81
82def git_push(path_to_repo):
83 v = Version()
84 ver_string = v.getVersionString()
85
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020086 os.chdir(path_to_repo)
87
88 # Work with git
89 # Make sure we branch off master
90 subprocess.call('git checkout master', shell=True)
91
92 # Update repo to current master, so we don't work off old version of the portsfile
93 subprocess.call('git pull Microsoft master', shell=True)
Martin Hořeňovskýdf5cf2d2017-05-16 14:34:55 +020094 subprocess.call('git push', shell=True)
Martin Hořeňovskýac369b72017-04-11 17:25:04 +020095
96 # Create a new branch for the update
97 subprocess.call('git checkout -b catch-{}'.format(ver_string), shell=True)
98 # Add changed files (should be only our files)
99 subprocess.call('git add -u .', shell=True)
100 # Create a commit with these changes
101 subprocess.call('git commit -m "Update Catch to {}"'.format(ver_string), shell=True)
102 # Don't push, so author can review
103 print('Changes were commited to the vcpkg fork. Please check, push and open PR.')
104
105header_hash = get_hash(adjusted_path('single_include/catch.hpp'))
106licence_hash = get_hash(adjusted_path('LICENSE.txt'))
107update_control(adjusted_path(default_path))
108update_portfile(adjusted_path(default_path), header_hash, licence_hash)
109
110git_push(adjusted_path('../vcpkg'))