Revert "Merged all Chromoting Host code into remoting_core.dll (Windows)."
[chromium-blink-merge.git] / native_client_sdk / src / build_tools / buildbot_common.py
blob82bbeaa195c822c52ee560c50997456b903b4cb7
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.
7 """
9 import os
10 import subprocess
11 import sys
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'))
19 import oshelpers
21 def IsSDKBuilder():
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.
26 Trybot names:
27 (win|mac|linux)_nacl_sdk
29 Builder names:
30 (windows|mac|linux)-sdk-multi(rel)?"""
31 return '-sdk-multi' in os.getenv('BUILDBOT_BUILDERNAME', '')
34 def IsSDKTrybot():
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', '')
43 def ErrorExit(msg):
44 """Write and error to stderr, then exit with 1 signaling failure."""
45 sys.stderr.write(msg + '\n')
46 sys.exit(1)
49 def BuildStep(name):
50 """Annotate a buildbot build step."""
51 sys.stdout.flush()
52 print '\n@@@BUILD_STEP %s@@@' % name
53 sys.stdout.flush()
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)
64 sys.stdout.flush()
65 sys.stderr.flush()
66 subprocess.check_call(args, cwd=cwd, env=env, shell=shell)
67 sys.stdout.flush()
68 sys.stderr.flush()
71 def CopyDir(src, dst, excludes=('.svn', '*/.svn')):
72 """Recursively copy a directory using."""
73 args = ['-r', src, dst]
74 for exc in excludes:
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)
79 oshelpers.Copy(args)
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)
86 args = [src, dst]
87 oshelpers.Copy(args)
90 def RemoveDir(dst):
91 """Remove the provided path."""
92 print 'rm -fr ' + dst
93 oshelpers.Remove(['-fr', dst])
96 def MakeDir(dst):
97 """Create the path including all parent directories as needed."""
98 print 'mkdir -p ' + dst
99 oshelpers.Mkdir(['-p', dst])
102 def Move(src, dst):
103 """Move the path src to dst."""
104 print 'mv -f %s %s' % (src, dst)
105 oshelpers.Move(['-f', src, dst])
108 def RemoveFile(dst):
109 """Remove the provided file."""
110 print 'rm ' + dst
111 oshelpers.Remove(['-f', dst])
114 BOT_GSUTIL = '/b/build/scripts/slave/gsutil'
115 LOCAL_GSUTIL = 'gsutil'
118 def GetGsutil():
119 if os.environ.get('BUILDBOT_BUILDERNAME'):
120 return BOT_GSUTIL
121 else:
122 return LOCAL_GSUTIL
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),
131 shell=True,
132 cwd=cwd)
133 url = 'https://commondatastorage.googleapis.com/'\
134 '%s/%s' % (bucket_path, filename)
135 if step_link:
136 print '@@@STEP_LINK@download@%s@@@' % url
137 sys.stdout.flush()