Beispiel #1
0
    def load_deps_file(self, objdir, fh):
        """Load a single dependency file."""
        for rule in read_dep_makefile(fh):
            for target in rule.targets():
                full_target = mozpath.normpath(mozpath.join(objdir,
                    target))

                normalized_deps = []
                for d in rule.dependencies():
                    full_depend = mozpath.join(objdir, d)
                    # Resolve symbolic links from $objdir/dist/include and
                    # the like to their srcdir equivalents.  Don't use
                    # _realpath_cache.get(full_depend, os.path.realpath(...)),
                    # as the whole point of this cache is to avoid hitting
                    # the filesystem if we don't have to.
                    if full_depend in self._realpath_cache:
                        full_depend = self._realpath_cache[full_depend]
                    else:
                        resolved = os.path.realpath(full_depend)
                        self._realpath_cache[full_depend] = resolved
                        full_depend = resolved
                    normalized_deps.append(full_depend)
                    self.dependencies.setdefault(full_depend, set()).add(full_target)

                assert full_target not in self.targets
                self.targets[full_target] = normalized_deps
Beispiel #2
0
    def copy(self, dest, skip_if_older=True):
        '''
        Invokes the preprocessor to create the destination file.
        '''
        if isinstance(dest, six.string_types):
            dest = Dest(dest)
        else:
            assert isinstance(dest, Dest)

        # We have to account for the case where the destination exists and is a
        # symlink to something. Since we know the preprocessor is certainly not
        # going to create a symlink, we can just remove the existing one. If the
        # destination is not a symlink, we leave it alone, since we're going to
        # overwrite its contents anyway.
        # If symlinks aren't supported at all, we can skip this step.
        # See comment in AbsoluteSymlinkFile about Windows.
        if hasattr(os, 'symlink') and platform.system() != 'Windows':
            if os.path.islink(dest.path):
                os.remove(dest.path)

        pp_deps = set(self.extra_depends)

        # If a dependency file was specified, and it exists, add any
        # dependencies from that file to our list.
        if self.depfile and os.path.exists(self.depfile):
            target = mozpath.normpath(dest.name)
            with _open(self.depfile, 'rt') as fileobj:
                for rule in makeutil.read_dep_makefile(fileobj):
                    if target in rule.targets():
                        pp_deps.update(rule.dependencies())

        skip = False
        if dest.exists() and skip_if_older:
            # If a dependency file was specified, and it doesn't exist,
            # assume that the preprocessor needs to be rerun. That will
            # regenerate the dependency file.
            if self.depfile and not os.path.exists(self.depfile):
                skip = False
            else:
                skip = not BaseFile.any_newer(dest.path, pp_deps)

        if skip:
            return False

        deps_out = None
        if self.depfile:
            deps_out = FileAvoidWrite(self.depfile)
        pp = Preprocessor(defines=self.defines, marker=self.marker)
        pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings)

        with _open(self.path, 'rU') as input:
            pp.processFile(input=input, output=dest, depfile=deps_out)

        dest.close()
        if self.depfile:
            deps_out.close()

        return True
Beispiel #3
0
    def copy(self, dest, skip_if_older=True):
        '''
        Invokes the preprocessor to create the destination file.
        '''
        if isinstance(dest, basestring):
            dest = Dest(dest)
        else:
            assert isinstance(dest, Dest)

        # We have to account for the case where the destination exists and is a
        # symlink to something. Since we know the preprocessor is certainly not
        # going to create a symlink, we can just remove the existing one. If the
        # destination is not a symlink, we leave it alone, since we're going to
        # overwrite its contents anyway.
        # If symlinks aren't supported at all, we can skip this step.
        if hasattr(os, 'symlink'):
            if os.path.islink(dest.path):
                os.remove(dest.path)

        pp_deps = set(self.extra_depends)

        # If a dependency file was specified, and it exists, add any
        # dependencies from that file to our list.
        if self.depfile and os.path.exists(self.depfile):
            target = mozpath.normpath(dest.name)
            with open(self.depfile, 'rb') as fileobj:
                for rule in makeutil.read_dep_makefile(fileobj):
                    if target in rule.targets():
                        pp_deps.update(rule.dependencies())

        skip = False
        if dest.exists() and skip_if_older:
            # If a dependency file was specified, and it doesn't exist,
            # assume that the preprocessor needs to be rerun. That will
            # regenerate the dependency file.
            if self.depfile and not os.path.exists(self.depfile):
                skip = False
            else:
                skip = not BaseFile.any_newer(dest.path, pp_deps)

        if skip:
            return False

        deps_out = None
        if self.depfile:
            deps_out = FileAvoidWrite(self.depfile)
        pp = Preprocessor(defines=self.defines, marker=self.marker)
        pp.setSilenceDirectiveWarnings(self.silence_missing_directive_warnings)

        with open(self.path, 'rU') as input:
            pp.processFile(input=input, output=dest, depfile=deps_out)

        dest.close()
        if self.depfile:
            deps_out.close()

        return True
Beispiel #4
0
 def add_dependencies(self, fh):
     depfile = self.normpath(os.path.abspath(fh.name))
     for rule in read_dep_makefile(fh):
         deps = list(rule.dependencies())
         if deps:
             deps = list(self.normpaths(deps))
             for t in self.normpaths(rule.targets()):
                 if t in self._targets:
                     raise Exception('Found target %s in %s and %s' %
                                     (t, self._targets[t][0], depfile))
                 self._targets[t] = (depfile, deps)
Beispiel #5
0
 def add_dependencies(self, fh):
     depfile = self.normpath(os.path.abspath(fh.name))
     for rule in read_dep_makefile(fh):
         deps = list(rule.dependencies())
         if deps:
             deps = list(self.normpaths(deps))
             for t in self.normpaths(rule.targets()):
                 if t in self._targets:
                     raise Exception('Found target %s in %s and %s'
                                     % (t, self._targets[t][0], depfile))
                 self._targets[t] = (depfile, deps)
Beispiel #6
0
 def test_read_dep_makefile(self):
     input = StringIO(
         os.path.abspath('foo') + ': bar\n' + 'baz qux: \\ \n' +
         'hoge \\\n' + 'piyo \\\n' + 'fuga\n' + 'fuga:\n')
     result = list(read_dep_makefile(input))
     self.assertEqual(len(result), 2)
     self.assertEqual(list(result[0].targets()),
                      [os.path.abspath('foo').replace(os.sep, '/')])
     self.assertEqual(list(result[0].dependencies()), ['bar'])
     self.assertEqual(list(result[1].targets()), ['baz', 'qux'])
     self.assertEqual(list(result[1].dependencies()),
                      ['hoge', 'piyo', 'fuga'])
Beispiel #7
0
 def test_read_dep_makefile(self):
     input = StringIO(
         os.path.abspath('foo') + ': bar\n' +
         'baz qux: \\ \n' +
         'hoge \\\n' +
         'piyo \\\n' +
         'fuga\n' +
         'fuga:\n'
     )
     result = list(read_dep_makefile(input))
     self.assertEqual(len(result), 2)
     self.assertEqual(list(result[0].targets()), [os.path.abspath('foo').replace(os.sep, '/')])
     self.assertEqual(list(result[0].dependencies()), ['bar'])
     self.assertEqual(list(result[1].targets()), ['baz', 'qux'])
     self.assertEqual(list(result[1].dependencies()), ['hoge', 'piyo', 'fuga'])
Beispiel #8
0
 def test_read_dep_makefile(self):
     input = StringIO(
         os.path.abspath("foo")
         + ": bar\n"
         + "baz qux: \\ \n"
         + "hoge \\\n"
         + "piyo \\\n"
         + "fuga\n"
         + "fuga:\n"
     )
     result = list(read_dep_makefile(input))
     self.assertEqual(len(result), 2)
     self.assertEqual(
         list(result[0].targets()), [os.path.abspath("foo").replace(os.sep, "/")]
     )
     self.assertEqual(list(result[0].dependencies()), ["bar"])
     self.assertEqual(list(result[1].targets()), ["baz", "qux"])
     self.assertEqual(list(result[1].dependencies()), ["hoge", "piyo", "fuga"])