Example #1
0
def CMDmerge(args):
  """Reads and merges the data from the trace back into the original .isolate.

  Ignores --outdir.
  """
  parser = OptionParserIsolate(command='merge', require_result=False)
  options, _ = parser.parse_args(args)
  complete_state = load_complete_state(options, NO_INFO)
  value = read(complete_state)

  # Now take that data and union it into the original .isolate file.
  with open(complete_state.saved_state.isolate_file, 'r') as f:
    prev_content = f.read()
  prev_config = merge_isolate.load_gyp(
      merge_isolate.eval_content(prev_content),
      merge_isolate.extract_comment(prev_content),
      merge_isolate.DEFAULT_OSES)
  new_config = merge_isolate.load_gyp(
      value,
      '',
      merge_isolate.DEFAULT_OSES)
  config = merge_isolate.union(prev_config, new_config)
  # pylint: disable=E1103
  data = merge_isolate.convert_map_to_gyp(
      *merge_isolate.reduce_inputs(*merge_isolate.invert_map(config.flatten())))
  print 'Updating %s' % complete_state.saved_state.isolate_file
  with open(complete_state.saved_state.isolate_file, 'wb') as f:
    merge_isolate.print_all(config.file_comment, data, f)

  return 0
 def test_merge_two_empty(self):
     # Flat stay flat. Pylint is confused about union() return type.
     # pylint: disable=E1103
     actual = merge_isolate.union(
         merge_isolate.union(merge_isolate.Configs([]),
                             merge_isolate.load_gyp({})),
         merge_isolate.load_gyp({})).flatten()
     self.assertEquals({}, actual)
Example #3
0
 def test_load_three_conditions(self):
   linux = {
     'conditions': [
       ['OS=="linux"', {
         'variables': {
           'isolate_dependency_tracked': [
             'file_linux',
             'file_common',
           ],
         },
       }],
     ],
   }
   mac = {
     'conditions': [
       ['OS=="mac"', {
         'variables': {
           'isolate_dependency_tracked': [
             'file_mac',
             'file_common',
           ],
         },
       }],
     ],
   }
   win = {
     'conditions': [
       ['OS=="win"', {
         'variables': {
           'isolate_dependency_tracked': [
             'file_win',
             'file_common',
           ],
         },
       }],
     ],
   }
   expected = {
     'linux': {
       'isolate_dependency_tracked': ['file_common', 'file_linux'],
     },
     'mac': {
       'isolate_dependency_tracked': ['file_common', 'file_mac'],
     },
     'win': {
       'isolate_dependency_tracked': ['file_common', 'file_win'],
     },
   }
   # Pylint is confused about union() return type.
   # pylint: disable=E1103
   configs = merge_isolate.union(
       merge_isolate.union(
         merge_isolate.union(
           merge_isolate.Configs([], None),
           merge_isolate.load_gyp(linux, None, [])),
         merge_isolate.load_gyp(mac, None, [])),
       merge_isolate.load_gyp(win, None, [])).flatten()
   self.assertEquals(expected, configs)
Example #4
0
 def test_merge_two_empty(self):
   # Flat stay flat. Pylint is confused about union() return type.
   # pylint: disable=E1103
   actual = merge_isolate.union(
       merge_isolate.union(
         merge_isolate.Configs([], None),
         merge_isolate.load_gyp({}, None, [])),
       merge_isolate.load_gyp({}, None, [])).flatten()
   self.assertEquals({}, actual)
Example #5
0
 def test_load_gyp_duplicate_command(self):
   value = {
     'variables': {
       'command': ['rm', '-rf', '/'],
     },
     'conditions': [
       ['OS=="atari"', {
         'variables': {
           'command': ['echo', 'Hello World'],
         },
       }],
     ],
   }
   try:
     merge_isolate.load_gyp(value, None, [])
     self.fail()
   except AssertionError:
     pass
 def test_load_two_conditions(self):
     linux = {
         'conditions': [
             [
                 'OS=="linux"', {
                     'variables': {
                         'isolate_dependency_tracked': [
                             'file_linux',
                             'file_common',
                         ],
                     },
                 }
             ],
         ],
     }
     mac = {
         'conditions': [
             [
                 'OS=="mac"', {
                     'variables': {
                         'isolate_dependency_tracked': [
                             'file_mac',
                             'file_common',
                         ],
                     },
                 }
             ],
         ],
     }
     expected = {
         'linux': {
             'isolate_dependency_tracked': ['file_common', 'file_linux'],
         },
         'mac': {
             'isolate_dependency_tracked': ['file_common', 'file_mac'],
         },
     }
     # Pylint is confused about union() return type.
     # pylint: disable=E1103
     configs = merge_isolate.union(
         merge_isolate.union(merge_isolate.Configs([]),
                             merge_isolate.load_gyp(linux)),
         merge_isolate.load_gyp(mac)).flatten()
     self.assertEquals(expected, configs)
 def test_load_gyp_duplicate_command(self):
     value = {
         'variables': {
             'command': ['rm', '-rf', '/'],
         },
         'conditions': [
             [
                 'OS=="atari"', {
                     'variables': {
                         'command': ['echo', 'Hello World'],
                     },
                 }
             ],
         ],
     }
     try:
         merge_isolate.load_gyp(value)
         self.fail()
     except AssertionError:
         pass
Example #8
0
def load_isolate(content, error):
    """Loads the .isolate file. Returns the command, dependencies and read_only
  flag.
  """
    # Load the .isolate file, process its conditions, retrieve the command and
    # dependencies.
    configs = merge_isolate.load_gyp(merge_isolate.eval_content(content))
    flavor = trace_inputs.get_flavor()
    config = configs.per_os.get(flavor) or configs.per_os.get(None)
    if not config:
        error('Failed to load configuration for \'%s\'' % flavor)
    # Merge tracked and untracked dependencies, isolate.py doesn't care about the
    # trackability of the dependencies, only the build tool does.
    return config.command, config.tracked + config.untracked, config.read_only
Example #9
0
def load_isolate(content, error):
  """Loads the .isolate file. Returns the command, dependencies and read_only
  flag.
  """
  # Load the .isolate file, process its conditions, retrieve the command and
  # dependencies.
  configs = merge_isolate.load_gyp(merge_isolate.eval_content(content))
  flavor = trace_inputs.get_flavor()
  config = configs.per_os.get(flavor) or configs.per_os.get(None)
  if not config:
    error('Failed to load configuration for \'%s\'' % flavor)
  # Merge tracked and untracked dependencies, isolate.py doesn't care about the
  # trackability of the dependencies, only the build tool does.
  return config.command, config.tracked + config.untracked, config.read_only
Example #10
0
def load_isolate(content, error):
    """Loads the .isolate file and returns the information unprocessed.

  Returns the command, dependencies and read_only flag. The dependencies are
  fixed to use os.path.sep.
  """
    # Load the .isolate file, process its conditions, retrieve the command and
    # dependencies.
    configs = merge_isolate.load_gyp(merge_isolate.eval_content(content))
    flavor = trace_inputs.get_flavor()
    config = configs.per_os.get(flavor) or configs.per_os.get(None)
    if not config:
        error("Failed to load configuration for '%s'" % flavor)
    # Merge tracked and untracked dependencies, isolate.py doesn't care about the
    # trackability of the dependencies, only the build tool does.
    dependencies = [f.replace("/", os.path.sep) for f in config.tracked + config.untracked]
    return config.command, dependencies, config.read_only
Example #11
0
 def test_load_gyp_no_condition(self):
   value = {
     'variables': {
       KEY_TRACKED: ['a'],
       KEY_UNTRACKED: ['b'],
     },
   }
   expected = {
     KEY_TRACKED: ['a'],
     KEY_UNTRACKED: ['b'],
   }
   actual = merge_isolate.load_gyp(value, None, [])
   # Flattening the whole config will discard 'None'.
   self.assertEquals({}, actual.flatten())
   self.assertEquals([None], actual.per_os.keys())
   # But the 'None' value is still available as a backup.
   self.assertEquals(expected, actual.per_os[None].flatten())
Example #12
0
 def test_load_gyp_no_condition(self):
     value = {
         'variables': {
             KEY_TRACKED: ['a'],
             KEY_UNTRACKED: ['b'],
         },
     }
     expected = {
         KEY_TRACKED: ['a'],
         KEY_UNTRACKED: ['b'],
     }
     actual = merge_isolate.load_gyp(value)
     # Flattening the whole config will discard 'None'.
     self.assertEquals({}, actual.flatten())
     self.assertEquals([None], actual.per_os.keys())
     # But the 'None' value is still available as a backup.
     self.assertEquals(expected, actual.per_os[None].flatten())
Example #13
0
def load_isolate(content, variables, error):
    """Loads the .isolate file. Returns the command, dependencies and read_only
  flag.
  """
    # Load the .isolate file, process its conditions, retrieve the command and
    # dependencies.
    configs = merge_isolate.load_gyp(merge_isolate.eval_content(content))
    flavor = trace_inputs.get_flavor()
    config = configs.per_os.get(flavor) or configs.per_os.get(None)
    if not config:
        error('Failed to load configuration for \'%s\'' % flavor)

    # Convert the variables and merge tracked and untracked dependencies.
    # isolate.py doesn't care about the trackability of the dependencies.
    infiles = [eval_variables(f, variables) for f in config.tracked
               ] + [eval_variables(f, variables) for f in config.untracked]
    command = [eval_variables(i, variables) for i in config.command]
    return command, infiles, config.read_only
Example #14
0
def load_isolate(content, error):
    """Loads the .isolate file and returns the information unprocessed.

  Returns the command, dependencies and read_only flag. The dependencies are
  fixed to use os.path.sep.
  """
    # Load the .isolate file, process its conditions, retrieve the command and
    # dependencies.
    configs = merge_isolate.load_gyp(merge_isolate.eval_content(content), None,
                                     merge_isolate.DEFAULT_OSES)
    flavor = isolate_common.get_flavor()
    config = configs.per_os.get(flavor) or configs.per_os.get(None)
    if not config:
        error('Failed to load configuration for \'%s\'' % flavor)
    # Merge tracked and untracked dependencies, isolate.py doesn't care about the
    # trackability of the dependencies, only the build tool does.
    dependencies = [
        f.replace('/', os.path.sep) for f in config.tracked + config.untracked
    ]
    return config.command, dependencies, config.read_only
Example #15
0
def load_isolate(content):
  """Loads the .isolate file and returns the information unprocessed.

  Returns the command, dependencies and read_only flag. The dependencies are
  fixed to use os.path.sep.
  """
  # Load the .isolate file, process its conditions, retrieve the command and
  # dependencies.
  configs = merge_isolate.load_gyp(
      merge_isolate.eval_content(content), None, merge_isolate.DEFAULT_OSES)
  flavor = isolate_common.get_flavor()
  config = configs.per_os.get(flavor) or configs.per_os.get(None)
  if not config:
    raise ExecutionError('Failed to load configuration for \'%s\'' % flavor)
  # Merge tracked and untracked dependencies, isolate.py doesn't care about the
  # trackability of the dependencies, only the build tool does.
  dependencies = [
    f.replace('/', os.path.sep) for f in config.tracked + config.untracked
  ]
  touched = [f.replace('/', os.path.sep) for f in config.touched]
  return config.command, dependencies, touched, config.read_only
Example #16
0
  def test_configs_comment(self):
    # Pylint is confused with merge_isolate.union() return type.
    # pylint: disable=E1103
    configs = merge_isolate.union(
        merge_isolate.load_gyp({}, '# Yo dawg!\n# Chill out.\n', []),
        merge_isolate.load_gyp({}, None, []))
    self.assertEquals('# Yo dawg!\n# Chill out.\n', configs.file_comment)

    configs = merge_isolate.union(
        merge_isolate.load_gyp({}, None, []),
        merge_isolate.load_gyp({}, '# Yo dawg!\n# Chill out.\n', []))
    self.assertEquals('# Yo dawg!\n# Chill out.\n', configs.file_comment)

    # Only keep the first one.
    configs = merge_isolate.union(
        merge_isolate.load_gyp({}, '# Yo dawg!\n', []),
        merge_isolate.load_gyp({}, '# Chill out.\n', []))
    self.assertEquals('# Yo dawg!\n', configs.file_comment)
Example #17
0
    def test_configs_comment(self):
        # Pylint is confused with merge_isolate.union() return type.
        # pylint: disable=E1103
        configs = merge_isolate.union(
            merge_isolate.load_gyp({}, '# Yo dawg!\n# Chill out.\n', []),
            merge_isolate.load_gyp({}, None, []))
        self.assertEquals('# Yo dawg!\n# Chill out.\n', configs.file_comment)

        configs = merge_isolate.union(
            merge_isolate.load_gyp({}, None, []),
            merge_isolate.load_gyp({}, '# Yo dawg!\n# Chill out.\n', []))
        self.assertEquals('# Yo dawg!\n# Chill out.\n', configs.file_comment)

        # Only keep the first one.
        configs = merge_isolate.union(
            merge_isolate.load_gyp({}, '# Yo dawg!\n', []),
            merge_isolate.load_gyp({}, '# Chill out.\n', []))
        self.assertEquals('# Yo dawg!\n', configs.file_comment)
Example #18
0
 def test_load_gyp(self):
   value = {
     'variables': {
       KEY_TRACKED: ['a'],
       KEY_UNTRACKED: ['b'],
     },
     'conditions': [
       ['OS=="atari"', {
         'variables': {
           KEY_TRACKED: ['c', 'x'],
           KEY_UNTRACKED: ['d'],
           'command': ['echo', 'Hello World'],
           'read_only': True,
         },
       }, {  # else
         'variables': {
           KEY_TRACKED: ['e', 'x'],
           KEY_UNTRACKED: ['f'],
           'command': ['echo', 'You should get an Atari'],
         },
       }],
       ['OS=="amiga"', {
         'variables': {
           KEY_TRACKED: ['g'],
           'read_only': False,
         },
       }],
       ['OS=="dendy"', {
       }],
       ['OS=="coleco"', {
       }, {  # else
         'variables': {
           KEY_UNTRACKED: ['h'],
           'read_only': None,
         },
       }],
     ],
   }
   expected = {
     'amiga': {
       'command': ['echo', 'You should get an Atari'],
       KEY_TRACKED: ['a', 'e', 'g', 'x'],
       KEY_UNTRACKED: ['b', 'f', 'h'],
       'read_only': False,
     },
     'atari': {
       'command': ['echo', 'Hello World'],
       KEY_TRACKED: ['a', 'c', 'x'],
       KEY_UNTRACKED: ['b', 'd', 'h'],
       'read_only': True,
     },
     'coleco': {
       'command': ['echo', 'You should get an Atari'],
       KEY_TRACKED: ['a', 'e', 'x'],
       KEY_UNTRACKED: ['b', 'f'],
     },
     'dendy': {
       'command': ['echo', 'You should get an Atari'],
       KEY_TRACKED: ['a', 'e', 'x'],
       KEY_UNTRACKED: ['b', 'f', 'h'],
     },
   }
   self.assertEquals(
       expected, merge_isolate.load_gyp(value, None, []).flatten())
Example #19
0
 def test_load_gyp_empty(self):
   self.assertEquals({}, merge_isolate.load_gyp({}, None, []).flatten())
Example #20
0
 def test_load_gyp(self):
     value = {
       'variables': {
         KEY_TRACKED: ['a'],
         KEY_UNTRACKED: ['b'],
       },
       'conditions': [
         ['OS=="atari"', {
           'variables': {
             KEY_TRACKED: ['c', 'x'],
             KEY_UNTRACKED: ['d'],
             'command': ['echo', 'Hello World'],
             'read_only': True,
           },
         }, {  # else
           'variables': {
             KEY_TRACKED: ['e', 'x'],
             KEY_UNTRACKED: ['f'],
             'command': ['echo', 'You should get an Atari'],
           },
         }],
         ['OS=="amiga"', {
           'variables': {
             KEY_TRACKED: ['g'],
             'read_only': False,
           },
         }],
         ['OS=="dendy"', {
         }],
         ['OS=="coleco"', {
         }, {  # else
           'variables': {
             KEY_UNTRACKED: ['h'],
             'read_only': None,
           },
         }],
       ],
     }
     expected = {
         'amiga': {
             'command': ['echo', 'You should get an Atari'],
             KEY_TRACKED: ['a', 'e', 'g', 'x'],
             KEY_UNTRACKED: ['b', 'f', 'h'],
             'read_only': False,
         },
         'atari': {
             'command': ['echo', 'Hello World'],
             KEY_TRACKED: ['a', 'c', 'x'],
             KEY_UNTRACKED: ['b', 'd', 'h'],
             'read_only': True,
         },
         'coleco': {
             'command': ['echo', 'You should get an Atari'],
             KEY_TRACKED: ['a', 'e', 'x'],
             KEY_UNTRACKED: ['b', 'f'],
         },
         'dendy': {
             'command': ['echo', 'You should get an Atari'],
             KEY_TRACKED: ['a', 'e', 'x'],
             KEY_UNTRACKED: ['b', 'f', 'h'],
         },
     }
     self.assertEquals(expected, merge_isolate.load_gyp(value).flatten())
Example #21
0
 def test_load_gyp_empty(self):
     self.assertEquals({}, merge_isolate.load_gyp({}).flatten())