blob: 92668e8a2cf631a77873e0ab1f267ab4cb64af2a [file] [log] [blame]
Kristofer Jonsson6d63f5f2020-04-20 13:40:49 +02001#!/usr/bin/env python
2
3#
4# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
5#
6# SPDX-License-Identifier: Apache-2.0
7#
8# Licensed under the Apache License, Version 2.0 (the License); you may
9# not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an AS IS BASIS, WITHOUT
16# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19#
20
21import os
22import subprocess
23
24def print_args(args, **kwargs):
25 cwd = kwargs['cwd']
26
27 if isinstance(args, list):
28 args = ' '.join(args)
29
30 print('%s$ %s' % (cwd, args))
31
32def check_call(args, **kwargs):
33 print_args(args, **kwargs)
34 return subprocess.check_call(args, **kwargs)
35
36def check_output(args, **kwargs):
37 print_args(args, **kwargs)
38 return subprocess.check_output(args, **kwargs)
39
40class Git(object):
41 def __init__(self, path, fetchurl, pushurl=None, revision='origin/master'):
42 self.path = path
43 self.fetchurl = fetchurl
44 self.pushurl = pushurl
45 self.revision = revision
46
47 def init(self):
48 if not os.path.exists(self.path):
49 os.makedirs(self.path)
50
51 if not os.path.exists(os.path.join(self.path, '.git')):
52 check_output(['git', 'init'], cwd=self.path)
53
54 def remote_add(self, name, fetchurl):
55 remotes = check_output(['git', 'remote'], cwd=self.path).decode('utf-8').split('\n')
56 if not name in remotes:
57 check_output(['git', 'remote', 'add', '-m', self.revision, name, self.fetchurl], cwd=self.path)
58
59 if self.pushurl:
60 check_output(['git', 'remote', 'set-url', '--add', '--push', name, self.pushurl], cwd=self.path)
61
62 def fetch(self):
63 check_output(['git', 'fetch'], cwd=self.path)
64
65 def checkout(self, revision):
66 rev = self.__get_rev(revision)
67 check_output(['git', 'checkout', rev], stderr=subprocess.STDOUT, cwd=self.path)
68
69 def clone(self):
70 if not os.path.exists(os.path.join(self.path, '.git')):
71 self.init()
72 self.remote_add('origin', self.fetchurl)
73 self.fetch()
74 self.checkout(self.revision)
75
76 def rebase(self):
77 rev = self.__get_rev(self.revision)
78 check_output(['git', 'rebase', rev], cwd=self.path)
79
80 def __get_rev(self, revision):
81 try:
82 rev = check_output(['git', 'rev-parse', 'origin/' + self.revision], cwd=self.path)
83 except:
84 rev = check_output(['git', 'rev-parse', self.revision], cwd=self.path)
85
86 return rev.decode('utf-8').strip()
87
88basedir = os.path.dirname(os.path.realpath(__file__))
89
90externals = [
Kristofer Jonssoned01cc22020-06-24 15:23:14 +020091 Git(os.path.join(basedir, 'core_software'), "https://review.mlplatform.org/ml/ethos-u/ethos-u-core-software", pushurl='ssh://review.mlplatform.org:29418/ml/ethos-u/ethos-u-core-software', revision='master'),
92 Git(os.path.join(basedir, 'core_software/core_driver'), "https://review.mlplatform.org/ml/ethos-u/ethos-u-core-driver", pushurl='ssh://review.mlplatform.org:29418/ml/ethos-u/ethos-u-core-driver', revision='master'),
Kristofer Jonsson6d63f5f2020-04-20 13:40:49 +020093 Git(os.path.join(basedir, 'core_software/cmsis'), 'https://github.com/ARM-software/CMSIS_5.git', revision='master'),
94 Git(os.path.join(basedir, 'core_software/tensorflow'), 'https://github.com/tensorflow/tensorflow', revision='master'),
Kristofer Jonssoned01cc22020-06-24 15:23:14 +020095 Git(os.path.join(basedir, 'vela'), "https://review.mlplatform.org/ml/ethos-u/ethos-u-vela", pushurl='ssh://review.mlplatform.org:29418/ml/ethos-u/ethos-u-vela', revision='master')
Kristofer Jonsson6d63f5f2020-04-20 13:40:49 +020096]
97
98for external in externals:
99 external.clone()
100 external.fetch()
101 external.rebase()