aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/build_defs/pkg/build_tar.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/build_defs/pkg/build_tar.py')
-rw-r--r--tools/build_defs/pkg/build_tar.py43
1 files changed, 40 insertions, 3 deletions
diff --git a/tools/build_defs/pkg/build_tar.py b/tools/build_defs/pkg/build_tar.py
index e5428041a3..90d602d3d3 100644
--- a/tools/build_defs/pkg/build_tar.py
+++ b/tools/build_defs/pkg/build_tar.py
@@ -34,6 +34,11 @@ gflags.DEFINE_multistring('empty_file', [], 'An empty file to add to the layer')
gflags.DEFINE_multistring('empty_dir', [], 'An empty dir to add to the layer')
+gflags.DEFINE_multistring(
+ 'empty_root_dir',
+ [],
+ 'An empty dir to add to the layer')
+
gflags.DEFINE_multistring('tar', [], 'A tar file to add to the layer')
gflags.DEFINE_multistring('deb', [], 'A debian package to add to the layer')
@@ -72,6 +77,9 @@ gflags.DEFINE_multistring('owner_names', None,
'Specify the owner names of individual files, e.g. '
'path/to/file=root.root.')
+gflags.DEFINE_string(
+ 'root_directory', './', 'Default root directory is named "."')
+
FLAGS = gflags.FLAGS
@@ -81,13 +89,18 @@ class TarFile(object):
class DebError(Exception):
pass
- def __init__(self, output, directory, compression):
+ def __init__(self, output, directory, compression, root_directory):
self.directory = directory
self.output = output
self.compression = compression
+ self.root_directory = root_directory
def __enter__(self):
- self.tarfile = archive.TarFileWriter(self.output, self.compression)
+ self.tarfile = archive.TarFileWriter(
+ self.output,
+ self.compression,
+ self.root_directory
+ )
return self
def __exit__(self, t, v, traceback):
@@ -175,6 +188,23 @@ class TarFile(object):
self.add_empty_file(
destpath, mode=mode, ids=ids, names=names, kind=tarfile.DIRTYPE)
+ def add_empty_root_dir(self, destpath, mode=None, ids=None, names=None):
+ """Add a directory to the root of the tar file.
+
+ Args:
+ destpath: the name of the directory in the layer
+ mode: force to set the specified mode, defaults to 644
+ ids: (uid, gid) for the file to set ownership
+ names: (username, groupname) for the file to set ownership.
+
+ An empty directory will be created as `destfile` in the root layer.
+ """
+ original_root_directory = self.tarfile.root_directory
+ self.tarfile.root_directory = destpath
+ self.add_empty_dir(
+ destpath, mode=mode, ids=ids, names=names)
+ self.tarfile.root_directory = original_root_directory
+
def add_tar(self, tar):
"""Merge a tar file into the destination tar file.
@@ -265,7 +295,12 @@ def main(unused_argv):
ids_map[f] = (int(user), int(group))
# Add objects to the tar file
- with TarFile(FLAGS.output, FLAGS.directory, FLAGS.compression) as output:
+ with TarFile(
+ FLAGS.output,
+ FLAGS.directory,
+ FLAGS.compression,
+ FLAGS.root_directory
+ ) as output:
def file_attributes(filename):
if filename[0] == '/':
@@ -283,6 +318,8 @@ def main(unused_argv):
output.add_empty_file(f, **file_attributes(f))
for f in FLAGS.empty_dir:
output.add_empty_dir(f, **file_attributes(f))
+ for f in FLAGS.empty_root_dir:
+ output.add_empty_root_dir(f, **file_attributes(f))
for tar in FLAGS.tar:
output.add_tar(tar)
for deb in FLAGS.deb: