def load_isolates(items): """Parses each .isolate file and returns the merged results. It only loads what load_isolate_as_config() can process. Return values: files: dict(filename, set(OS where this filename is a dependency)) dirs: dict(dirame, set(OS where this dirname is a dependency)) oses: set(all the OSes referenced) """ # pylint: disable=W0212 configs = isolate_format.Configs(None, ()) for item in items: item = os.path.abspath(item) logging.debug('loading %s' % item) if item == '-': content = sys.stdin.read() else: with open(item, 'r') as f: content = f.read() new_config = isolate_format.load_isolate_as_config( os.path.dirname(item), isolate_format.eval_content(content), isolate_format.extract_comment(content)) logging.debug('has configs: ' + ','.join(map(repr, new_config._by_config))) configs = configs.union(new_config) logging.debug('Total configs: ' + ','.join(map(repr, configs._by_config))) return configs
def test_merge_two_empty(self): actual = isolate_format.Configs(None, ()).union( isolate_format.load_isolate_as_config(FAKE_DIR, {}, None)).union( isolate_format.load_isolate_as_config(FAKE_DIR, {}, None)) expected = { (): { 'isolate_dir': FAKE_DIR, }, } self.assertEqual(expected, actual.flatten())
def test_merge_two_empty(self): # Flat stay flat. Pylint is confused about union() return type. # pylint: disable=E1103 actual = isolate_format.Configs(None, ()).union( isolate_format.load_isolate_as_config(FAKE_DIR, {}, None)).union( isolate_format.load_isolate_as_config(FAKE_DIR, {}, None)) expected = { (): { 'isolate_dir': FAKE_DIR, }, } self.assertEqual(expected, actual.flatten())
def test_load_two_conditions(self): linux = { 'conditions': [ [ 'OS=="linux"', { 'variables': { 'files': [ 'file_linux', 'file_common', ], }, } ], ], } mac = { 'conditions': [ [ 'OS=="mac"', { 'variables': { 'files': [ 'file_mac', 'file_common', ], }, } ], ], } expected = { (None, ): { 'isolate_dir': FAKE_DIR, }, ('linux', ): { 'files': ['file_common', 'file_linux'], 'isolate_dir': FAKE_DIR, }, ('mac', ): { 'files': ['file_common', 'file_mac'], 'isolate_dir': FAKE_DIR, }, } # Pylint is confused about union() return type. # pylint: disable=E1103 configs = isolate_format.Configs(None, ()).union( isolate_format.load_isolate_as_config( FAKE_DIR, linux, None)).union( isolate_format.load_isolate_as_config(FAKE_DIR, mac, None)).flatten() self.assertEqual(expected, configs)
def test_load_three_conditions(self): linux = { 'conditions': [ [ 'OS=="linux" and chromeos==1', { 'variables': { 'files': [ 'file_linux', 'file_common', ], }, } ], ], } mac = { 'conditions': [ [ 'OS=="mac" and chromeos==0', { 'variables': { 'files': [ 'file_mac', 'file_common', ], }, } ], ], } win = { 'conditions': [ [ 'OS=="win" and chromeos==0', { 'variables': { 'files': [ 'file_win', 'file_common', ], }, } ], ], } expected = { (None, None): { 'isolate_dir': FAKE_DIR, }, ('linux', 1): { 'files': ['file_common', 'file_linux'], 'isolate_dir': FAKE_DIR, }, ('mac', 0): { 'files': ['file_common', 'file_mac'], 'isolate_dir': FAKE_DIR, }, ('win', 0): { 'files': ['file_common', 'file_win'], 'isolate_dir': FAKE_DIR, }, } configs = isolate_format.Configs(None, ()).union( isolate_format.load_isolate_as_config( FAKE_DIR, linux, None)).union( isolate_format.load_isolate_as_config( FAKE_DIR, mac, None)).union( isolate_format.load_isolate_as_config( FAKE_DIR, win, None)) self.assertEqual(expected, configs.flatten())