blob: ec7487e5add8d11453adac23b866aa21f76874d2 [file] [log] [blame]
Takuto Ikuta9af233a2018-11-29 03:53:53 +00001#!/usr/bin/env python
2# Copyright 2018 The Chromium Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import os
7import subprocess
8import json
9import sys
10
Takuto Ikuta9af233a2018-11-29 03:53:53 +000011import ninjalog_uploader
12
13THIS_DIR = os.path.dirname(__file__)
14UPLOADER = os.path.join(THIS_DIR, 'ninjalog_uploader.py')
15CONFIG = os.path.join(THIS_DIR, 'ninjalog.cfg')
Takuto Ikutac8069af2019-01-09 06:24:56 +000016VERSION = 2
Takuto Ikuta9af233a2018-11-29 03:53:53 +000017
18
19def LoadConfig():
20 if os.path.isfile(CONFIG):
21 with open(CONFIG, 'rb') as f:
22 config = json.load(f)
23 if config['version'] == VERSION:
24 config['countdown'] -= 1
25 return config
26
27 return {
28 'is-googler': ninjalog_uploader.IsGoogler(
29 'chromium-build-stats.appspot.com'),
30 'countdown': 10,
31 'version': VERSION,
32 }
33
34
35def SaveConfig(config):
36 with open(CONFIG, 'wb') as f:
37 json.dump(config, f)
38
39
40def ShowMessage(countdown):
Takuto Ikutac8069af2019-01-09 06:24:56 +000041 whitelisted = '\n'.join([' * %s' % config for config in
42 ninjalog_uploader.WHITELISTED_CONFIGS])
Takuto Ikuta9af233a2018-11-29 03:53:53 +000043 print """
Takuto Ikuta540ba9d2018-12-19 22:24:08 +000044Your ninjalog will be uploaded to build stats server. The uploaded log will be
45used to analyze user side build performance.
Takuto Ikuta9af233a2018-11-29 03:53:53 +000046
47The following information will be uploaded with ninjalog.
48* OS (e.g. Win, Mac or Linux)
Takuto Ikuta9af233a2018-11-29 03:53:53 +000049* number of cpu cores of building machine
Takuto Ikutac8069af2019-01-09 06:24:56 +000050* build targets (e.g. chrome, browser_tests)
51* parallelism passed by -j flag
52* following build configs
53%s
Takuto Ikuta9af233a2018-11-29 03:53:53 +000054
55Uploading ninjalog will be started after you run autoninja another %d time.
56
57If you don't want to upload ninjalog, please run following command.
58$ %s opt-out
59
Takuto Ikuta540ba9d2018-12-19 22:24:08 +000060If you want to allow upload ninjalog from next autoninja run, please run the
61following command.
Takuto Ikuta9af233a2018-11-29 03:53:53 +000062$ %s opt-in
63
Takuto Ikuta540ba9d2018-12-19 22:24:08 +000064If you have questions about this, please send mail to infra-dev@chromium.org
Takuto Ikuta9af233a2018-11-29 03:53:53 +000065
Takuto Ikuta540ba9d2018-12-19 22:24:08 +000066You can find a more detailed explanation in
67%s
68
Takuto Ikutac8069af2019-01-09 06:24:56 +000069""" % (whitelisted, countdown, __file__, __file__,
Takuto Ikuta540ba9d2018-12-19 22:24:08 +000070 os.path.abspath(os.path.join(THIS_DIR, "ninjalog.README.md")))
Takuto Ikuta9af233a2018-11-29 03:53:53 +000071
72
73def main():
74 config = LoadConfig()
75
76 if len(sys.argv) == 2 and sys.argv[1] == 'opt-in':
77 config['opt-in'] = True
78 config['countdown'] = 0
79 SaveConfig(config)
80 print('ninjalog upload is opted in.')
81 return 0
82
83 if len(sys.argv) == 2 and sys.argv[1] == 'opt-out':
84 config['opt-in'] = False
85 SaveConfig(config)
86 print('ninjalog upload is opted out.')
87 return 0
88
89 SaveConfig(config)
90
91 if 'opt-in' in config and not config['opt-in']:
92 # Upload is opted out.
93 return 0
94
95 if not config.get("is-googler", False):
96 # Not googler.
97 return 0
98
99 if config.get("countdown", 0) > 0:
100 # Need to show message.
101 ShowMessage(config["countdown"])
102 return 0
103
104 if len(sys.argv) == 1:
105 # dry-run for debugging.
106 print("upload ninjalog dry-run")
107 return 0
108
109 # Run upload script without wait.
110 devnull = open(os.devnull, "w")
111 subprocess.Popen([sys.executable, UPLOADER] + sys.argv[1:],
112 stdout=devnull, stderr=devnull)
113
114
115if __name__ == '__main__':
116 sys.exit(main())