Add CreateTarball library function.

BUG=None
TEST=unit tests, remote trybots.

Change-Id: I0d25b520e13760242698424878f0f05ccdc25de6
Reviewed-on: https://gerrit.chromium.org/gerrit/38878
Commit-Ready: Ryan Cui <rcui@chromium.org>
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: Ryan Cui <rcui@chromium.org>
diff --git a/scripts/cros_generate_sysroot.py b/scripts/cros_generate_sysroot.py
index b86bbbf..860aeea 100644
--- a/scripts/cros_generate_sysroot.py
+++ b/scripts/cros_generate_sysroot.py
@@ -77,11 +77,8 @@
          '--usepkg-exclude=%s' % self.options.package, self.options.package])
 
   def _CreateTarball(self):
-    xz = cros_build_lib.FindCompressor(cros_build_lib.COMP_XZ)
-    cros_build_lib.SudoRunCommand(
-        ['tar', '-I', xz, '-cf',
-         os.path.join(self.options.out_dir, self.options.out_file), '.'],
-        cwd=self.sysroot)
+    target = os.path.join(self.options.out_dir, self.options.out_file)
+    cros_build_lib.CreateTarball(target, self.sysroot, sudo=True)
 
   def Perform(self):
     """Generate the sysroot."""