Use the correct svn revision in --build-llvm-next builds

Bug: http://b/149832468

They were set to the revision of the current stable release instead.

Test: build.py --build-llvm-next
Change-Id: I1c42d090e78d5bb15d9eeec65d0bcf2c9395c79b
diff --git a/android_version.py b/android_version.py
index 7b0c44c..6ef185c 100644
--- a/android_version.py
+++ b/android_version.py
@@ -16,6 +16,12 @@
 #
 
 patch_level = '4'
-svn_revision = 'r377782b'
+_svn_revision = 'r377782b'
 # svn_revision_next will be newer than the official svn_revision in the future.
-svn_revision_next = 'r380035'
+_svn_revision_next = 'r380035'
+
+def get_svn_revision(build_llvm_next):
+    if build_llvm_next:
+        return _svn_revision_next
+    else:
+        return _svn_revision
diff --git a/build.py b/build.py
index 8faf6d7..f60aa99 100755
--- a/build.py
+++ b/build.py
@@ -52,6 +52,7 @@
 # TODO (Pirama): Put all the build options in a global so it's easy to refer to
 # them instead of plumbing flags through function parameters.
 BUILD_LLDB = False
+BUILD_LLVM_NEXT = False
 
 def logger():
     """Returns the module level logger."""
@@ -89,7 +90,8 @@
 
 
 def pgo_profdata_filename():
-    base_revision = android_version.svn_revision.rstrip(string.ascii_lowercase)
+    svn_revision = android_version.get_svn_revision(BUILD_LLVM_NEXT)
+    base_revision = svn_revision.rstrip(string.ascii_lowercase)
     return '%s.profdata' % base_revision
 
 def pgo_profdata_file(profdata_file):
@@ -899,7 +901,7 @@
     cmake_defines['LLVM_TARGETS_TO_BUILD'] = targets
     cmake_defines['LLVM_BUILD_LLVM_DYLIB'] = 'ON'
     cmake_defines['CLANG_VENDOR'] = 'Android (' + build_name + ' based on ' + \
-        android_version.svn_revision + ') '
+        android_version.get_svn_revision(BUILD_LLVM_NEXT) + ') '
     cmake_defines['LLVM_BINUTILS_INCDIR'] = utils.android_path(
         'toolchain/binutils/binutils-2.27/include')
 
@@ -1778,7 +1780,8 @@
     version_file_path = os.path.join(install_dir, 'AndroidVersion.txt')
     with open(version_file_path, 'w') as version_file:
         version_file.write('{}\n'.format(version.long_version()))
-        version_file.write('based on {}\n'.format(android_version.svn_revision))
+        svn_revision = android_version.get_svn_revision(BUILD_LLVM_NEXT)
+        version_file.write('based on {}\n'.format(svn_revision))
 
     # Create RBE input files.
     if is_linux:
@@ -1959,8 +1962,9 @@
     do_strip_host_package = do_strip and not args.debug
 
     # TODO (Pirama): Avoid using global statement
-    global BUILD_LLDB
+    global BUILD_LLDB, BUILD_LLVM_NEXT
     BUILD_LLDB = 'lldb' not in args.no_build
+    BUILD_LLVM_NEXT = args.build_llvm_next
 
     need_host = utils.host_is_darwin() or ('linux' not in args.no_build)
     need_windows = utils.host_is_linux() and \
diff --git a/source_manager.py b/source_manager.py
index 3e38971..daae834 100644
--- a/source_manager.py
+++ b/source_manager.py
@@ -59,15 +59,6 @@
     subprocess.check_call(patch_manager_cmd, env=env)
 
 
-def _get_svn_version_to_build(build_llvm_next):
-    if build_llvm_next:
-        rev = android_version.svn_revision_next
-    else:
-        rev = android_version.svn_revision
-    # strip the leading 'r' and letter suffix, e.g., r377782b => 377782
-    return rev[1:].rstrip(string.ascii_lowercase)
-
-
 def setup_sources(source_dir, build_llvm_next):
     """Setup toolchain sources into source_dir.
 
@@ -99,7 +90,10 @@
     # patch source tree
     patch_dir = utils.android_path('toolchain', 'llvm_android', 'patches')
     patch_json = os.path.join(patch_dir, 'PATCHES.json')
-    svn_version = _get_svn_version_to_build(build_llvm_next)
+    svn_version = android_version.get_svn_revision(build_llvm_next)
+    # strip the leading 'r' and letter suffix, e.g., r377782b => 377782
+    svn_version = svn_version[1:].rstrip(string.ascii_lowercase)
+
     apply_patches(tmp_source_dir, svn_version, patch_json, patch_dir)
 
     # Copy tmp_source_dir to source_dir if they are different.  This avoids