@ -2,7 +2,6 @@
# 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.
"""
This is script to upload ninja_log from googler .
@ -32,20 +31,21 @@ import httplib2
# These build configs affect build performance a lot.
# TODO(tikuta): Add 'blink_symbol_level', 'closure_compile' and
# 'use_jumbo_build'.
WHITELISTED_CONFIGS = (
' symbol_level ' , ' use_goma ' , ' is_debug ' , ' is_component_build ' , ' enable_nacl ' ,
' host_os ' , ' host_cpu ' , ' target_os ' , ' target_cpu '
)
WHITELISTED_CONFIGS = ( ' symbol_level ' , ' use_goma ' , ' is_debug ' ,
' is_component_build ' , ' enable_nacl ' , ' host_os ' ,
' host_cpu ' , ' target_os ' , ' target_cpu ' )
def IsGoogler ( server ) :
""" Check whether this script run inside corp network. """
try :
h = httplib2 . Http ( )
_ , content = h . request ( ' https:// ' + server + ' /should-upload ' , ' GET ' )
_ , content = h . request ( ' https:// ' + server + ' /should-upload ' , ' GET ' )
return content == ' Success '
except httplib2 . HttpLib2Error :
return False
def ParseGNArgs ( gn_args ) :
""" Parse gn_args as json and return config dictionary. """
configs = json . loads ( gn_args )
@ -62,6 +62,7 @@ def ParseGNArgs(gn_args):
return build_configs
def GetBuildTargetFromCommandLine ( cmdline ) :
""" Get build targets from commandline. """
@ -80,8 +81,7 @@ def GetBuildTargetFromCommandLine(cmdline):
idx + = 2
continue
if ( cmdline [ idx ] [ : 2 ] in onearg_flags or
cmdline [ idx ] in zeroarg_flags ) :
if ( cmdline [ idx ] [ : 2 ] in onearg_flags or cmdline [ idx ] in zeroarg_flags ) :
idx + = 1
continue
@ -90,16 +90,16 @@ def GetBuildTargetFromCommandLine(cmdline):
return targets
def GetJflag ( cmdline ) :
""" Parse cmdline to get flag value for -j """
for i in range ( len ( cmdline ) ) :
if ( cmdline [ i ] == ' -j ' and i + 1 < len ( cmdline ) and
cmdline [ i + 1 ] . isdigit ( ) ) :
return int ( cmdline [ i + 1 ] )
if ( cmdline [ i ] == ' -j ' and i + 1 < len ( cmdline )
and cmdline [ i + 1 ] . isdigit ( ) ) :
return int ( cmdline [ i + 1 ] )
if ( cmdline [ i ] . startswith ( ' -j ' ) and
cmdline [ i ] [ len ( ' -j ' ) : ] . isdigit ( ) ) :
if ( cmdline [ i ] . startswith ( ' -j ' ) and cmdline [ i ] [ len ( ' -j ' ) : ] . isdigit ( ) ) :
return int ( cmdline [ i ] [ len ( ' -j ' ) : ] )
@ -145,6 +145,7 @@ def GetMetadata(cmdline, ninjalog):
return metadata
def GetNinjalog ( cmdline ) :
""" GetNinjalog returns the path to ninjalog from cmdline. """
# ninjalog is in current working directory by default.
@ -164,15 +165,19 @@ def GetNinjalog(cmdline):
return os . path . join ( ninjalog_dir , ' .ninja_log ' )
def main ( ) :
parser = argparse . ArgumentParser ( )
parser . add_argument ( ' --server ' ,
default = ' chromium-build-stats.appspot.com ' ,
help = ' server to upload ninjalog file. ' )
parser . add_argument ( ' --ninjalog ' , help = ' ninjalog file to upload. ' )
parser . add_argument ( ' --verbose ' , action = ' store_true ' ,
parser . add_argument ( ' --verbose ' ,
action = ' store_true ' ,
help = ' Enable verbose logging. ' )
parser . add_argument ( ' --cmdline ' , required = True , nargs = argparse . REMAINDER ,
parser . add_argument ( ' --cmdline ' ,
required = True ,
nargs = argparse . REMAINDER ,
help = ' command line args passed to ninja. ' )
args = parser . parse_args ( )
@ -186,7 +191,6 @@ def main():
if not IsGoogler ( args . server ) :
return 0
ninjalog = args . ninjalog or GetNinjalog ( args . cmdline )
if not os . path . isfile ( ninjalog ) :
logging . warn ( " ninjalog is not found in %s " , ninjalog )
@ -210,18 +214,20 @@ def main():
g . write ( json . dumps ( metadata ) )
h = httplib2 . Http ( )
resp_headers , content = h . request (
' https:// ' + args . server + ' /upload_ninja_log/ ' , ' POST ' ,
body = output . getvalue ( ) , headers = { ' Content-Encoding ' : ' gzip ' } )
resp_headers , content = h . request ( ' https:// ' + args . server +
' /upload_ninja_log/ ' ,
' POST ' ,
body = output . getvalue ( ) ,
headers = { ' Content-Encoding ' : ' gzip ' } )
if resp_headers . status != 200 :
logging . warn ( " unexpected status code for response: %s " ,
resp_headers . status )
logging . warn ( " unexpected status code for response: %s " , resp_headers . status )
return 1
logging . info ( ' response header: %s ' , resp_headers )
logging . info ( ' response content: %s ' , content )
return 0
if __name__ == ' __main__ ' :
sys . exit ( main ( ) )