blob: e95a86dcf0a47ce1bc287a955bad9da02b8614e0 [file] [log] [blame]
Shawn O. Pearce47c1a632009-03-02 18:24:23 -08001# Copyright (C) 2009 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Mike Frysinger5f11eac2020-02-25 15:09:01 -050015import platform
Shawn O. Pearce47c1a632009-03-02 18:24:23 -080016import sys
Mike Frysinger5f11eac2020-02-25 15:09:01 -050017
Shawn O. Pearcec95583b2009-03-03 17:47:06 -080018from command import Command, MirrorSafeCommand
Mike Frysinger9bfdfbe2019-09-30 22:46:45 -040019from git_command import git, RepoSourceVersion, user_agent
David Pursehousee00aa6b2012-09-11 14:33:51 +090020from git_refs import HEAD
Shawn O. Pearce47c1a632009-03-02 18:24:23 -080021
David Pursehouse819827a2020-02-12 15:20:19 +090022
Shawn O. Pearcec95583b2009-03-03 17:47:06 -080023class Version(Command, MirrorSafeCommand):
Shawn O. Pearceecff4f12011-11-29 15:01:33 -080024 wrapper_version = None
25 wrapper_path = None
26
Shawn O. Pearce47c1a632009-03-02 18:24:23 -080027 common = False
28 helpSummary = "Display the version of repo"
29 helpUsage = """
30%prog
31"""
32
33 def Execute(self, opt, args):
34 rp = self.manifest.repoProject
35 rem = rp.GetRemote(rp.remote.name)
Mike Frysinger0588f3d2021-01-08 13:50:23 -050036 branch = rp.GetBranch('default')
Shawn O. Pearce47c1a632009-03-02 18:24:23 -080037
Mike Frysinger9bfdfbe2019-09-30 22:46:45 -040038 # These might not be the same. Report them both.
39 src_ver = RepoSourceVersion()
40 rp_ver = rp.bare_git.describe(HEAD)
41 print('repo version %s' % rp_ver)
Sarah Owenscecd1d82012-11-01 22:59:27 -070042 print(' (from %s)' % rem.url)
Mike Frysinger0588f3d2021-01-08 13:50:23 -050043 print(' (tracking %s)' % branch.merge)
Mike Frysingerb4a6f6d2020-03-30 18:51:19 -040044 print(' (%s)' % rp.bare_git.log('-1', '--format=%cD', HEAD))
Shawn O. Pearceecff4f12011-11-29 15:01:33 -080045
Mike Frysingerbb930462020-02-25 15:18:31 -050046 if self.wrapper_path is not None:
47 print('repo launcher version %s' % self.wrapper_version)
48 print(' (from %s)' % self.wrapper_path)
Shawn O. Pearceecff4f12011-11-29 15:01:33 -080049
Mike Frysinger9bfdfbe2019-09-30 22:46:45 -040050 if src_ver != rp_ver:
51 print(' (currently at %s)' % src_ver)
52
53 print('repo User-Agent %s' % user_agent.repo)
Mike Frysingerca540ae2019-07-10 15:42:30 -040054 print('git %s' % git.version_tuple().full)
Mike Frysinger9bfdfbe2019-09-30 22:46:45 -040055 print('git User-Agent %s' % user_agent.git)
Sarah Owenscecd1d82012-11-01 22:59:27 -070056 print('Python %s' % sys.version)
Mike Frysinger5f11eac2020-02-25 15:09:01 -050057 uname = platform.uname()
Mike Frysingere257d562020-03-23 16:55:02 -040058 if sys.version_info.major < 3:
59 # Python 3 returns a named tuple, but Python 2 is simpler.
60 print(uname)
61 else:
62 print('OS %s %s (%s)' % (uname.system, uname.release, uname.version))
63 print('CPU %s (%s)' %
64 (uname.machine, uname.processor if uname.processor else 'unknown'))