File: updateVcpkgPackage.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (110 lines) | stat: -rw-r--r-- 3,669 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python

import io, os, re, sys, subprocess
import hashlib

from scriptCommon import catchPath
from releaseCommon import Version

print(catchPath)

default_path = '../vcpkg/ports/catch-classic/'

def adjusted_path(path):
    return os.path.join(catchPath, path)

def get_hash(path):
    BUFF_SIZE = 65536
    sha512 = hashlib.sha512()
    # The newlines should be normalized into \n, which is what we want
    # If reused use 'rb' with a file written with io.open(newline='\n')
    with open(path, 'r') as f:
        while True:
            data = f.read(BUFF_SIZE)
            if not data:
                break
            if sys.version_info[0] < 3:
                sha512.update(data)
            else:
                sha512.update(data.encode('utf-8'))
    return sha512.hexdigest()

def update_control(path):
    v = Version()
    ver_string = v.getVersionString()

    # Update control
    lines = []
    control_path = os.path.join(path, 'CONTROL')
    with open(control_path, 'r') as f:
        for line in f:
            lines.append(line)
    with open(control_path, 'w') as f:
        for line in lines:
            if 'Version: ' in line:
                line = 'Version: {}\n'.format(v.getVersionString())
            f.write(line)

def update_portfile(path, header_hash, licence_hash):
    print('Updating portfile')
    v = Version()
    ver_string = v.getVersionString()

    # Update portfile
    lines = []
    portfile_path = os.path.join(path, 'portfile.cmake')
    with open(portfile_path, 'r') as f:
        for line in f:
            lines.append(line)
    with open(portfile_path, 'w') as f:
        # There are three things we need to change/update
        # 1) CATCH_VERSION cmake variable
        # 2) Hash of header
        # 3) Hash of licence
        # We could assume licence never changes, but where is the fun in that?
        for line in lines:
            # Update the version
            if 'set(CATCH_VERSION' in line:
                line = 'set(CATCH_VERSION v{})\n'.format(v.getVersionString())

            # Determine which file we are updating
            if 'vcpkg_download_distfile' in line:
                kind = line.split('(')[-1].strip()

            # Update the hashes
            if 'SHA512' in line and kind == 'HEADER':
                line = '    SHA512 {}\n'.format(header_hash)
            if 'SHA512' in line and kind == 'LICENSE':
                line = '    SHA512 {}\n'.format(licence_hash)
            f.write(line)


def git_push(path_to_repo):
    v = Version()
    ver_string = v.getVersionString()

    os.chdir(path_to_repo)

    # Work with git
    # Make sure we branch off master
    subprocess.call('git checkout master', shell=True)
    
    # Update repo to current master, so we don't work off old version of the portsfile 
    subprocess.call('git pull Microsoft master', shell=True)
    subprocess.call('git push', shell=True)

    # Create a new branch for the update
    subprocess.call('git checkout -b catch-{}'.format(ver_string), shell=True)
    # Add changed files (should be only our files)
    subprocess.call('git add -u .', shell=True)
    # Create a commit with these changes
    subprocess.call('git commit -m "Update Catch to {}"'.format(ver_string), shell=True)
    # Don't push, so author can review
    print('Changes were commited to the vcpkg fork. Please check, push and open PR.')

header_hash = get_hash(adjusted_path('single_include/catch.hpp'))
licence_hash = get_hash(adjusted_path('LICENSE.txt'))
update_control(adjusted_path(default_path))
update_portfile(adjusted_path(default_path), header_hash, licence_hash)

git_push(adjusted_path('../vcpkg'))