-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathninjalog_uploader_wrapper.py
executable file
·135 lines (105 loc) · 3.5 KB
/
ninjalog_uploader_wrapper.py
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env python3
# Copyright 2018 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import print_function
import json
import os
import platform
import subprocess
import sys
import ninjalog_uploader
import subprocess2
THIS_DIR = os.path.dirname(__file__)
UPLOADER = os.path.join(THIS_DIR, 'ninjalog_uploader.py')
CONFIG = os.path.join(THIS_DIR, 'ninjalog.cfg')
VERSION = 3
def LoadConfig():
if os.path.isfile(CONFIG):
with open(CONFIG, 'r') as f:
try:
config = json.load(f)
except Exception:
# Set default value when failed to load config.
config = {
'is-googler': ninjalog_uploader.IsGoogler(),
'countdown': 10,
'version': VERSION,
}
if config['version'] == VERSION:
config['countdown'] = max(0, config['countdown'] - 1)
return config
return {
'is-googler': ninjalog_uploader.IsGoogler(),
'countdown': 10,
'version': VERSION,
}
def SaveConfig(config):
with open(CONFIG, 'w') as f:
json.dump(config, f)
def ShowMessage(countdown):
whitelisted = '\n'.join(
[' * %s' % config for config in ninjalog_uploader.ALLOWLISTED_CONFIGS])
print("""
Your ninjalog will be uploaded to build stats server. The uploaded log will be
used to analyze user side build performance.
The following information will be uploaded with ninjalog.
* OS (e.g. Win, Mac or Linux)
* number of cpu cores of building machine
* build targets (e.g. chrome, browser_tests)
* parallelism passed by -j flag
* following build configs
%s
Uploading ninjalog will be started after you run autoninja another %d time(s).
If you don't want to upload ninjalog, please run following command.
$ python3 %s opt-out
If you want to allow upload ninjalog from next autoninja run, please run the
following command.
$ python3 %s opt-in
If you have questions about this, please send mail to [email protected]
You can find a more detailed explanation in
%s
or
https://chromium.googlesource.com/chromium/tools/depot_tools/+/main/ninjalog.README.md
""" % (whitelisted, countdown, __file__, __file__,
os.path.abspath(os.path.join(THIS_DIR, "ninjalog.README.md"))))
def main():
config = LoadConfig()
if len(sys.argv) == 2 and sys.argv[1] == 'opt-in':
config['opt-in'] = True
config['countdown'] = 0
SaveConfig(config)
print('ninjalog upload is opted in.')
return 0
if len(sys.argv) == 2 and sys.argv[1] == 'opt-out':
config['opt-in'] = False
SaveConfig(config)
print('ninjalog upload is opted out.')
return 0
if 'opt-in' in config and not config['opt-in']:
# Upload is opted out.
return 0
if not config.get("is-googler", False):
# Not googler.
return 0
if config.get("countdown", 0) > 0:
# Need to show message.
ShowMessage(config["countdown"])
# Only save config if something has meaningfully changed.
SaveConfig(config)
return 0
if len(sys.argv) == 1:
# dry-run for debugging.
print("upload ninjalog dry-run")
return 0
# Run upload script without wait.
devnull = open(os.devnull, "w")
creationnflags = 0
if platform.system() == 'Windows':
creationnflags = subprocess.CREATE_NEW_PROCESS_GROUP
subprocess2.Popen([sys.executable, UPLOADER] + sys.argv[1:],
stdout=devnull,
stderr=devnull,
creationflags=creationnflags)
if __name__ == '__main__':
sys.exit(main())