blob: d05907e6875a36a40c31157d6acac5dedfd2ea10 [file] [log] [blame]
Hirthanan Subenderan00f18042020-02-11 17:24:38 -08001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-"
3#
4# Copyright 2020 The Chromium OS Authors. All rights reserved.
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""Setup module containing script to Synchronize kernel repositories + database."""
9
10from __future__ import print_function
11import os
12import subprocess
13
14from common import UPSTREAM_PATH, CHROMEOS_PATH, STABLE_PATH, \
15 UPSTREAM_REPO, CHROMEOS_REPO, STABLE_REPO, \
16 SUPPORTED_KERNELS, stable_branch, chromeos_branch
17
18from initdb_upstream import update_upstreamdb
19from initdb_stable import update_stabledb
20from initdb_chromeos import update_chromeosdb
21
22
23def synchronize_upstream():
24 """Synchronizes locally cloned repo with linux upstream remote."""
25 cwd = os.getcwd()
26 destdir = os.path.join(cwd, UPSTREAM_PATH)
27 repo = UPSTREAM_REPO
28
29 print(destdir, repo, cwd)
30
31 if not os.path.exists(destdir):
32 print(f'Cloning {repo} into {destdir}')
33 cmd = f'git clone {repo} {destdir}'.split(' ')
34 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
35 p.wait()
36
37 else:
38 os.chdir(destdir)
39
40 print(f'Updating {repo} into {destdir}')
41 cmd = 'git checkout master; git pull'.split(' ')
42 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
43 p.wait()
44
45 os.chdir(cwd)
46
47
48def synchronize_custom(path, repo):
49 """Synchronizes locally cloned repo with linux stable/chromeos remote."""
50 cwd = os.getcwd()
51 destdir = os.path.join(cwd, path)
52 upstream_destdir = os.path.join(cwd, UPSTREAM_PATH)
53
54 get_branch = stable_branch if path == 'linux-stable' else chromeos_branch
55
56 if not os.path.exists(destdir):
57 print(f'Cloning {repo} into {destdir}')
58 cmd = f'git clone {repo} {destdir}'.split(' ')
59 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
60 p.wait()
61
62 os.chdir(destdir)
63 for kernel in SUPPORTED_KERNELS:
64 cmd = f'git checkout -b {get_branch(kernel)} origin/{get_branch(kernel)}'.split(' ')
65 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
66 p.wait()
67
68 cmd = f'git remote add upstream {upstream_destdir}; git fetch upstream'
69 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
70 p.wait()
71
72 else:
73 os.chdir(destdir)
74
75 print(f'Updating {repo} into {destdir}')
76 cmd = 'git reset --hard HEAD; git fetch origin'
77 p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
78 p.wait()
79
80 for kernel in SUPPORTED_KERNELS:
81 branch = get_branch(kernel)
82 cmd = f'git rev-parse --verify {branch}'.split(' ')
83 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
84 p.wait()
85
86 output, _ = p.communicate()
87 if output:
88 cmd = f'git checkout {branch}'.split(' ')
89 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
90 p.wait()
91
92 cmd = 'git pull'.split(' ')
93 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
94 p.wait()
95
96 output, _ = p.communicate()
97 if not output:
98 cmd = f'git reset --hard origin/{branch}'.split(' ')
99 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
100 p.wait()
101 else:
102 cmd = f'git checkout -b {branch} origin/{branch}'.split(' ')
103 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
104 p.wait()
105
106 os.chdir(cwd)
107
108
109def synchronize_repositories():
110 """Deep clones linux-upstream, linux-stable, and linux-chromeos repositories"""
111 synchronize_upstream()
112 synchronize_custom(STABLE_PATH, STABLE_REPO)
113 synchronize_custom(CHROMEOS_PATH, CHROMEOS_REPO)
114
115def synchronize_database():
116 """Synchronizes the databases for upstream, stable, and chromeos."""
117 update_upstreamdb()
118 update_stabledb()
119 update_chromeosdb()
120
121
122if __name__ == '__main__':
123 synchronize_repositories()
124 synchronize_database()