1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Common utilities for all buildbot scripts that specifically don't rely
6 on having a full chromium checkout.
13 SCRIPT_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
14 SDK_SRC_DIR
= os
.path
.dirname(SCRIPT_DIR
)
15 SDK_DIR
= os
.path
.dirname(SDK_SRC_DIR
)
16 SRC_DIR
= os
.path
.dirname(SDK_DIR
)
17 sys
.path
.append(os
.path
.join(SDK_SRC_DIR
, 'tools'))
22 """Returns True if this script is running on an SDK builder.
24 False means it is either running on a trybot, or a user's machine.
27 (win|mac|linux)_nacl_sdk
30 (windows|mac|linux)-sdk-multi(rel)?"""
31 return '-sdk-multi' in os
.getenv('BUILDBOT_BUILDERNAME', '')
35 """Returns True if this script is running on an SDK trybot.
37 False means it is either running on an SDK builder, or a user's machine.
39 See IsSDKBuilder above for trybot/buildbot names."""
40 return '_nacl_sdk' in os
.getenv('BUILDBOT_BUILDERNAME', '')
44 """Write and error to stderr, then exit with 1 signaling failure."""
45 sys
.stderr
.write(msg
+ '\n')
50 """Annotate a buildbot build step."""
52 print '\n@@@BUILD_STEP %s@@@' % name
56 def Run(args
, cwd
=None, env
=None, shell
=False):
57 """Start a process with the provided arguments.
59 Starts a process in the provided directory given the provided arguments. If
60 shell is not False, the process is launched via the shell to provide shell
61 interpretation of the arguments. Shell behavior can differ between platforms
62 so this should be avoided when not using platform dependent shell scripts."""
63 print 'Running: ' + ' '.join(args
)
66 subprocess
.check_call(args
, cwd
=cwd
, env
=env
, shell
=shell
)
71 def CopyDir(src
, dst
, excludes
=('.svn', '*/.svn')):
72 """Recursively copy a directory using."""
73 args
= ['-r', src
, dst
]
75 args
.append('--exclude=' + exc
)
76 print 'cp -r %s %s' % (src
, dst
)
77 if os
.path
.abspath(src
) == os
.path
.abspath(dst
):
78 ErrorExit('ERROR: Copying directory onto itself: ' + src
)
82 def CopyFile(src
, dst
):
83 print 'cp %s %s' % (src
, dst
)
84 if os
.path
.abspath(src
) == os
.path
.abspath(dst
):
85 ErrorExit('ERROR: Copying file onto itself: ' + src
)
91 """Remove the provided path."""
93 oshelpers
.Remove(['-fr', dst
])
97 """Create the path including all parent directories as needed."""
98 print 'mkdir -p ' + dst
99 oshelpers
.Mkdir(['-p', dst
])
103 """Move the path src to dst."""
104 print 'mv -f %s %s' % (src
, dst
)
105 oshelpers
.Move(['-f', src
, dst
])
109 """Remove the provided file."""
111 oshelpers
.Remove(['-f', dst
])
114 BOT_GSUTIL
= '/b/build/scripts/slave/gsutil'
115 LOCAL_GSUTIL
= 'gsutil'
119 if os
.environ
.get('BUILDBOT_BUILDERNAME'):
125 def Archive(filename
, bucket_path
, cwd
=None, step_link
=True):
126 """Upload the given filename to Google Store."""
127 full_dst
= 'gs://%s/%s' % (bucket_path
, filename
)
129 subprocess
.check_call(
130 '%s cp -a public-read %s %s' % (GetGsutil(), filename
, full_dst
),
133 url
= 'https://commondatastorage.googleapis.com/'\
134 '%s/%s' % (bucket_path
, filename
)
136 print '@@@STEP_LINK@download@%s@@@' % url