Reuse more upload_to_android and allow removing flag on Android

Bug: skia:
Change-Id: I8c84b63d01ead32bf4aa71550f6fa84ddfcf480f
Reviewed-on: https://skia-review.googlesource.com/63743
Reviewed-by: Ravi Mistry <rmistry@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
This commit is contained in:
Yuqian Li 2017-10-31 10:14:25 -04:00 committed by Skia Commit-Bot
parent 7484dbd1df
commit ee6784d268
2 changed files with 76 additions and 43 deletions

View File

@ -108,26 +108,32 @@ About to run repo init. If it hangs asking you to run glogin then please:
return repo_binary
def upload_to_android(work_dir, change_num, debug):
repo_binary = init_work_dir(work_dir)
# Create repo branch.
subprocess.check_call('%s start %s .' % (repo_binary, REPO_BRANCH_NAME),
shell=True)
try:
change_details = get_change_details(change_num)
class Modifier:
def modify(self):
raise NotImplementedError
def get_user_msg(self):
raise NotImplementedError
class FetchModifier(Modifier):
def __init__(self, change_num, debug):
self.change_num = change_num
self.debug = debug
def modify(self):
# Download and cherry-pick the patch.
change_details = get_change_details(self.change_num)
latest_patchset = len(change_details['revisions'])
mod = int(change_num) % 100
mod = int(self.change_num) % 100
download_ref = 'refs/changes/%s/%s/%s' % (
str(mod).zfill(2), change_num, latest_patchset)
str(mod).zfill(2), self.change_num, latest_patchset)
subprocess.check_call(
'git fetch https://skia.googlesource.com/skia %s' % download_ref,
shell=True)
subprocess.check_call('git cherry-pick FETCH_HEAD', shell=True)
if debug:
if self.debug:
# Add SK_DEBUG to SkUserConfig.h.
with open(SK_USER_CONFIG_PATH, 'a') as f:
f.write('#ifndef SK_DEBUG\n')
@ -145,17 +151,70 @@ def upload_to_android(work_dir, change_num, debug):
'[DO ' + 'NOT ' + 'SUBMIT] %s\n\n'
'Test: Presubmit checks will test this change.' % (
original_commit_message))
subprocess.check_call('git commit --amend -m "%s"' % new_commit_message,
shell=True)
# Upload to Android Gerrit.
subprocess.check_call('%s upload --verify' % repo_binary, shell=True)
print """
def get_user_msg(self):
return """
Open the above URL and trigger TH by checking 'Presubmit-Ready'.
You can download binaries (if required) from the TH link after it completes.
"""
# Add a legacy flag if it doesn't exist, or remove it if it exists.
class AndroidLegacyFlagModifier(Modifier):
def __init__(self, flag):
self.flag = flag
self.verb = "Unknown"
def modify(self):
flag_line = " #define %s\n" % self.flag
config_file = os.path.join('include', 'config', 'SkUserConfigManual.h')
with open(config_file) as f:
lines = f.readlines()
if flag_line not in lines:
lines.insert(
lines.index("#endif // SkUserConfigManual_DEFINED\n"), flag_line)
verb = "Add"
else:
lines.remove(flag_line)
verb = "Remove"
with open(config_file, 'w') as f:
for line in lines:
f.write(line)
subprocess.check_call('git add %s' % config_file, shell=True)
message = '%s %s\n\nTest: Presubmit checks will test this change.' % (
verb, self.flag)
subprocess.check_call('git commit -m "%s"' % message, shell=True)
def get_user_msg(self):
return """
Please open the above URL to review and land the change.
"""
def upload_to_android(work_dir, modifier):
repo_binary = init_work_dir(work_dir)
# Create repo branch.
subprocess.check_call('%s start %s .' % (repo_binary, REPO_BRANCH_NAME),
shell=True)
try:
modifier.modify()
# Upload to Android Gerrit.
subprocess.check_call('%s upload --verify' % repo_binary, shell=True)
print modifier.get_user_msg()
finally:
# Abandon repo branch.
subprocess.call('%s abandon %s' % (repo_binary, REPO_BRANCH_NAME),
@ -176,7 +235,7 @@ def main():
'--debug', '-d', action='store_true', default=False,
help='Adds SK_DEBUG to SkUserConfig.h.')
args = parser.parse_args()
upload_to_android(args.work_dir, args.change_num, args.debug)
upload_to_android(args.work_dir, FetchModifier(args.change_num, args.debug))
if __name__ == '__main__':

View File

@ -43,37 +43,11 @@ def insert_at(filename, pattern, offset, content):
def add_to_android(args):
REPO_BRANCH_NAME = "flag"
sys.path.append(ANDROID_TOOLS_DIR)
import upload_to_android
repo_binary = upload_to_android.init_work_dir(args.android_dir);
# Create repo branch.
subprocess.check_call('%s start %s .' % (repo_binary, REPO_BRANCH_NAME),
shell=True)
try:
# Add flag to SkUserConfigManual.h.
config_file = os.path.join('include', 'config', 'SkUserConfigManual.h')
insert_at(config_file,
"#endif // SkUserConfigManual_DEFINED\n",
0,
" #define %s\n" % args.flag)
subprocess.check_call('git add %s' % config_file, shell=True)
message = ('Add %s\n\n'
'Test: Presubmit checks will test this change.' % args.flag)
subprocess.check_call('git commit -m "%s"' % message, shell=True)
# Upload to Android Gerrit.
subprocess.check_call('%s upload --verify' % repo_binary, shell=True)
finally:
# Remove repo branch
subprocess.check_call('%s abandon flag' % repo_binary, shell=True)
modifier = upload_to_android.AndroidLegacyFlagModifier(args.flag)
upload_to_android.upload_to_android(args.android_dir, modifier)
def add_to_chromium(args):