def test_load_with_includes_with_commands_and_variables(self): # This one is the pinacle of fun. Check that isolate_dir is the expected # value. To achieve this, put the .isolate files into subdirectories. dir_1 = os.path.join(self.tempdir, '1') dir_3 = os.path.join(self.tempdir, '3') dir_3_2 = os.path.join(self.tempdir, '3', '2') os.mkdir(dir_1) os.mkdir(dir_3) os.mkdir(dir_3_2) isolate1 = { 'conditions': [ [ 'OS=="amiga" or OS=="win"', { 'variables': { 'command': [ 'foo', 'amiga_or_win', '<(PATH)', ], }, } ], [ 'OS=="linux"', { 'variables': { 'command': [ 'foo', 'linux', '<(PATH)', ], 'files': [ '<(PATH)/file_linux', ], }, } ], [ 'OS=="mac" or OS=="win"', { 'variables': { 'files': [ '<(PATH)/file_non_linux', ], }, } ], ], } isolate2 = { 'conditions': [ [ 'OS=="linux" or OS=="mac"', { 'variables': { 'command': [ 'foo', 'linux_or_mac', '<(PATH)', ], 'files': [ '<(PATH)/other/file', ], }, } ], ], } # Do not define command in isolate3, otherwise commands in the other # included .isolated will be ignored. isolate3 = { 'includes': [ '../1/isolate1.isolate', '2/isolate2.isolate', ], 'conditions': [ [ 'OS=="amiga"', { 'variables': { 'files': [ '<(PATH)/file_amiga', ], }, } ], [ 'OS=="mac"', { 'variables': { 'files': [ '<(PATH)/file_mac', ], }, } ], ], } # No need to write isolate3. with open(os.path.join(dir_1, 'isolate1.isolate'), 'wb') as f: isolate_format.pretty_print(isolate1, f) with open(os.path.join(dir_3_2, 'isolate2.isolate'), 'wb') as f: isolate_format.pretty_print(isolate2, f) # The 'isolate_dir' are important, they are what will be used when # defining the final isolate_dir to use to run the command in the .isolated # file. actual = isolate_format.load_isolate_as_config(dir_3, isolate3, None) expected = { (None, ): { 'isolate_dir': dir_1, }, ('amiga', ): { 'command': ['foo', 'amiga_or_win', '<(PATH)'], 'files': [ '<(PATH)/file_amiga', ], 'isolate_dir': dir_1, }, ('linux', ): { # Last included takes precedence. *command comes from isolate2*, so # it becomes the canonical root, so reference to file from isolate1 is # via '../../1'. 'command': ['foo', 'linux_or_mac', '<(PATH)'], 'files': [ '<(PATH)/file_linux', '<(PATH)/other/file', ], 'isolate_dir': dir_3_2, }, ('mac', ): { 'command': ['foo', 'linux_or_mac', '<(PATH)'], 'files': [ '<(PATH)/file_mac', '<(PATH)/file_non_linux', '<(PATH)/other/file', ], 'isolate_dir': dir_3_2, }, ('win', ): { # command comes from isolate1. 'command': ['foo', 'amiga_or_win', '<(PATH)'], 'files': [ '<(PATH)/file_non_linux', ], 'isolate_dir': dir_1, }, } self.assertEqual(expected, actual.flatten())
def test_load_with_includes(self): included_isolate = { 'variables': { 'files': [ 'file_common', ], }, 'conditions': [ [ 'OS=="linux"', { 'variables': { 'files': [ 'file_linux', ], 'read_only': 1, }, } ], [ 'OS=="mac" or OS=="win"', { 'variables': { 'files': [ 'file_non_linux', ], 'read_only': 0, }, } ], ], } with open(os.path.join(self.tempdir, 'included.isolate'), 'wb') as f: isolate_format.pretty_print(included_isolate, f) values = { 'includes': ['included.isolate'], 'variables': { 'files': [ 'file_less_common', ], }, 'conditions': [ [ 'OS=="mac"', { 'variables': { 'files': [ 'file_mac', ], 'read_only': 2, }, } ], ], } actual = isolate_format.load_isolate_as_config(self.tempdir, values, None) expected = { (None, ): { 'files': [ 'file_common', 'file_less_common', ], 'isolate_dir': self.tempdir, }, ('linux', ): { 'files': [ 'file_linux', ], 'isolate_dir': self.tempdir, 'read_only': 1, }, ('mac', ): { 'files': [ 'file_mac', 'file_non_linux', ], 'isolate_dir': self.tempdir, 'read_only': 2, }, ('win', ): { 'files': [ 'file_non_linux', ], 'isolate_dir': self.tempdir, 'read_only': 0, }, } self.assertEqual(expected, actual.flatten())
def test_load_with_includes_with_commands(self): # This one is messy. Check that isolate_dir is the expected value. To # achieve this, put the .isolate files into subdirectories. dir_1 = os.path.join(self.tempdir, '1') dir_3 = os.path.join(self.tempdir, '3') dir_3_2 = os.path.join(self.tempdir, '3', '2') os.mkdir(dir_1) os.mkdir(dir_3) os.mkdir(dir_3_2) isolate1 = { 'conditions': [ [ 'OS=="amiga" or OS=="win"', { 'variables': { 'command': [ 'foo', 'amiga_or_win', ], }, } ], [ 'OS=="linux"', { 'variables': { 'command': [ 'foo', 'linux', ], 'files': [ 'file_linux', ], }, } ], [ 'OS=="mac" or OS=="win"', { 'variables': { 'files': [ 'file_non_linux', ], }, } ], ], } isolate2 = { 'conditions': [ [ 'OS=="linux" or OS=="mac"', { 'variables': { 'command': [ 'foo', 'linux_or_mac', ], 'files': [ 'other/file', ], }, } ], ], } # Do not define command in isolate3, otherwise commands in the other # included .isolated will be ignored. isolate3 = { 'includes': [ '../1/isolate1.isolate', '2/isolate2.isolate', ], 'conditions': [ [ 'OS=="amiga"', { 'variables': { 'files': [ 'file_amiga', ], }, } ], ['OS=="mac"', { 'variables': { 'files': [ 'file_mac', ], }, }], ], } # No need to write isolate3. with open(os.path.join(dir_1, 'isolate1.isolate'), 'wb') as f: isolate_format.pretty_print(isolate1, f) with open(os.path.join(dir_3_2, 'isolate2.isolate'), 'wb') as f: isolate_format.pretty_print(isolate2, f) # The 'isolate_dir' are important, they are what will be used when # defining the final isolate_dir to use to run the command in the .isolated # file. actual = isolate_format.load_isolate_as_config(dir_3, isolate3, None) expected = { (None, ): { # TODO(maruel): See TODO in ConfigSettings.flatten(). # TODO(maruel): If kept, in this case dir_3 should be selected. 'isolate_dir': dir_1, }, ('amiga', ): { 'command': ['foo', 'amiga_or_win'], 'files': [ # Note that the file was rebased from isolate1. This is important, # isolate1 represent the canonical root path because it is the one # that defined the command. '../3/file_amiga', ], 'isolate_dir': dir_1, }, ('linux', ): { # Last included takes precedence. *command comes from isolate2*, so # it becomes the canonical root, so reference to file from isolate1 is # via '../../1'. 'command': ['foo', 'linux_or_mac'], 'files': [ '../../1/file_linux', 'other/file', ], 'isolate_dir': dir_3_2, }, ('mac', ): { 'command': ['foo', 'linux_or_mac'], 'files': [ '../../1/file_non_linux', '../file_mac', 'other/file', ], 'isolate_dir': dir_3_2, }, ('win', ): { # command comes from isolate1. 'command': ['foo', 'amiga_or_win'], 'files': [ # While this may be surprising, this is because the command was # defined in isolate1, not isolate3. 'file_non_linux', ], 'isolate_dir': dir_1, }, } self.assertEqual(expected, actual.flatten())
def _test_pretty_print_impl(self, value, expected): actual = cStringIO.StringIO() isolate_format.pretty_print(value, actual) self.assertEqual(expected.splitlines(), actual.getvalue().splitlines())
def test_load_with_includes_with_commands_and_variables(self): # This one is the pinacle of fun. Check that isolate_dir is the expected # value. To achieve this, put the .isolate files into subdirectories. dir_1 = os.path.join(self.tempdir, '1') dir_3 = os.path.join(self.tempdir, '3') dir_3_2 = os.path.join(self.tempdir, '3', '2') os.mkdir(dir_1) os.mkdir(dir_3) os.mkdir(dir_3_2) isolate1 = { 'conditions': [ ['OS=="amiga" or OS=="win"', { 'variables': { 'command': [ 'foo', 'amiga_or_win', '<(PATH)', ], }, }], ['OS=="linux"', { 'variables': { 'command': [ 'foo', 'linux', '<(PATH)', ], 'isolate_dependency_tracked': [ '<(PATH)/file_linux', ], }, }], ['OS=="mac" or OS=="win"', { 'variables': { 'isolate_dependency_tracked': [ '<(PATH)/file_non_linux', ], }, }], ], } isolate2 = { 'conditions': [ ['OS=="linux" or OS=="mac"', { 'variables': { 'command': [ 'foo', 'linux_or_mac', '<(PATH)', ], 'isolate_dependency_tracked': [ '<(PATH)/other/file', ], }, }], ], } isolate3 = { 'includes': [ '../1/isolate1.isolate', '2/isolate2.isolate', ], 'conditions': [ ['OS=="amiga"', { 'variables': { 'isolate_dependency_tracked': [ '<(PATH)/file_amiga', ], }, }], ['OS=="mac"', { 'variables': { 'command': [ 'foo', 'mac', '<(PATH)', ], 'isolate_dependency_tracked': [ '<(PATH)/file_mac', ], }, }], ], } # No need to write isolate3. with open(os.path.join(dir_1, 'isolate1.isolate'), 'wb') as f: isolate_format.pretty_print(isolate1, f) with open(os.path.join(dir_3_2, 'isolate2.isolate'), 'wb') as f: isolate_format.pretty_print(isolate2, f) # The 'isolate_dir' are important, they are what will be used when # definining the final isolate_dir to use to run the command in the # .isolated file. actual = isolate_format.load_isolate_as_config(dir_3, isolate3, None) expected = { (None,): { 'isolate_dir': dir_1, }, ('amiga',): { 'command': ['foo', 'amiga_or_win', '<(PATH)'], 'isolate_dependency_tracked': [ '<(PATH)/file_amiga', ], 'isolate_dir': dir_1, }, ('linux',): { # Last included takes precedence. *command comes from isolate2*, so # it becomes the canonical root, so reference to file from isolate1 is # via '../../1'. 'command': ['foo', 'linux_or_mac', '<(PATH)'], 'isolate_dependency_tracked': [ '<(PATH)/file_linux', '<(PATH)/other/file', ], 'isolate_dir': dir_3_2, }, ('mac',): { 'command': ['foo', 'mac', '<(PATH)'], 'isolate_dependency_tracked': [ '<(PATH)/file_mac', '<(PATH)/file_non_linux', '<(PATH)/other/file', ], 'isolate_dir': dir_3, }, ('win',): { # command comes from isolate1. 'command': ['foo', 'amiga_or_win', '<(PATH)'], 'isolate_dependency_tracked': [ '<(PATH)/file_non_linux', ], 'isolate_dir': dir_1, }, } self.assertEqual(expected, actual.flatten())
def test_load_with_includes_with_commands(self): # This one is messy. Check that isolate_dir is the expected value. To # achieve this, put the .isolate files into subdirectories. dir_1 = os.path.join(self.tempdir, '1') dir_3 = os.path.join(self.tempdir, '3') dir_3_2 = os.path.join(self.tempdir, '3', '2') os.mkdir(dir_1) os.mkdir(dir_3) os.mkdir(dir_3_2) isolate1 = { 'conditions': [ ['OS=="amiga" or OS=="win"', { 'variables': { 'command': [ 'foo', 'amiga_or_win', ], }, }], ['OS=="linux"', { 'variables': { 'command': [ 'foo', 'linux', ], 'isolate_dependency_tracked': [ 'file_linux', ], }, }], ['OS=="mac" or OS=="win"', { 'variables': { 'isolate_dependency_tracked': [ 'file_non_linux', ], }, }], ], } isolate2 = { 'conditions': [ ['OS=="linux" or OS=="mac"', { 'variables': { 'command': [ 'foo', 'linux_or_mac', ], 'isolate_dependency_tracked': [ 'other/file', ], }, }], ], } isolate3 = { 'includes': [ '../1/isolate1.isolate', '2/isolate2.isolate', ], 'conditions': [ ['OS=="amiga"', { 'variables': { 'isolate_dependency_tracked': [ 'file_amiga', ], }, }], ['OS=="mac"', { 'variables': { 'command': [ 'foo', 'mac', ], 'isolate_dependency_tracked': [ 'file_mac', ], }, }], ], } # No need to write isolate3. with open(os.path.join(dir_1, 'isolate1.isolate'), 'wb') as f: isolate_format.pretty_print(isolate1, f) with open(os.path.join(dir_3_2, 'isolate2.isolate'), 'wb') as f: isolate_format.pretty_print(isolate2, f) # The 'isolate_dir' are important, they are what will be used when # definining the final isolate_dir to use to run the command in the # .isolated file. actual = isolate_format.load_isolate_as_config(dir_3, isolate3, None) expected = { (None,): { # TODO(maruel): See TODO in ConfigSettings.flatten(). # TODO(maruel): If kept, in this case dir_3 should be selected. 'isolate_dir': dir_1, }, ('amiga',): { 'command': ['foo', 'amiga_or_win'], 'isolate_dependency_tracked': [ # Note that the file was rebased from isolate1. This is important, # isolate1 represent the canonical root path because it is the one # that defined the command. '../3/file_amiga', ], 'isolate_dir': dir_1, }, ('linux',): { # Last included takes precedence. *command comes from isolate2*, so # it becomes the canonical root, so reference to file from isolate1 is # via '../../1'. 'command': ['foo', 'linux_or_mac'], 'isolate_dependency_tracked': [ '../../1/file_linux', 'other/file', ], 'isolate_dir': dir_3_2, }, ('mac',): { # command in isolate3 takes precedence over the ones included. 'command': ['foo', 'mac'], 'isolate_dependency_tracked': [ '../1/file_non_linux', '2/other/file', 'file_mac', ], 'isolate_dir': dir_3, }, ('win',): { # command comes from isolate1. 'command': ['foo', 'amiga_or_win'], 'isolate_dependency_tracked': [ # While this may be surprising, this is because the command was # defined in isolate1, not isolate3. 'file_non_linux', ], 'isolate_dir': dir_1, }, } self.assertEqual(expected, actual.flatten())
def test_load_with_includes(self): included_isolate = { 'variables': { 'isolate_dependency_tracked': [ 'file_common', ], }, 'conditions': [ ['OS=="linux"', { 'variables': { 'isolate_dependency_tracked': [ 'file_linux', ], 'read_only': 1, }, }], ['OS=="mac" or OS=="win"', { 'variables': { 'isolate_dependency_tracked': [ 'file_non_linux', ], 'read_only': 0, }, }], ], } with open(os.path.join(self.tempdir, 'included.isolate'), 'wb') as f: isolate_format.pretty_print(included_isolate, f) values = { 'includes': ['included.isolate'], 'variables': { 'isolate_dependency_tracked': [ 'file_less_common', ], }, 'conditions': [ ['OS=="mac"', { 'variables': { 'isolate_dependency_tracked': [ 'file_mac', ], 'read_only': 2, }, }], ], } actual = isolate_format.load_isolate_as_config(self.tempdir, values, None) expected = { (None,): { 'isolate_dependency_tracked': [ 'file_common', 'file_less_common', ], 'isolate_dir': self.tempdir, }, ('linux',): { 'isolate_dependency_tracked': [ 'file_linux', ], 'isolate_dir': self.tempdir, 'read_only': 1, }, ('mac',): { 'isolate_dependency_tracked': [ 'file_mac', 'file_non_linux', ], 'isolate_dir': self.tempdir, 'read_only': 2, }, ('win',): { 'isolate_dependency_tracked': [ 'file_non_linux', ], 'isolate_dir': self.tempdir, 'read_only': 0, }, } self.assertEqual(expected, actual.flatten())