diff options
author | 2018-05-03 00:36:18 -0700 | |
---|---|---|
committer | 2018-05-03 00:37:38 -0700 | |
commit | 0810170875fa8c6415369601889377525b26c9c4 (patch) | |
tree | ed25551993b415d51607b408fb1dc701a7ce8163 /tools | |
parent | db50b5e3198071eb9836b4ff9b2ac6263cbea1dc (diff) |
AddFiles will recursively add files when a directory is encountered
This PR provides support for directories as inputs to pkg_rpm, which is useful for RPMs that contain a lot of files, and one doesn't want to exceed the shell argument buffer size. Files are recursively added from the top-level parent directory.
Closes #5097.
PiperOrigin-RevId: 195211382
Diffstat (limited to 'tools')
-rw-r--r-- | tools/build_defs/pkg/make_rpm.py | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/tools/build_defs/pkg/make_rpm.py b/tools/build_defs/pkg/make_rpm.py index f93224d167..c008a01a6c 100644 --- a/tools/build_defs/pkg/make_rpm.py +++ b/tools/build_defs/pkg/make_rpm.py @@ -131,6 +131,14 @@ def CopyAndRewrite(input_file, output_file, replacements=None): def Which(program): + """Search for the given program in the PATH. + + Args: + program: The program to search for. + + Returns: + The full path to the program. + """ def IsExe(fpath): return os.path.isfile(fpath) and os.access(fpath, os.X_OK) @@ -173,9 +181,21 @@ class RpmBuilder(object): self.rpmbuild_path = FindRpmbuild() self.rpm_path = None - def AddFiles(self, files): - """Add a set of files to the current RPM.""" - self.files += files + def AddFiles(self, paths, root=''): + """Add a set of files to the current RPM. + + If an item in paths is a directory, its files are recursively added. + + Args: + paths: The files to add. + root: The root of the filesystem to search for files. Defaults to ''. + """ + for path in paths: + full_path = os.path.join(root, path) + if os.path.isdir(full_path): + self.AddFiles(os.listdir(full_path), full_path) + else: + self.files.append(full_path) def SetupWorkdir(self, spec_file, original_dir): """Create the needed structure in the workdir.""" |