3
3
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
4
5
5
import contextlib
6
+ import fnmatch
6
7
import io
8
+ import os
7
9
import pathlib
8
10
import shutil
9
11
import tarfile
@@ -61,9 +63,6 @@ def run(self, program, user="build", environment=None):
61
63
62
64
container_exec (self .container , program , user = user , environment = environment )
63
65
64
- def run_capture (self , command , user = None ):
65
- return self .container .exec_run (command , user = user )
66
-
67
66
def get_tools_archive (self , dest , name ):
68
67
log ("copying container files to %s" % dest )
69
68
data = container_get_archive (self .container , "/build/out/tools/%s" % name )
@@ -80,6 +79,15 @@ def get_archive(self, path, as_tar=False):
80
79
else :
81
80
return data .getvalue ()
82
81
82
+ def find_output_files (self , base_path , pattern ):
83
+ command = ["/usr/bin/find" , "/build/out/%s" % base_path , "-name" , pattern ]
84
+
85
+ for line in self .container .exec_run (command , user = "build" )[1 ].splitlines ():
86
+ if not line .strip ():
87
+ continue
88
+
89
+ yield line [len ("/build/out/%s/" % base_path ) :].decode ("ascii" )
90
+
83
91
84
92
class TempdirContext (object ):
85
93
def __init__ (self , td ):
@@ -143,6 +151,17 @@ def get_tools_archive(self, dest, name):
143
151
with dest .open ("wb" ) as fh :
144
152
create_tar_from_directory (fh , self .td / "out" / "tools" )
145
153
154
+ def find_output_files (self , base_path , pattern ):
155
+ base = str (self .td / "out" / base_path )
156
+
157
+ for root , dirs , files in os .walk (base ):
158
+ dirs .sort ()
159
+
160
+ for f in sorted (files ):
161
+ if fnmatch .fnmatch (f , pattern ):
162
+ full = os .path .join (root , f )
163
+ yield full [len (base ) + 1 :]
164
+
146
165
147
166
@contextlib .contextmanager
148
167
def build_environment (client , image ):
0 commit comments