2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Creates IPC fuzzer packages suitable for uploading to ClusterFuzz. Stores
7 the packages into chrome build directory. See fuzzer_list below for the list of
12 import distutils
.archive_util
18 class CFPackageBuilder
:
26 desc
= 'Builder of IPC fuzzer packages for ClusterFuzz'
27 parser
= argparse
.ArgumentParser(description
=desc
)
28 parser
.add_argument('--out-dir', dest
='out_dir', default
='out',
29 help='output directory under src/ directory')
30 parser
.add_argument('--build-type', dest
='build_type', default
='Release',
31 help='Debug vs. Release build')
32 self
.args
= parser
.parse_args()
35 script_path
= os
.path
.realpath(__file__
)
36 self
.mutate_dir
= os
.path
.dirname(script_path
)
37 src_dir
= os
.path
.join(self
.mutate_dir
, os
.pardir
, os
.pardir
, os
.pardir
)
38 src_dir
= os
.path
.abspath(src_dir
)
39 out_dir
= os
.path
.join(src_dir
, self
.args
.out_dir
)
40 self
.build_dir
= os
.path
.join(out_dir
, self
.args
.build_type
)
42 def enter_tmp_workdir(self
):
43 self
.old_cwd
= os
.getcwd()
44 self
.work_dir
= tempfile
.mkdtemp()
45 os
.chdir(self
.work_dir
)
47 def rm_tmp_workdir(self
):
48 os
.chdir(self
.old_cwd
)
49 shutil
.rmtree(self
.work_dir
)
51 def build_package(self
, fuzzer
):
53 fuzzer_src_path
= os
.path
.join(self
.mutate_dir
, fuzzer
+ '.py')
54 fuzzer_dst_path
= os
.path
.join(fuzzer
, 'run.py')
55 shutil
.copyfile(fuzzer_src_path
, fuzzer_dst_path
)
56 distutils
.archive_util
.make_zipfile(fuzzer
, fuzzer
)
57 package_name
= fuzzer
+ '.zip'
58 shutil
.copy(package_name
, self
.build_dir
)
59 final_package_path
= os
.path
.join(self
.build_dir
, package_name
)
60 print 'Built %s' % final_package_path
65 self
.enter_tmp_workdir()
66 for fuzzer
in self
.fuzzer_list
:
67 self
.build_package(fuzzer
)
71 if __name__
== "__main__":
72 builder
= CFPackageBuilder()
73 sys
.exit(builder
.main())