def test_unified_build_finder(self): self.create_both('chrome.manifest', 'a\nb\nc\n') self.create_one('a', 'chrome/chrome.manifest', 'a\nb\nc\n') self.create_one('b', 'chrome/chrome.manifest', 'b\nc\na\n') self.create_one('a', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '</body>', '</html>', ])) self.create_one('b', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>bar</div>', '</body>', '</html>', ])) finder = UnifiedBuildFinder(FileFinder(self.tmppath('a')), FileFinder(self.tmppath('b'))) self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/chrome.manifest')]), [('chrome.manifest', 'a\nb\nc\n'), ('chrome/chrome.manifest', 'a\nb\nc\n')]) self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/buildconfig.html')]), [('chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '<hr> </hr>', '<div>bar</div>', '</body>', '</html>', ]))]) xpi = MockDest() with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'foo') jar.add('bar', 'bar') foo_xpi = xpi.read() self.create_both('foo.xpi', foo_xpi) with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'bar') self.create_one('a', 'bar.xpi', foo_xpi) self.create_one('b', 'bar.xpi', xpi.read()) errors.out = StringIO() with self.assertRaises(AccumulatedErrors), errors.accumulate(): self.assertEqual([(f, c.open().read()) for f, c in finder.find('*.xpi')], [('foo.xpi', foo_xpi)]) errors.out = sys.stderr
def test_unified_build_finder(self): self.create_both('chrome.manifest', 'a\nb\nc\n') self.create_one('a', 'chrome/chrome.manifest', 'a\nb\nc\n') self.create_one('b', 'chrome/chrome.manifest', 'b\nc\na\n') self.create_one('a', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '</body>', '</html>', ])) self.create_one('b', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>bar</div>', '</body>', '</html>', ])) finder = UnifiedBuildFinder(self.tmppath('a'), self.tmppath('b')) self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/chrome.manifest')]), [('chrome.manifest', 'a\nb\nc\n'), ('chrome/chrome.manifest', 'a\nb\nc\n')]) self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/buildconfig.html')]), [('chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '<hr> </hr>', '<div>bar</div>', '</body>', '</html>', ]))])
def main(): parser = argparse.ArgumentParser( description= "Merge two builds of a Gecko-based application into a Universal build") parser.add_argument("app1", help="Directory containing the application") parser.add_argument("app2", help="Directory containing the application to merge") parser.add_argument( "--non-resource", nargs="+", metavar="PATTERN", default=[], help="Extra files not to be considered as resources", ) options = parser.parse_args() buildconfig.substs["OS_ARCH"] = "Darwin" buildconfig.substs["LIPO"] = os.environ.get("LIPO") app1_finder = UnpackFinder(FileFinder(options.app1, find_executables=True)) app2_finder = UnpackFinder(FileFinder(options.app2, find_executables=True)) app_finder = UnifiedBuildFinder(app1_finder, app2_finder) copier = FileCopier() compress = min(app1_finder.compressed, JAR_DEFLATED) if app1_finder.kind == "flat": formatter = FlatFormatter(copier) elif app1_finder.kind == "jar": formatter = JarFormatter(copier, compress=compress) elif app1_finder.kind == "omni": formatter = OmniJarFormatter( copier, app1_finder.omnijar, compress=compress, non_resources=options.non_resource, ) with errors.accumulate(): packager = SimplePackager(formatter) for p, f in app_finder: packager.add(p, f) packager.close() # Transplant jar preloading information. for path, log in six.iteritems(app1_finder.jarlogs): assert isinstance(copier[path], Jarrer) copier[path].preload(log) copier.copy(options.app1, skip_if_older=False)
def test_unified_build_finder(self): finder = UnifiedBuildFinder(FileFinder(self.tmppath('a')), FileFinder(self.tmppath('b'))) # Test chrome.manifest unification self.create_both('chrome.manifest', 'a\nb\nc\n') self.create_one('a', 'chrome/chrome.manifest', 'a\nb\nc\n') self.create_one('b', 'chrome/chrome.manifest', 'b\nc\na\n') self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/chrome.manifest')]), [('chrome.manifest', 'a\nb\nc\n'), ('chrome/chrome.manifest', 'a\nb\nc\n')]) # Test buildconfig.html unification self.create_one('a', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '</body>', '</html>', ])) self.create_one('b', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>bar</div>', '</body>', '</html>', ])) self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/buildconfig.html')]), [('chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '<hr> </hr>', '<div>bar</div>', '</body>', '</html>', ]))]) # Test xpi file unification xpi = MockDest() with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'foo') jar.add('bar', 'bar') foo_xpi = xpi.read() self.create_both('foo.xpi', foo_xpi) with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'bar') self.create_one('a', 'bar.xpi', foo_xpi) self.create_one('b', 'bar.xpi', xpi.read()) errors.out = StringIO() with self.assertRaises(AccumulatedErrors), errors.accumulate(): self.assertEqual([(f, c.open().read()) for f, c in finder.find('*.xpi')], [('foo.xpi', foo_xpi)]) errors.out = sys.stderr # Test install.rdf unification x86_64 = 'Darwin_x86_64-gcc3' x86 = 'Darwin_x86-gcc3' target_tag = '<{em}targetPlatform>{platform}</{em}targetPlatform>' target_attr = '{em}targetPlatform="{platform}" ' rdf_tag = ''.join([ '<{RDF}Description {em}bar="bar" {em}qux="qux">', '<{em}foo>foo</{em}foo>', '{targets}', '<{em}baz>baz</{em}baz>', '</{RDF}Description>' ]) rdf_attr = ''.join([ '<{RDF}Description {em}bar="bar" {attr}{em}qux="qux">', '{targets}', '<{em}foo>foo</{em}foo><{em}baz>baz</{em}baz>', '</{RDF}Description>' ]) for descr_ns, target_ns in (('RDF:', ''), ('', 'em:'), ('RDF:', 'em:')): # First we need to infuse the above strings with our namespaces and # platform values. ns = { 'RDF': descr_ns, 'em': target_ns } target_tag_x86_64 = target_tag.format(platform=x86_64, **ns) target_tag_x86 = target_tag.format(platform=x86, **ns) target_attr_x86_64 = target_attr.format(platform=x86_64, **ns) target_attr_x86 = target_attr.format(platform=x86, **ns) tag_x86_64 = rdf_tag.format(targets=target_tag_x86_64, **ns) tag_x86 = rdf_tag.format(targets=target_tag_x86, **ns) tag_merged = rdf_tag.format(targets=target_tag_x86_64 + target_tag_x86, **ns) tag_empty = rdf_tag.format(targets="", **ns) attr_x86_64 = rdf_attr.format(attr=target_attr_x86_64, targets="", **ns) attr_x86 = rdf_attr.format(attr=target_attr_x86, targets="", **ns) attr_merged = rdf_attr.format(attr="", targets=target_tag_x86_64 + target_tag_x86, **ns) # This table defines the test cases, columns "a" and "b" being the # contents of the install.rdf of the respective platform and # "result" the exepected merged content after unification. testcases = ( #_____a_____ _____b_____ ___result___# (tag_x86_64, tag_x86, tag_merged ), (tag_x86_64, tag_empty, tag_empty ), (tag_empty, tag_x86, tag_empty ), (tag_empty, tag_empty, tag_empty ), (attr_x86_64, attr_x86, attr_merged ), (tag_x86_64, attr_x86, tag_merged ), (attr_x86_64, tag_x86, attr_merged ), (attr_x86_64, tag_empty, tag_empty ), (tag_empty, attr_x86, tag_empty ) ) # Now create the files from the above table and compare results = [] for emid, (rdf_a, rdf_b, result) in enumerate(testcases): filename = 'ext/id{0}/install.rdf'.format(emid) self.create_one('a', filename, rdf_a) self.create_one('b', filename, rdf_b) results.append((filename, result)) self.assertEqual(sorted([(f, c.open().read()) for f, c in finder.find('**/install.rdf')]), results)
def main(): parser = ArgumentParser() parser.add_argument('-D', dest='defines', action='append', metavar="VAR[=VAL]", help='Define a variable') parser.add_argument('--format', default='omni', help='Choose the chrome format for packaging ' + '(omni, jar or flat ; default: %(default)s)') parser.add_argument('--removals', default=None, help='removed-files source file') parser.add_argument('--ignore-errors', action='store_true', default=False, help='Transform errors into warnings.') parser.add_argument('--minify', action='store_true', default=False, help='Make some files more compact while packaging') parser.add_argument('--minify-js', action='store_true', help='Minify JavaScript files while packaging.') parser.add_argument('--js-binary', help='Path to js binary. This is used to verify ' 'minified JavaScript. If this is not defined, ' 'minification verification will not be performed.') parser.add_argument('--jarlog', default='', help='File containing jar ' + 'access logs') parser.add_argument('--optimizejars', action='store_true', default=False, help='Enable jar optimizations') parser.add_argument('--unify', default='', help='Base directory of another build to unify with') parser.add_argument('manifest', default=None, nargs='?', help='Manifest file name') parser.add_argument('source', help='Source directory') parser.add_argument('destination', help='Destination directory') parser.add_argument('--non-resource', nargs='+', metavar='PATTERN', default=[], help='Extra files not to be considered as resources') args = parser.parse_args() defines = dict(buildconfig.defines) if args.ignore_errors: errors.ignore_errors() if args.defines: for name, value in [split_define(d) for d in args.defines]: defines[name] = value copier = FileCopier() if args.format == 'flat': formatter = FlatFormatter(copier) elif args.format == 'jar': formatter = JarFormatter(copier, optimize=args.optimizejars) elif args.format == 'omni': formatter = OmniJarFormatter(copier, buildconfig.substs['OMNIJAR_NAME'], optimize=args.optimizejars, non_resources=args.non_resource) else: errors.fatal('Unknown format: %s' % args.format) # Adjust defines according to the requested format. if isinstance(formatter, OmniJarFormatter): defines['MOZ_OMNIJAR'] = 1 elif 'MOZ_OMNIJAR' in defines: del defines['MOZ_OMNIJAR'] binpath = '' if 'BINPATH' in defines: binpath = SimpleManifestSink.normalize_path(defines['BINPATH']) while binpath.startswith('/'): binpath = binpath[1:] if args.unify: def is_native(path): path = os.path.abspath(path) return platform.machine() in mozpack.path.split(path) # Invert args.unify and args.source if args.unify points to the # native architecture. args.source, args.unify = sorted([args.source, args.unify], key=is_native, reverse=True) if is_native(args.source): launcher.tooldir = args.source elif not buildconfig.substs['CROSS_COMPILE']: launcher.tooldir = buildconfig.substs['LIBXUL_DIST'] with errors.accumulate(): finder_args = dict( minify=args.minify, minify_js=args.minify_js, ) if args.js_binary: finder_args['minify_js_verify_command'] = [ args.js_binary, os.path.join(os.path.abspath(os.path.dirname(__file__)), 'js-compare-ast.js') ] if args.unify: finder = UnifiedBuildFinder(FileFinder(args.source), FileFinder(args.unify), **finder_args) else: finder = FileFinder(args.source, **finder_args) if 'NO_PKG_FILES' in os.environ: sinkformatter = NoPkgFilesRemover(formatter, args.manifest is not None) else: sinkformatter = formatter sink = SimpleManifestSink(finder, sinkformatter) if args.manifest: preprocess_manifest(sink, args.manifest, defines) else: sink.add(Component(''), 'bin/*') sink.close(args.manifest is not None) if args.removals: lines = [l.lstrip() for l in open(args.removals).readlines()] removals_in = StringIO(''.join(lines)) removals_in.name = args.removals removals = RemovedFiles(copier) preprocess(removals_in, removals, defines) copier.add(mozpack.path.join(binpath, 'removed-files'), removals) # shlibsign libraries if launcher.can_launch(): for lib in SIGN_LIBS: libbase = mozpack.path.join(binpath, '%s%s') \ % (buildconfig.substs['DLL_PREFIX'], lib) libname = '%s%s' % (libbase, buildconfig.substs['DLL_SUFFIX']) if copier.contains(libname): copier.add( libbase + '.chk', LibSignFile(os.path.join(args.destination, libname))) # Setup preloading if args.jarlog and os.path.exists(args.jarlog): from mozpack.mozjar import JarLog log = JarLog(args.jarlog) for p, f in copier: if not isinstance(f, Jarrer): continue key = JarLog.canonicalize(os.path.join(args.destination, p)) if key in log: f.preload(log[key]) # Fill startup cache if isinstance(formatter, OmniJarFormatter) and launcher.can_launch() \ and buildconfig.substs['MOZ_DISABLE_STARTUPCACHE'] != '1': if buildconfig.substs['LIBXUL_SDK']: gre_path = mozpack.path.join(buildconfig.substs['LIBXUL_DIST'], 'bin') else: gre_path = None for base in sorted([[ p for p in [mozpack.path.join('bin', b), b] if os.path.exists(os.path.join(args.source, p)) ][0] for b in sink.packager.get_bases()]): if not gre_path: gre_path = base base_path = sink.normalize_path(base) if base_path in formatter.omnijars: precompile_cache(formatter.omnijars[base_path], args.source, gre_path, base) copier.copy(args.destination) generate_precomplete( os.path.normpath(os.path.join(args.destination, binpath)))
def test_unified_build_finder(self): finder = UnifiedBuildFinder(FileFinder(self.tmppath("a")), FileFinder(self.tmppath("b"))) # Test chrome.manifest unification self.create_both("chrome.manifest", "a\nb\nc\n") self.create_one("a", "chrome/chrome.manifest", "a\nb\nc\n") self.create_one("b", "chrome/chrome.manifest", "b\nc\na\n") self.assertEqual( sorted([(f, c.open().read().decode("utf-8")) for f, c in finder.find("**/chrome.manifest")]), [("chrome.manifest", "a\nb\nc\n"), ("chrome/chrome.manifest", "a\nb\nc\n")], ) # Test buildconfig.html unification self.create_one( "a", "chrome/browser/foo/buildconfig.html", "\n".join([ "<html>", " <body>", " <div>", " <h1>Build Configuration</h1>", " <div>foo</div>", " </div>", " </body>", "</html>", ]), ) self.create_one( "b", "chrome/browser/foo/buildconfig.html", "\n".join([ "<html>", " <body>", " <div>", " <h1>Build Configuration</h1>", " <div>bar</div>", " </div>", " </body>", "</html>", ]), ) self.assertEqual( sorted([(f, c.open().read().decode("utf-8")) for f, c in finder.find("**/buildconfig.html")]), [( "chrome/browser/foo/buildconfig.html", "\n".join([ "<html>", " <body>", " <div>", " <h1>Build Configuration</h1>", " <div>foo</div>", " <hr> </hr>", " <div>bar</div>", " </div>", " </body>", "</html>", ]), )], ) # Test xpi file unification xpi = MockDest() with JarWriter(fileobj=xpi, compress=True) as jar: jar.add("foo", "foo") jar.add("bar", "bar") foo_xpi = xpi.read() self.create_both("foo.xpi", foo_xpi) with JarWriter(fileobj=xpi, compress=True) as jar: jar.add("foo", "bar") self.create_one("a", "bar.xpi", foo_xpi) self.create_one("b", "bar.xpi", xpi.read()) errors.out = StringIO() with self.assertRaises(AccumulatedErrors), errors.accumulate(): self.assertEqual( [(f, c.open().read()) for f, c in finder.find("*.xpi")], [("foo.xpi", foo_xpi)], ) errors.out = sys.stderr # Test install.rdf unification x86_64 = "Darwin_x86_64-gcc3" x86 = "Darwin_x86-gcc3" target_tag = "<{em}targetPlatform>{platform}</{em}targetPlatform>" target_attr = '{em}targetPlatform="{platform}" ' rdf_tag = "".join([ '<{RDF}Description {em}bar="bar" {em}qux="qux">', "<{em}foo>foo</{em}foo>", "{targets}", "<{em}baz>baz</{em}baz>", "</{RDF}Description>", ]) rdf_attr = "".join([ '<{RDF}Description {em}bar="bar" {attr}{em}qux="qux">', "{targets}", "<{em}foo>foo</{em}foo><{em}baz>baz</{em}baz>", "</{RDF}Description>", ]) for descr_ns, target_ns in (("RDF:", ""), ("", "em:"), ("RDF:", "em:")): # First we need to infuse the above strings with our namespaces and # platform values. ns = {"RDF": descr_ns, "em": target_ns} target_tag_x86_64 = target_tag.format(platform=x86_64, **ns) target_tag_x86 = target_tag.format(platform=x86, **ns) target_attr_x86_64 = target_attr.format(platform=x86_64, **ns) target_attr_x86 = target_attr.format(platform=x86, **ns) tag_x86_64 = rdf_tag.format(targets=target_tag_x86_64, **ns) tag_x86 = rdf_tag.format(targets=target_tag_x86, **ns) tag_merged = rdf_tag.format(targets=target_tag_x86_64 + target_tag_x86, **ns) tag_empty = rdf_tag.format(targets="", **ns) attr_x86_64 = rdf_attr.format(attr=target_attr_x86_64, targets="", **ns) attr_x86 = rdf_attr.format(attr=target_attr_x86, targets="", **ns) attr_merged = rdf_attr.format(attr="", targets=target_tag_x86_64 + target_tag_x86, **ns) # This table defines the test cases, columns "a" and "b" being the # contents of the install.rdf of the respective platform and # "result" the exepected merged content after unification. testcases = ( # _____a_____ _____b_____ ___result___# (tag_x86_64, tag_x86, tag_merged), (tag_x86_64, tag_empty, tag_empty), (tag_empty, tag_x86, tag_empty), (tag_empty, tag_empty, tag_empty), (attr_x86_64, attr_x86, attr_merged), (tag_x86_64, attr_x86, tag_merged), (attr_x86_64, tag_x86, attr_merged), (attr_x86_64, tag_empty, tag_empty), (tag_empty, attr_x86, tag_empty), ) # Now create the files from the above table and compare results = [] for emid, (rdf_a, rdf_b, result) in enumerate(testcases): filename = "ext/id{0}/install.rdf".format(emid) self.create_one("a", filename, rdf_a) self.create_one("b", filename, rdf_b) results.append((filename, result)) self.assertEqual( sorted([(f, c.open().read().decode("utf-8")) for f, c in finder.find("**/install.rdf")]), results, )
def test_unified_build_finder(self): finder = UnifiedBuildFinder(FileFinder(self.tmppath('a')), FileFinder(self.tmppath('b'))) # Test chrome.manifest unification self.create_both('chrome.manifest', 'a\nb\nc\n') self.create_one('a', 'chrome/chrome.manifest', 'a\nb\nc\n') self.create_one('b', 'chrome/chrome.manifest', 'b\nc\na\n') self.assertEqual( sorted([(f, c.open().read()) for f, c in finder.find('**/chrome.manifest')]), [('chrome.manifest', 'a\nb\nc\n'), ('chrome/chrome.manifest', 'a\nb\nc\n')]) # Test buildconfig.html unification self.create_one( 'a', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '</body>', '</html>', ])) self.create_one( 'b', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>bar</div>', '</body>', '</html>', ])) self.assertEqual( sorted([(f, c.open().read()) for f, c in finder.find('**/buildconfig.html')]), [('chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '<hr> </hr>', '<div>bar</div>', '</body>', '</html>', ]))]) # Test xpi file unification xpi = MockDest() with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'foo') jar.add('bar', 'bar') foo_xpi = xpi.read() self.create_both('foo.xpi', foo_xpi) with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'bar') self.create_one('a', 'bar.xpi', foo_xpi) self.create_one('b', 'bar.xpi', xpi.read()) errors.out = StringIO() with self.assertRaises(AccumulatedErrors), errors.accumulate(): self.assertEqual([(f, c.open().read()) for f, c in finder.find('*.xpi')], [('foo.xpi', foo_xpi)]) errors.out = sys.stderr # Test install.rdf unification x86_64 = 'Darwin_x86_64-gcc3' x86 = 'Darwin_x86-gcc3' target_tag = '<{em}targetPlatform>{platform}</{em}targetPlatform>' target_attr = '{em}targetPlatform="{platform}" ' rdf_tag = ''.join([ '<{RDF}Description {em}bar="bar" {em}qux="qux">', '<{em}foo>foo</{em}foo>', '{targets}', '<{em}baz>baz</{em}baz>', '</{RDF}Description>' ]) rdf_attr = ''.join([ '<{RDF}Description {em}bar="bar" {attr}{em}qux="qux">', '{targets}', '<{em}foo>foo</{em}foo><{em}baz>baz</{em}baz>', '</{RDF}Description>' ]) for descr_ns, target_ns in (('RDF:', ''), ('', 'em:'), ('RDF:', 'em:')): # First we need to infuse the above strings with our namespaces and # platform values. ns = {'RDF': descr_ns, 'em': target_ns} target_tag_x86_64 = target_tag.format(platform=x86_64, **ns) target_tag_x86 = target_tag.format(platform=x86, **ns) target_attr_x86_64 = target_attr.format(platform=x86_64, **ns) target_attr_x86 = target_attr.format(platform=x86, **ns) tag_x86_64 = rdf_tag.format(targets=target_tag_x86_64, **ns) tag_x86 = rdf_tag.format(targets=target_tag_x86, **ns) tag_merged = rdf_tag.format(targets=target_tag_x86_64 + target_tag_x86, **ns) tag_empty = rdf_tag.format(targets="", **ns) attr_x86_64 = rdf_attr.format(attr=target_attr_x86_64, targets="", **ns) attr_x86 = rdf_attr.format(attr=target_attr_x86, targets="", **ns) attr_merged = rdf_attr.format(attr="", targets=target_tag_x86_64 + target_tag_x86, **ns) # This table defines the test cases, columns "a" and "b" being the # contents of the install.rdf of the respective platform and # "result" the exepected merged content after unification. testcases = ( #_____a_____ _____b_____ ___result___# (tag_x86_64, tag_x86, tag_merged), (tag_x86_64, tag_empty, tag_empty), (tag_empty, tag_x86, tag_empty), (tag_empty, tag_empty, tag_empty), (attr_x86_64, attr_x86, attr_merged), (tag_x86_64, attr_x86, tag_merged), (attr_x86_64, tag_x86, attr_merged), (attr_x86_64, tag_empty, tag_empty), (tag_empty, attr_x86, tag_empty)) # Now create the files from the above table and compare results = [] for emid, (rdf_a, rdf_b, result) in enumerate(testcases): filename = 'ext/id{0}/install.rdf'.format(emid) self.create_one('a', filename, rdf_a) self.create_one('b', filename, rdf_b) results.append((filename, result)) self.assertEqual( sorted([(f, c.open().read()) for f, c in finder.find('**/install.rdf')]), results)
def test_unified_build_finder(self): self.create_both('chrome.manifest', 'a\nb\nc\n') self.create_one('a', 'chrome/chrome.manifest', 'a\nb\nc\n') self.create_one('b', 'chrome/chrome.manifest', 'b\nc\na\n') self.create_one( 'a', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '</body>', '</html>', ])) self.create_one( 'b', 'chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>bar</div>', '</body>', '</html>', ])) finder = UnifiedBuildFinder(FileFinder(self.tmppath('a')), FileFinder(self.tmppath('b'))) self.assertEqual( sorted([(f, c.open().read()) for f, c in finder.find('**/chrome.manifest')]), [('chrome.manifest', 'a\nb\nc\n'), ('chrome/chrome.manifest', 'a\nb\nc\n')]) self.assertEqual( sorted([(f, c.open().read()) for f, c in finder.find('**/buildconfig.html')]), [('chrome/browser/foo/buildconfig.html', '\n'.join([ '<html>', '<body>', '<h1>about:buildconfig</h1>', '<div>foo</div>', '<hr> </hr>', '<div>bar</div>', '</body>', '</html>', ]))]) xpi = MockDest() with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'foo') jar.add('bar', 'bar') foo_xpi = xpi.read() self.create_both('foo.xpi', foo_xpi) with JarWriter(fileobj=xpi, compress=True) as jar: jar.add('foo', 'bar') self.create_one('a', 'bar.xpi', foo_xpi) self.create_one('b', 'bar.xpi', xpi.read()) errors.out = StringIO() with self.assertRaises(AccumulatedErrors), errors.accumulate(): self.assertEqual([(f, c.open().read()) for f, c in finder.find('*.xpi')], [('foo.xpi', foo_xpi)]) errors.out = sys.stderr