Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / tools / swarming_client / tests / isolate_format_test.py
index 516528e..a053a3e 100755 (executable)
@@ -13,19 +13,19 @@ import unittest
 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 sys.path.insert(0, ROOT_DIR)
 
-FAKE_DIR = u'/path/to/non_existing'
-
 import isolate_format
-import run_isolated
-from utils import tools
-# Create shortcuts.
-from isolate_format import KEY_TOUCHED, KEY_TRACKED, KEY_UNTRACKED
+from utils import file_path
 
 
 # Access to a protected member XXX of a client class
 # pylint: disable=W0212
 
 
+FAKE_DIR = (
+    u'z:\\path\\to\\non_existing'
+    if sys.platform == 'win32' else u'/path/to/non_existing')
+
+
 class IsolateFormatTest(unittest.TestCase):
   def test_unknown_key(self):
     try:
@@ -41,25 +41,6 @@ class IsolateFormatTest(unittest.TestCase):
     except AssertionError:
       pass
 
-  def test_union(self):
-    value1 = {
-      'a': set(['A']),
-      'b': ['B', 'C'],
-      'c': 'C',
-    }
-    value2 = {
-      'a': set(['B', 'C']),
-      'b': [],
-      'd': set(),
-    }
-    expected = {
-      'a': set(['A', 'B', 'C']),
-      'b': ['B', 'C'],
-      'c': 'C',
-      'd': set(),
-    }
-    self.assertEqual(expected, isolate_format.union(value1, value2))
-
   def test_eval_content(self):
     try:
       # Intrinsics are not available.
@@ -69,8 +50,13 @@ class IsolateFormatTest(unittest.TestCase):
       pass
 
   def test_load_isolate_as_config_empty(self):
+    expected = {
+      (): {
+        'isolate_dir': FAKE_DIR,
+      },
+    }
     self.assertEqual(
-        {(): {}},
+        expected,
         isolate_format.load_isolate_as_config(FAKE_DIR, {}, None).flatten())
 
   def test_load_isolate_as_config(self):
@@ -78,68 +64,60 @@ class IsolateFormatTest(unittest.TestCase):
       'conditions': [
         ['OS=="amiga" or OS=="atari" or OS=="coleco" or OS=="dendy"', {
           'variables': {
-            KEY_TRACKED: ['a'],
-            KEY_UNTRACKED: ['b'],
-            KEY_TOUCHED: ['touched'],
+            'files': ['a', 'b', 'touched'],
           },
         }],
         ['OS=="atari"', {
           'variables': {
-            KEY_TRACKED: ['c', 'x'],
-            KEY_UNTRACKED: ['d'],
-            KEY_TOUCHED: ['touched_a'],
+            'files': ['c', 'd', 'touched_a', 'x'],
             'command': ['echo', 'Hello World'],
             'read_only': 2,
           },
         }],
         ['OS=="amiga" or OS=="coleco" or OS=="dendy"', {
           'variables': {
-            KEY_TRACKED: ['e', 'x'],
-            KEY_UNTRACKED: ['f'],
-            KEY_TOUCHED: ['touched_e'],
+            'files': ['e', 'f', 'touched_e', 'x'],
             'command': ['echo', 'You should get an Atari'],
           },
         }],
         ['OS=="amiga"', {
           'variables': {
-            KEY_TRACKED: ['g'],
+            'files': ['g'],
             'read_only': 1,
           },
         }],
         ['OS=="amiga" or OS=="atari" or OS=="dendy"', {
           'variables': {
-            KEY_UNTRACKED: ['h'],
+            'files': ['h'],
           },
         }],
       ],
     }
     expected = {
-      (None,): {},
+      (None,): {
+        'isolate_dir': FAKE_DIR,
+      },
       ('amiga',): {
+        'files': ['a', 'b', 'e', 'f', 'g', 'h', 'touched', 'touched_e', 'x'],
         'command': ['echo', 'You should get an Atari'],
-        KEY_TOUCHED: ['touched', 'touched_e'],
-        KEY_TRACKED: ['a', 'e', 'g', 'x'],
-        KEY_UNTRACKED: ['b', 'f', 'h'],
+        'isolate_dir': FAKE_DIR,
         'read_only': 1,
       },
       ('atari',): {
+        'files': ['a', 'b', 'c', 'd', 'h', 'touched', 'touched_a', 'x'],
         'command': ['echo', 'Hello World'],
-        KEY_TOUCHED: ['touched', 'touched_a'],
-        KEY_TRACKED: ['a', 'c', 'x'],
-        KEY_UNTRACKED: ['b', 'd', 'h'],
+        'isolate_dir': FAKE_DIR,
         'read_only': 2,
       },
       ('coleco',): {
+        'files': ['a', 'b', 'e', 'f', 'touched', 'touched_e', 'x'],
         'command': ['echo', 'You should get an Atari'],
-        KEY_TOUCHED: ['touched', 'touched_e'],
-        KEY_TRACKED: ['a', 'e', 'x'],
-        KEY_UNTRACKED: ['b', 'f'],
+        'isolate_dir': FAKE_DIR,
       },
       ('dendy',): {
+        'files': ['a', 'b', 'e', 'f', 'h', 'touched', 'touched_e', 'x'],
         'command': ['echo', 'You should get an Atari'],
-        KEY_TOUCHED: ['touched', 'touched_e'],
-        KEY_TRACKED: ['a', 'e', 'x'],
-        KEY_UNTRACKED: ['b', 'f', 'h'],
+        'isolate_dir': FAKE_DIR,
       },
     }
     self.assertEqual(
@@ -169,9 +147,7 @@ class IsolateFormatTest(unittest.TestCase):
     value = {
       'variables': {
         'command': ['echo', 'You should get an Atari'],
-        KEY_TRACKED: ['a'],
-        KEY_UNTRACKED: ['b'],
-        KEY_TOUCHED: ['touched'],
+        'files': ['a', 'b', 'touched'],
         'read_only': 1,
       },
     }
@@ -179,9 +155,8 @@ class IsolateFormatTest(unittest.TestCase):
     expected = {
       (): {
         'command': ['echo', 'You should get an Atari'],
-        KEY_TRACKED: ['a'],
-        KEY_UNTRACKED: ['b'],
-        KEY_TOUCHED: ['touched'],
+        'files': ['a', 'b', 'touched'],
+        'isolate_dir': FAKE_DIR,
         'read_only': 1,
       },
     }
@@ -189,308 +164,25 @@ class IsolateFormatTest(unittest.TestCase):
         expected, isolate_format.load_isolate_as_config(
             FAKE_DIR, value, None).flatten())
 
-  def test_invert_map(self):
-    value = {
-      ('amiga',): {
-        'command': ['echo', 'You should get an Atari'],
-        KEY_TOUCHED: ['touched', 'touched_e'],
-        KEY_TRACKED: ['a', 'e', 'g', 'x'],
-        KEY_UNTRACKED: ['b', 'f', 'h'],
-        'read_only': 0,
-      },
-      ('atari',): {
-        'command': ['echo', 'Hello World'],
-        KEY_TOUCHED: ['touched', 'touched_a'],
-        KEY_TRACKED: ['a', 'c', 'x'],
-        KEY_UNTRACKED: ['b', 'd', 'h'],
-        'read_only': 1,
-      },
-      ('coleco',): {
-        'command': ['echo', 'You should get an Atari'],
-        KEY_TOUCHED: ['touched', 'touched_e'],
-        KEY_TRACKED: ['a', 'e', 'x'],
-        KEY_UNTRACKED: ['b', 'f'],
-      },
-      ('dendy',): {
-        'command': ['echo', 'You should get an Atari'],
-        KEY_TOUCHED: ['touched', 'touched_e'],
-        KEY_TRACKED: ['a', 'e', 'x'],
-        KEY_UNTRACKED: ['b', 'f', 'h'],
-      },
-    }
-    amiga, atari, coleco, dendy = (
-        set([(os,)]) for os in ('amiga', 'atari', 'coleco', 'dendy'))
-    expected_values = {
-      'command': {
-        ('echo', 'Hello World'): atari,
-        ('echo', 'You should get an Atari'): amiga | coleco | dendy,
-      },
-      KEY_TRACKED: {
-        'a': amiga | atari | coleco | dendy,
-        'c': atari,
-        'e': amiga | coleco | dendy,
-        'g': amiga,
-        'x': amiga | atari | coleco | dendy,
-      },
-      KEY_UNTRACKED: {
-        'b': amiga | atari | coleco | dendy,
-        'd': atari,
-        'f': amiga | coleco | dendy,
-        'h': amiga | atari | dendy,
-      },
-      KEY_TOUCHED: {
-        'touched': amiga | atari | coleco | dendy,
-        'touched_a': atari,
-        'touched_e': amiga | coleco | dendy,
-      },
-      'read_only': {
-        0: amiga,
-        1: atari,
-      },
-    }
-    actual_values = isolate_format.invert_map(value)
-    self.assertEqual(expected_values, actual_values)
-
-  def test_reduce_inputs(self):
-    amiga, atari, coleco, dendy = (
-        set([(os,)]) for os in ('amiga', 'atari', 'coleco', 'dendy'))
-    values = {
-      'command': {
-        ('echo', 'Hello World'): atari,
-        ('echo', 'You should get an Atari'): amiga | coleco | dendy,
-      },
-      KEY_TRACKED: {
-        'a': amiga | atari | coleco | dendy,
-        'c': atari,
-        'e': amiga | coleco | dendy,
-        'g': amiga,
-        'x': amiga | atari | coleco | dendy,
-      },
-      KEY_UNTRACKED: {
-        'b': amiga | atari | coleco | dendy,
-        'd': atari,
-        'f': amiga | coleco | dendy,
-        'h': amiga | atari | dendy,
-      },
-      KEY_TOUCHED: {
-        'touched': amiga | atari | coleco | dendy,
-        'touched_a': atari,
-        'touched_e': amiga | coleco | dendy,
-      },
-      'read_only': {
-        0: amiga,
-        1: atari,
-      },
-    }
-    expected_values = {
-      'command': {
-        ('echo', 'Hello World'): atari,
-        ('echo', 'You should get an Atari'): amiga | coleco | dendy,
-      },
-      KEY_TRACKED: {
-        'a': amiga | atari | coleco | dendy,
-        'c': atari,
-        'e': amiga | coleco | dendy,
-        'g': amiga,
-        'x': amiga | atari | coleco | dendy,
-      },
-      KEY_UNTRACKED: {
-        'b': amiga | atari | coleco | dendy,
-        'd': atari,
-        'f': amiga | coleco | dendy,
-        'h': amiga | atari | dendy,
-      },
-      KEY_TOUCHED: {
-        'touched': amiga | atari | coleco | dendy,
-        'touched_a': atari,
-        'touched_e': amiga | coleco | dendy,
-      },
-      'read_only': {
-        0: amiga,
-        1: atari,
-      },
-    }
-    actual_values = isolate_format.reduce_inputs(values)
-    self.assertEqual(expected_values, actual_values)
-
-  def test_reduce_inputs_merge_subfolders_and_files(self):
-    linux, mac, win = (set([(os,)]) for os in ('linux', 'mac', 'win'))
-    values = {
-      KEY_TRACKED: {
-        'folder/tracked_file': win,
-        'folder_helper/tracked_file': win,
-      },
-      KEY_UNTRACKED: {
-        'folder/': linux | mac | win,
-        'folder/subfolder/': win,
-        'folder/untracked_file': linux | mac | win,
-        'folder_helper/': linux,
-      },
-      KEY_TOUCHED: {
-        'folder/touched_file': win,
-        'folder/helper_folder/deep_file': win,
-        'folder_helper/touched_file1': mac | win,
-        'folder_helper/touched_file2': linux,
-      },
-    }
-    expected_values = {
-      'command': {},
-      KEY_TRACKED: {
-        'folder_helper/tracked_file': win,
-      },
-      KEY_UNTRACKED: {
-        'folder/': linux | mac | win,
-        'folder_helper/': linux,
-      },
-      KEY_TOUCHED: {
-        'folder_helper/touched_file1': mac | win,
-      },
-      'read_only': {},
-    }
-    actual_values = isolate_format.reduce_inputs(values)
-    self.assertEqual(expected_values, actual_values)
-
-  def test_reduce_inputs_take_strongest_dependency(self):
-    amiga, atari, coleco, dendy = (
-        set([(os,)]) for os in ('amiga', 'atari', 'coleco', 'dendy'))
-    values = {
-      'command': {
-        ('echo', 'Hello World'): atari,
-        ('echo', 'You should get an Atari'): amiga | coleco | dendy,
-      },
-      KEY_TRACKED: {
-        'a': amiga | atari | coleco | dendy,
-        'b': amiga | atari | coleco,
-      },
-      KEY_UNTRACKED: {
-        'c': amiga | atari | coleco | dendy,
-        'd': amiga | coleco | dendy,
-      },
-      KEY_TOUCHED: {
-        'a': amiga | atari | coleco | dendy,
-        'b': atari | coleco | dendy,
-        'c': amiga | atari | coleco | dendy,
-        'd': atari | coleco | dendy,
-      },
-    }
-    expected_values = {
-      'command': {
-        ('echo', 'Hello World'): atari,
-        ('echo', 'You should get an Atari'): amiga | coleco | dendy,
-      },
-      KEY_TRACKED: {
-        'a': amiga | atari | coleco | dendy,
-        'b': amiga | atari | coleco,
-      },
-      KEY_UNTRACKED: {
-        'c': amiga | atari | coleco | dendy,
-        'd': amiga | coleco | dendy,
-      },
-      KEY_TOUCHED: {
-        'b': dendy,
-        'd': atari,
-      },
-      'read_only': {},
-    }
-    actual_values = isolate_format.reduce_inputs(values)
-    self.assertEqual(expected_values, actual_values)
-
-  def test_convert_map_to_isolate_dict(self):
-    amiga = ('amiga',)
-    atari = ('atari',)
-    coleco = ('coleco',)
-    dendy = ('dendy',)
-    values = {
-      'command': {
-        ('echo', 'Hello World'): (atari,),
-        ('echo', 'You should get an Atari'): (amiga, coleco, dendy),
-      },
-      KEY_TRACKED: {
-        'a': (amiga, atari, coleco, dendy),
-        'c': (atari,),
-        'e': (amiga, coleco, dendy),
-        'g': (amiga,),
-        'x': (amiga, atari, coleco, dendy),
-      },
-      KEY_UNTRACKED: {
-        'b': (amiga, atari, coleco, dendy),
-        'd': (atari,),
-        'f': (amiga, coleco, dendy),
-        'h': (amiga, atari, dendy),
-      },
-      KEY_TOUCHED: {
-        'touched': (amiga, atari, coleco, dendy),
-        'touched_a': (atari,),
-        'touched_e': (amiga, coleco, dendy),
-      },
-      'read_only': {
-        0: (amiga,),
-        1: (atari,),
-      },
-    }
-    expected_conditions = [
-      ['OS=="amiga"', {
-        'variables': {
-          KEY_TRACKED: ['g'],
-          'read_only': 0,
-        },
-      }],
-      ['OS=="amiga" or OS=="atari" or OS=="coleco" or OS=="dendy"', {
-        'variables': {
-          KEY_TRACKED: ['a', 'x'],
-          KEY_UNTRACKED: ['b'],
-          KEY_TOUCHED: ['touched'],
-        },
-      }],
-      ['OS=="amiga" or OS=="atari" or OS=="dendy"', {
-        'variables': {
-          KEY_UNTRACKED: ['h'],
-        },
-      }],
-      ['OS=="amiga" or OS=="coleco" or OS=="dendy"', {
-        'variables': {
-          'command': ['echo', 'You should get an Atari'],
-          KEY_TRACKED: ['e'],
-          KEY_UNTRACKED: ['f'],
-          KEY_TOUCHED: ['touched_e'],
-        },
-      }],
-      ['OS=="atari"', {
-        'variables': {
-          'command': ['echo', 'Hello World'],
-          KEY_TRACKED: ['c'],
-          KEY_UNTRACKED: ['d'],
-          KEY_TOUCHED: ['touched_a'],
-          'read_only': 1,
-        },
-      }],
-    ]
-    actual = isolate_format.convert_map_to_isolate_dict(values, ('OS',))
-    self.assertEqual(expected_conditions, sorted(actual.pop('conditions')))
-    self.assertFalse(actual)
-
   def test_merge_two_empty(self):
     # Flat stay flat. Pylint is confused about union() return type.
     # pylint: disable=E1103
-    actual = isolate_format.union(
-        isolate_format.union(
-          isolate_format.Configs(None, ()),
-          isolate_format.load_isolate_as_config(FAKE_DIR, {}, None)),
-        isolate_format.load_isolate_as_config(FAKE_DIR, {}, None))
-    self.assertEqual({(): {}}, actual.flatten())
-
-  def test_merge_empty(self):
-    actual = isolate_format.convert_map_to_isolate_dict(
-        isolate_format.reduce_inputs(isolate_format.invert_map({})),
-        ('dummy1', 'dummy2'))
-    self.assertEqual({'conditions': []}, actual)
+    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': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_linux',
               'file_common',
             ],
@@ -502,7 +194,7 @@ class IsolateFormatTest(unittest.TestCase):
       'conditions': [
         ['OS=="mac"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_mac',
               'file_common',
             ],
@@ -511,21 +203,24 @@ class IsolateFormatTest(unittest.TestCase):
       ],
     }
     expected = {
-      (None,): {},
+      (None,): {
+        'isolate_dir': FAKE_DIR,
+      },
       ('linux',): {
-        'isolate_dependency_tracked': ['file_common', 'file_linux'],
+        'files': ['file_common', 'file_linux'],
+        'isolate_dir': FAKE_DIR,
       },
       ('mac',): {
-        'isolate_dependency_tracked': ['file_common', 'file_mac'],
+        'files': ['file_common', 'file_mac'],
+        'isolate_dir': FAKE_DIR,
       },
     }
     # Pylint is confused about union() return type.
     # pylint: disable=E1103
-    configs = isolate_format.union(
-        isolate_format.union(
-          isolate_format.Configs(None, ()),
-          isolate_format.load_isolate_as_config(FAKE_DIR, linux, None)),
-        isolate_format.load_isolate_as_config(FAKE_DIR, mac, None)).flatten()
+    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):
@@ -533,7 +228,7 @@ class IsolateFormatTest(unittest.TestCase):
       'conditions': [
         ['OS=="linux" and chromeos==1', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_linux',
               'file_common',
             ],
@@ -545,7 +240,7 @@ class IsolateFormatTest(unittest.TestCase):
       'conditions': [
         ['OS=="mac" and chromeos==0', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_mac',
               'file_common',
             ],
@@ -557,7 +252,7 @@ class IsolateFormatTest(unittest.TestCase):
       'conditions': [
         ['OS=="win" and chromeos==0', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_win',
               'file_common',
             ],
@@ -566,26 +261,28 @@ class IsolateFormatTest(unittest.TestCase):
       ],
     }
     expected = {
-      (None, None): {},
+      (None, None): {
+        'isolate_dir': FAKE_DIR,
+      },
       ('linux', 1): {
-        'isolate_dependency_tracked': ['file_common', 'file_linux'],
+        'files': ['file_common', 'file_linux'],
+        'isolate_dir': FAKE_DIR,
       },
       ('mac', 0): {
-        'isolate_dependency_tracked': ['file_common', 'file_mac'],
+        'files': ['file_common', 'file_mac'],
+        'isolate_dir': FAKE_DIR,
       },
       ('win', 0): {
-        'isolate_dependency_tracked': ['file_common', 'file_win'],
+        'files': ['file_common', 'file_win'],
+        'isolate_dir': FAKE_DIR,
       },
     }
     # Pylint is confused about union() return type.
     # pylint: disable=E1103
-    configs = isolate_format.union(
-        isolate_format.union(
-          isolate_format.union(
-            isolate_format.Configs(None, ()),
-            isolate_format.load_isolate_as_config(FAKE_DIR, linux, None)),
-          isolate_format.load_isolate_as_config(FAKE_DIR, mac, None)),
-        isolate_format.load_isolate_as_config(FAKE_DIR, win, None))
+    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())
 
   def test_safe_index(self):
@@ -621,11 +318,22 @@ class IsolateFormatTest(unittest.TestCase):
     self.assertEqual(('CHROMEOS', 'OS'), configs.config_variables)
     flatten = dict((k, v.flatten()) for k, v in configs._by_config.iteritems())
     expected = {
-      (None, None): {},
-      (None, 'abc'): {'command': ['bar']},
-      ('1', None): {'command': ['foo']},
+      (None, None): {
+        'isolate_dir': FAKE_DIR,
+      },
+      (None, 'abc'): {
+        'command': ['bar'],
+        'isolate_dir': FAKE_DIR,
+      },
+      ('1', None): {
+        'command': ['foo'],
+        'isolate_dir': FAKE_DIR,
+      },
       # TODO(maruel): It is a conflict.
-      ('1', 'abc'): {'command': ['bar']},
+      ('1', 'abc'): {
+        'command': ['bar'],
+        'isolate_dir': FAKE_DIR,
+      },
     }
     self.assertEqual(expected, flatten)
 
@@ -654,226 +362,50 @@ class IsolateFormatTest(unittest.TestCase):
     self.assertEqual(('CHROMEOS', 'OS'), configs.config_variables)
     flatten = dict((k, v.flatten()) for k, v in configs._by_config.iteritems())
     expected = {
-      (None, None): {},
-      (None, 'abc'): {'command': ['bar']},
-      ('1', None): {'command': ['foo']},
-    }
-    self.assertEqual(expected, flatten)
-
-  def test_make_isolate_multi_variables(self):
-    config = isolate_format.Configs(None, ('CHROMEOS', 'OS'))
-    config._by_config[(('0', 'linux'))] = isolate_format.ConfigSettings(
-        {'command': ['bar']})
-    config._by_config[(('1', 'linux'))] = isolate_format.ConfigSettings(
-        {'command': ['foo']})
-    expected = {
-      'conditions': [
-        ['CHROMEOS=="0" and OS=="linux"', {
-          'variables': {
-            'command': ['bar'],
-          },
-        }],
-        ['CHROMEOS=="1" and OS=="linux"', {
-          'variables': {
-            'command': ['foo'],
-          },
-        }],
-      ],
-    }
-    self.assertEqual(expected, config.make_isolate_file())
-
-  def test_make_isolate_multi_variables_missing(self):
-    config = isolate_format.Configs(None, ('CHROMEOS', 'OS'))
-    config._by_config[((None, 'abc'))] = isolate_format.ConfigSettings(
-        {'command': ['bar']})
-    config._by_config[(('1', None))] = isolate_format.ConfigSettings(
-        {'command': ['foo']})
-    expected = {
-      'conditions': [
-        ['CHROMEOS=="1"', {
-          'variables': {
-            'command': ['foo'],
-          },
-        }],
-        ['OS=="abc"', {
-          'variables': {
-            'command': ['bar'],
-          },
-        }],
-      ],
-    }
-    self.assertEqual(expected, config.make_isolate_file())
-
-  def test_make_isolate_4_variables(self):
-    # Test multiple combinations of bound and free variables.
-    config = isolate_format.Configs(None, ('CHROMEOS', 'OS', 'BRAND', 'LIB'))
-    config._by_config = {
-        (0, 'linux', None, 's'): isolate_format.ConfigSettings(
-            {'command': ['bar']}),
-        (None, 'mac', None, 's'): isolate_format.ConfigSettings(
-            {'command': ['foo']}),
-        (None, 'win', None, 's'): isolate_format.ConfigSettings(
-            {'command': ['ziz']}),
-        (0, 'win', 'Chrome', 's'): isolate_format.ConfigSettings(
-            {'command': ['baz']}),
-    }
-    expected = {
-      'conditions': [
-        ['CHROMEOS==0 and OS=="linux" and LIB=="s"', {
-          'variables': {
-            'command': ['bar'],
-          },
-        }],
-        # TODO(maruel): Short by key name.
-        ['CHROMEOS==0 and OS=="win" and BRAND=="Chrome" and LIB=="s"', {
-          'variables': {
-            'command': ['baz'],
-          },
-        }],
-        ['OS=="mac" and LIB=="s"', {
-          'variables': {
-            'command': ['foo'],
-          },
-        }],
-        ['OS=="win" and LIB=="s"', {
-          'variables': {
-            'command': ['ziz'],
-          },
-        }],
-      ],
-    }
-    self.assertEqual(expected, config.make_isolate_file())
-
-  def test_merge_three_conditions(self):
-    values = {
-      ('linux',): {
-        'isolate_dependency_tracked': ['file_common', 'file_linux'],
+      (None, None): {
+        'isolate_dir': FAKE_DIR,
       },
-      ('mac',): {
-        'isolate_dependency_tracked': ['file_common', 'file_mac'],
+      (None, 'abc'): {
+        'command': ['bar'],
+        'isolate_dir': FAKE_DIR,
       },
-      ('win',): {
-        'isolate_dependency_tracked': ['file_common', 'file_win'],
+      ('1', None): {
+        'command': ['foo'],
+        'isolate_dir': FAKE_DIR,
       },
     }
-    expected = {
-      'conditions': [
-        ['OS=="linux"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_linux',
-            ],
-          },
-        }],
-        ['OS=="linux" or OS=="mac" or OS=="win"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_common',
-            ],
-          },
-        }],
-        ['OS=="mac"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_mac',
-            ],
-          },
-        }],
-        ['OS=="win"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_win',
-            ],
-          },
-        }],
-      ],
-    }
-    actual = isolate_format.convert_map_to_isolate_dict(
-        isolate_format.reduce_inputs(isolate_format.invert_map(values)),
-        ('OS',))
-    self.assertEqual(expected, actual)
+    self.assertEqual(expected, flatten)
 
-  def test_merge_three_conditions_read_only(self):
-    values = {
-      ('linux',): {
-        'isolate_dependency_tracked': ['file_common', 'file_linux'],
-        'read_only': 1,
-      },
-      ('mac',): {
-        'isolate_dependency_tracked': ['file_common', 'file_mac'],
-        'read_only': 0,
-      },
-      ('win',): {
-        'isolate_dependency_tracked': ['file_common', 'file_win'],
-        'read_only': 2,
-      },
-      ('amiga',): {
-        'read_only': 1,
-      }
-    }
+  def test_ConfigSettings_union(self):
+    lhs_values = {}
+    rhs_values = {'files': ['data/', 'test/data/']}
+    lhs = isolate_format.ConfigSettings(lhs_values, '/src/net/third_party/nss')
+    rhs = isolate_format.ConfigSettings(rhs_values, '/src/base')
+    out = lhs.union(rhs)
     expected = {
-      'conditions': [
-        ['OS=="amiga" or OS=="linux"', {
-          'variables': {
-            'read_only': 1,
-          },
-        }],
-        ['OS=="linux"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_linux',
-            ],
-          },
-        }],
-        ['OS=="linux" or OS=="mac" or OS=="win"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_common',
-            ],
-          },
-        }],
-        ['OS=="mac"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_mac',
-            ],
-            'read_only': 0,
-          },
-        }],
-        ['OS=="win"', {
-          'variables': {
-            'isolate_dependency_tracked': [
-              'file_win',
-            ],
-            'read_only': 2,
-          },
-        }],
-      ],
+      'files': ['data/', 'test/data/'],
+      'isolate_dir': '/src/base',
     }
-    actual = isolate_format.convert_map_to_isolate_dict(
-        isolate_format.reduce_inputs(isolate_format.invert_map(values)),
-        ('OS',))
-    self.assertEqual(expected, actual)
+    self.assertEqual(expected, out.flatten())
 
   def test_configs_comment(self):
     # Pylint is confused with isolate_format.union() return type.
     # pylint: disable=E1103
-    configs = isolate_format.union(
-        isolate_format.load_isolate_as_config(
-            FAKE_DIR, {}, '# Yo dawg!\n# Chill out.\n'),
+    configs = isolate_format.load_isolate_as_config(
+            FAKE_DIR, {}, '# Yo dawg!\n# Chill out.\n').union(
         isolate_format.load_isolate_as_config(FAKE_DIR, {}, None))
     self.assertEqual('# Yo dawg!\n# Chill out.\n', configs.file_comment)
 
-    configs = isolate_format.union(
-        isolate_format.load_isolate_as_config(FAKE_DIR, {}, None),
+    configs = isolate_format.load_isolate_as_config(FAKE_DIR, {}, None).union(
         isolate_format.load_isolate_as_config(
             FAKE_DIR, {}, '# Yo dawg!\n# Chill out.\n'))
     self.assertEqual('# Yo dawg!\n# Chill out.\n', configs.file_comment)
 
     # Only keep the first one.
-    configs = isolate_format.union(
-        isolate_format.load_isolate_as_config(FAKE_DIR, {}, '# Yo dawg!\n'),
-        isolate_format.load_isolate_as_config(FAKE_DIR, {}, '# Chill out.\n'))
+    configs = isolate_format.load_isolate_as_config(
+        FAKE_DIR, {}, '# Yo dawg!\n').union(
+            isolate_format.load_isolate_as_config(
+                FAKE_DIR, {}, '# Chill out.\n'))
     self.assertEqual('# Yo dawg!\n', configs.file_comment)
 
   def test_extract_comment(self):
@@ -892,61 +424,57 @@ class IsolateFormatTest(unittest.TestCase):
   def test_pretty_print_mid_size(self):
     value = {
       'variables': {
-        'bar': [
+        'files': [
           'file1',
           'file2',
         ],
       },
       'conditions': [
-        ['OS=\"foo\"', {
+        ['OS==\"foo\"', {
           'variables': {
-            KEY_UNTRACKED: [
-              'dir1',
-              'dir2',
-            ],
-            KEY_TRACKED: [
-              'file4',
+            'files': [
+              'dir1/',
+              'dir2/',
               'file3',
+              'file4',
             ],
             'command': ['python', '-c', 'print "H\\i\'"'],
             'read_only': 2,
-            'relative_cwd': 'isol\'at\\e',
           },
         }],
-        ['OS=\"bar\"', {
+        ['OS==\"bar\"', {
           'variables': {},
         }],
       ],
     }
+    isolate_format.verify_root(value, {})
+    # This is an .isolate format.
     expected = (
         "{\n"
         "  'variables': {\n"
-        "    'bar': [\n"
+        "    'files': [\n"
         "      'file1',\n"
         "      'file2',\n"
         "    ],\n"
         "  },\n"
         "  'conditions': [\n"
-        "    ['OS=\"foo\"', {\n"
+        "    ['OS==\"foo\"', {\n"
         "      'variables': {\n"
         "        'command': [\n"
         "          'python',\n"
         "          '-c',\n"
         "          'print \"H\\i\'\"',\n"
         "        ],\n"
-        "        'relative_cwd': 'isol\\'at\\\\e',\n"
-        "        'read_only': 2\n"
-        "        'isolate_dependency_tracked': [\n"
-        "          'file4',\n"
+        "        'files': [\n"
+        "          'dir1/',\n"
+        "          'dir2/',\n"
         "          'file3',\n"
+        "          'file4',\n"
         "        ],\n"
-        "        'isolate_dependency_untracked': [\n"
-        "          'dir1',\n"
-        "          'dir2',\n"
-        "        ],\n"
+        "        'read_only': 2,\n"
         "      },\n"
         "    }],\n"
-        "    ['OS=\"bar\"', {\n"
+        "    ['OS==\"bar\"', {\n"
         "      'variables': {\n"
         "      },\n"
         "    }],\n"
@@ -964,9 +492,9 @@ class IsolateFormatTest(unittest.TestCase):
         }],
       ],
     }
-    with self.assertRaises(isolate_format.isolateserver.ConfigError):
+    with self.assertRaises(isolate_format.IsolateError):
       isolate_format.load_isolate_as_config(
-          '.', isolate_with_else_clauses, None)
+          FAKE_DIR, isolate_with_else_clauses, None)
 
   def test_match_configs(self):
     expectations = [
@@ -1012,14 +540,14 @@ class IsolateFormatTest(unittest.TestCase):
   def test_load_with_globals(self):
     values = {
       'variables': {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_common',
         ],
       },
       'conditions': [
         ['OS=="linux"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_linux',
             ],
             'read_only': 1,
@@ -1027,7 +555,7 @@ class IsolateFormatTest(unittest.TestCase):
         }],
         ['OS=="mac" or OS=="win"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_non_linux',
             ],
             'read_only': 0,
@@ -1037,71 +565,36 @@ class IsolateFormatTest(unittest.TestCase):
     }
     expected = {
       (None,): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_common',
         ],
+        'isolate_dir': FAKE_DIR,
       },
       ('linux',): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_linux',
         ],
+        'isolate_dir': FAKE_DIR,
         'read_only': 1,
       },
       ('mac',): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_non_linux',
         ],
+        'isolate_dir': FAKE_DIR,
         'read_only': 0,
       },
       ('win',): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_non_linux',
         ],
+        'isolate_dir': FAKE_DIR,
         'read_only': 0,
       },
     }
-    actual = isolate_format.load_isolate_as_config('.', values, None)
+    actual = isolate_format.load_isolate_as_config(FAKE_DIR, values, None)
     self.assertEqual(expected, actual.flatten())
 
-  def test_configs_with_globals(self):
-    c = isolate_format.Configs(None, ('x', 'y'))
-    c.set_config((1, 1), isolate_format.ConfigSettings({KEY_TRACKED: ['1,1']}))
-    c.set_config((2, 2), isolate_format.ConfigSettings({KEY_TRACKED: ['2,2']}))
-    c.set_config(
-        (1, None), isolate_format.ConfigSettings({KEY_TRACKED: ['1,y']}))
-    c.set_config(
-        (None, 2), isolate_format.ConfigSettings({KEY_TRACKED: ['x,2']}))
-    c.set_config(
-        (None, None), isolate_format.ConfigSettings({KEY_TRACKED: ['x,y']}))
-    expected = {
-      (None, None): {KEY_TRACKED: ['x,y']},
-      (None, 2): {KEY_TRACKED: ['x,2']},
-      (1, None): {KEY_TRACKED: ['1,y']},
-      (1, 1): {KEY_TRACKED: ['1,1']},
-      (2, 2): {KEY_TRACKED: ['2,2']},
-    }
-    self.assertEqual(expected, c.flatten())
-
-    s = c.get_config((1, 1))
-    self.assertEqual({KEY_TRACKED: ['1,1', '1,y', 'x,y']}, s.flatten())
-
-    s = c.get_config((1, None))
-    self.assertEqual({KEY_TRACKED: ['1,y', 'x,y']}, s.flatten())
-
-    s = c.get_config((None, None))
-    self.assertEqual({KEY_TRACKED: ['x,y']}, s.flatten())
-
-    expected = {
-      'conditions': [
-        ['x==1', {'variables': {KEY_TRACKED: ['1,y']}}],
-        ['x==1 and y==1', {'variables': {KEY_TRACKED: ['1,1']}}],
-        ['x==2 and y==2', {'variables': {KEY_TRACKED: ['2,2']}}],
-        ['y==2', {'variables': {KEY_TRACKED: ['x,2']}}],
-      ],
-      'variables': {KEY_TRACKED: ['x,y']},
-    }
-    self.assertEqual(expected, c.make_isolate_file())
-
 
 class IsolateFormatTmpDirTest(unittest.TestCase):
   def setUp(self):
@@ -1110,21 +603,21 @@ class IsolateFormatTmpDirTest(unittest.TestCase):
 
   def tearDown(self):
     try:
-      run_isolated.rmtree(self.tempdir)
+      file_path.rmtree(self.tempdir)
     finally:
       super(IsolateFormatTmpDirTest, self).tearDown()
 
   def test_load_with_includes(self):
     included_isolate = {
       'variables': {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_common',
         ],
       },
       'conditions': [
         ['OS=="linux"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_linux',
             ],
             'read_only': 1,
@@ -1132,7 +625,7 @@ class IsolateFormatTmpDirTest(unittest.TestCase):
         }],
         ['OS=="mac" or OS=="win"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_non_linux',
             ],
             'read_only': 0,
@@ -1140,19 +633,19 @@ class IsolateFormatTmpDirTest(unittest.TestCase):
         }],
       ],
     }
-    tools.write_json(
-        os.path.join(self.tempdir, 'included.isolate'), included_isolate, True)
+    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': [
+        'files': [
           'file_less_common',
         ],
       },
       'conditions': [
         ['OS=="mac"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_mac',
             ],
             'read_only': 2,
@@ -1164,117 +657,299 @@ class IsolateFormatTmpDirTest(unittest.TestCase):
 
     expected = {
       (None,): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_common',
           'file_less_common',
         ],
+        'isolate_dir': self.tempdir,
       },
       ('linux',): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_linux',
         ],
+        'isolate_dir': self.tempdir,
         'read_only': 1,
       },
       ('mac',): {
-        'isolate_dependency_tracked': [
+        'files': [
           'file_mac',
           'file_non_linux',
         ],
+        'isolate_dir': self.tempdir,
         'read_only': 2,
       },
       ('win',): {
-        'isolate_dependency_tracked': [
+        '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.
+    # 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', 'bar',
+              'foo', 'linux',
             ],
-            'isolate_dependency_tracked': [
+            'files': [
               'file_linux',
             ],
           },
         }],
         ['OS=="mac" or OS=="win"', {
           'variables': {
-            'isolate_dependency_tracked': [
+            'files': [
               'file_non_linux',
             ],
           },
         }],
-        ['OS=="win"', {
+      ],
+    }
+    isolate2 = {
+      'conditions': [
+        ['OS=="linux" or OS=="mac"', {
+          'variables': {
+            'command': [
+              'foo', 'linux_or_mac',
+            ],
+            'files': [
+              'other/file',
+            ],
+          },
+        }],
+      ],
+    }
+    isolate3 = {
+      'includes': [
+        '../1/isolate1.isolate',
+        '2/isolate2.isolate',
+      ],
+      'conditions': [
+        ['OS=="amiga"', {
+          'variables': {
+            'files': [
+              'file_amiga',
+            ],
+          },
+        }],
+        ['OS=="mac"', {
           'variables': {
             'command': [
-              'foo', 'bar',
+              'foo', 'mac',
+            ],
+            '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
+    # 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'],
+        '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 in isolate3 takes precedence over the ones included.
+        'command': ['foo', 'mac'],
+        'files': [
+          '../1/file_non_linux',
+          '2/other/file',
+          'file_mac',
+        ],
+        'isolate_dir': dir_3,
+      },
+      ('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_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',
             ],
           },
         }],
       ],
     }
-    tools.write_json(
-        os.path.join(self.tempdir, 'isolate1.isolate'), isolate1, True)
     isolate2 = {
       'conditions': [
         ['OS=="linux" or OS=="mac"', {
           'variables': {
             'command': [
-              'zoo',
+              'foo', 'linux_or_mac', '<(PATH)',
             ],
-            'isolate_dependency_tracked': [
-              'other/file',
+            'files': [
+              '<(PATH)/other/file',
             ],
           },
         }],
       ],
     }
-    tools.write_json(
-        os.path.join(self.tempdir, 'isolate2.isolate'), isolate2, True)
     isolate3 = {
-      'includes': ['isolate1.isolate', 'isolate2.isolate'],
+      'includes': [
+        '../1/isolate1.isolate',
+        '2/isolate2.isolate',
+      ],
       'conditions': [
+        ['OS=="amiga"', {
+          'variables': {
+            'files': [
+              '<(PATH)/file_amiga',
+            ],
+          },
+        }],
         ['OS=="mac"', {
           'variables': {
             'command': [
-              'yo', 'dawg',
+              'foo', 'mac', '<(PATH)',
             ],
-            'isolate_dependency_tracked': [
-              'file_mac',
+            '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)
 
-    actual = isolate_format.load_isolate_as_config(self.tempdir, isolate3, None)
+    # 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,): {},
+      (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': ['zoo'],
-        'isolate_dependency_tracked': ['file_linux', 'other/file'],
+        # 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 in isolate3 takes precedence.
-        'command': ['yo', 'dawg'],
-        'isolate_dependency_tracked': [
-          'file_mac',
-          'file_non_linux',
-          'other/file',
+        'command': ['foo', 'mac', '<(PATH)'],
+        'files': [
+          '<(PATH)/file_mac',
+          '<(PATH)/file_non_linux',
+          '<(PATH)/other/file',
         ],
+        'isolate_dir': dir_3,
       },
       ('win',): {
-        'command': ['foo', 'bar'],
-        'isolate_dependency_tracked': ['file_non_linux'],
+        # command comes from isolate1.
+        'command': ['foo', 'amiga_or_win', '<(PATH)'],
+        'files': [
+          '<(PATH)/file_non_linux',
+        ],
+        'isolate_dir': dir_1,
       },
     }
     self.assertEqual(expected, actual.flatten())