Exemplo n.º 1
0
    def test_objdir_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))

        path = ObjDirPath(ctxt, "!qux")
        self.assertEqual(path, "!qux")
        self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "foo", "qux"))

        path = ObjDirPath(ctxt, "!../bar/qux")
        self.assertEqual(path, "!../bar/qux")
        self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "bar", "qux"))

        path = ObjDirPath(ctxt, "!/qux/qux")
        self.assertEqual(path, "!/qux/qux")
        self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, "../bar/qux")

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, "/qux/qux")

        path = ObjDirPath(path)
        self.assertIsInstance(path, ObjDirPath)
        self.assertEqual(path, "!/qux/qux")
        self.assertEqual(path.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        path = Path(path)
        self.assertIsInstance(path, ObjDirPath)
Exemplo n.º 2
0
    def test_objdir_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))

        path = ObjDirPath(ctxt, '!qux')
        self.assertEqual(path, '!qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        path = ObjDirPath(ctxt, '!../bar/qux')
        self.assertEqual(path, '!../bar/qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'bar', 'qux'))

        path = ObjDirPath(ctxt, '!/qux/qux')
        self.assertEqual(path, '!/qux/qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, '../bar/qux')

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, '/qux/qux')

        path = ObjDirPath(path)
        self.assertIsInstance(path, ObjDirPath)
        self.assertEqual(path, '!/qux/qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        path = Path(path)
        self.assertIsInstance(path, ObjDirPath)
Exemplo n.º 3
0
    def test_objdir_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))

        path = ObjDirPath(ctxt, "!qux")
        self.assertEqual(path, "!qux")
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, "foo", "qux"))

        path = ObjDirPath(ctxt, "!../bar/qux")
        self.assertEqual(path, "!../bar/qux")
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, "bar", "qux"))

        path = ObjDirPath(ctxt, "!/qux/qux")
        self.assertEqual(path, "!/qux/qux")
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, "../bar/qux")

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, "/qux/qux")

        path = ObjDirPath(path)
        self.assertIsInstance(path, ObjDirPath)
        self.assertEqual(path, "!/qux/qux")
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        path = Path(path)
        self.assertIsInstance(path, ObjDirPath)
Exemplo n.º 4
0
    def test_objdir_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))

        path = ObjDirPath(ctxt, '!qux')
        self.assertEqual(path, '!qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        path = ObjDirPath(ctxt, '!../bar/qux')
        self.assertEqual(path, '!../bar/qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'bar', 'qux'))

        path = ObjDirPath(ctxt, '!/qux/qux')
        self.assertEqual(path, '!/qux/qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, '../bar/qux')

        with self.assertRaises(ValueError):
            path = ObjDirPath(ctxt, '/qux/qux')

        path = ObjDirPath(path)
        self.assertIsInstance(path, ObjDirPath)
        self.assertEqual(path, '!/qux/qux')
        self.assertEqual(path.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        path = Path(path)
        self.assertIsInstance(path, ObjDirPath)
Exemplo n.º 5
0
    def test_path_typed_list(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))

        paths = [
            "!../bar/qux",
            "!/qux/qux",
            "!qux",
            "../bar/qux",
            "/qux/qux",
            "qux",
        ]

        MyList = ContextDerivedTypedList(Path)
        l = MyList(ctxt1)
        l += paths

        for p_str, p_path in zip(paths, l):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))
            self.assertEqual(p_path.join("foo"),
                             Path(ctxt1, mozpath.join(p_str, "foo")))

        l2 = MyList(ctxt2)
        l2 += paths

        for p_str, p_path in zip(paths, l2):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt2, p_str))

        # Assigning with Paths from another context doesn't rebase them
        l2 = MyList(ctxt2)
        l2 += l

        for p_str, p_path in zip(paths, l2):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))

        MyListWithFlags = ContextDerivedTypedListWithItems(
            Path,
            StrictOrderingOnAppendListWithFlagsFactory({
                "foo": bool,
            }),
        )
        l = MyListWithFlags(ctxt1)
        l += paths

        for p in paths:
            l[p].foo = True

        for p_str, p_path in zip(paths, l):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))
            self.assertEqual(l[p_str].foo, True)
            self.assertEqual(l[p_path].foo, True)
Exemplo n.º 6
0
    def test_path_typed_list(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        paths = [
            '!../bar/qux',
            '!/qux/qux',
            '!qux',
            '../bar/qux',
            '/qux/qux',
            'qux',
        ]

        MyList = ContextDerivedTypedList(Path)
        l = MyList(ctxt1)
        l += paths

        for p_str, p_path in zip(paths, l):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))
            self.assertEqual(p_path.join('foo'),
                             Path(ctxt1, mozpath.join(p_str, 'foo')))

        l2 = MyList(ctxt2)
        l2 += paths

        for p_str, p_path in zip(paths, l2):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt2, p_str))

        # Assigning with Paths from another context doesn't rebase them
        l2 = MyList(ctxt2)
        l2 += l

        for p_str, p_path in zip(paths, l2):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))

        MyListWithFlags = ContextDerivedTypedListWithItems(
            Path, StrictOrderingOnAppendListWithFlagsFactory({
                'foo': bool,
            }))
        l = MyListWithFlags(ctxt1)
        l += paths

        for p in paths:
            l[p].foo = True

        for p_str, p_path in zip(paths, l):
            self.assertEqual(p_str, p_path)
            self.assertEqual(p_path, Path(ctxt1, p_str))
            self.assertEqual(l[p_str].foo, True)
            self.assertEqual(l[p_path].foo, True)
Exemplo n.º 7
0
    def test_path_with_mixed_contexts(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        path1 = Path(ctxt1, 'qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, 'qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'foo', 'qux'))

        path1 = Path(ctxt1, '../bar/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '../bar/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'bar', 'qux'))

        path1 = Path(ctxt1, '/qux/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '/qux/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'qux', 'qux'))

        path1 = Path(ctxt1, '!qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '!qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        path1 = Path(ctxt1, '!../bar/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '!../bar/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'bar', 'qux'))

        path1 = Path(ctxt1, '!/qux/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))
Exemplo n.º 8
0
    def test_absolute_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))

        path = AbsolutePath(ctxt, '%/qux')
        self.assertEqual(path, '%/qux')
        self.assertEqual(path.full_path, '/qux')

        with self.assertRaises(ValueError):
            path = AbsolutePath(ctxt, '%qux')
Exemplo n.º 9
0
    def test_absolute_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))

        path = AbsolutePath(ctxt, '%/qux')
        self.assertEqual(path, '%/qux')
        self.assertEqual(path.full_path, '/qux')

        with self.assertRaises(ValueError):
            path = AbsolutePath(ctxt, '%qux')
Exemplo n.º 10
0
    def test_path_with_mixed_contexts(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))

        path1 = Path(ctxt1, "qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, "foo", "qux"))

        path1 = Path(ctxt1, "../bar/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "../bar/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, "bar", "qux"))

        path1 = Path(ctxt1, "/qux/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "/qux/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, "qux", "qux"))

        path1 = Path(ctxt1, "!qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "!qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "foo", "qux"))

        path1 = Path(ctxt1, "!../bar/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "!../bar/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "bar", "qux"))

        path1 = Path(ctxt1, "!/qux/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))
Exemplo n.º 11
0
    def test_absolute_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))

        path = AbsolutePath(ctxt, "%/qux")
        self.assertEqual(path, "%/qux")
        self.assertEqual(path.full_path, "/qux")

        with self.assertRaises(ValueError):
            path = AbsolutePath(ctxt, "%qux")
Exemplo n.º 12
0
    def test_path_with_mixed_contexts(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        path1 = Path(ctxt1, 'qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, 'qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'foo', 'qux'))

        path1 = Path(ctxt1, '../bar/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '../bar/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'bar', 'qux'))

        path1 = Path(ctxt1, '/qux/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '/qux/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'qux', 'qux'))

        path1 = Path(ctxt1, '!qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '!qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        path1 = Path(ctxt1, '!../bar/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '!../bar/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'bar', 'qux'))

        path1 = Path(ctxt1, '!/qux/qux')
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))
Exemplo n.º 13
0
    def test_absolute_path(self):
        config = self.config
        ctxt = Context(config=config)
        ctxt.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))

        path = AbsolutePath(ctxt, "%/qux")
        self.assertEqual(path, "%/qux")
        self.assertEqual(path.full_path, "/qux")

        with self.assertRaises(ValueError):
            path = AbsolutePath(ctxt, "%qux")
Exemplo n.º 14
0
    def test_path_with_mixed_contexts(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))

        path1 = Path(ctxt1, "qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))

        path1 = Path(ctxt1, "../bar/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "../bar/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "bar", "qux"))

        path1 = Path(ctxt1, "/qux/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "/qux/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))

        path1 = Path(ctxt1, "!qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "!qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "foo", "qux"))

        path1 = Path(ctxt1, "!../bar/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "!../bar/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "bar", "qux"))

        path1 = Path(ctxt1, "!/qux/qux")
        path2 = Path(ctxt2, path1)
        self.assertEqual(path2, path1)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.context, ctxt1)
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))
Exemplo n.º 15
0
    def test_path_typed_hierarchy_list(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        paths = [
            '!../bar/qux',
            '!/qux/qux',
            '!qux',
            '../bar/qux',
            '/qux/qux',
            'qux',
        ]

        MyList = ContextDerivedTypedHierarchicalStringList(Path)
        l = MyList(ctxt1)
        l += paths
        l.subdir += paths

        for _, files in l.walk():
            for p_str, p_path in zip(paths, files):
                self.assertEqual(p_str, p_path)
                self.assertEqual(p_path, Path(ctxt1, p_str))
                self.assertEqual(p_path.join('foo'),
                                 Path(ctxt1, mozpath.join(p_str, 'foo')))

        l2 = MyList(ctxt2)
        l2 += paths
        l2.subdir += paths

        for _, files in l2.walk():
            for p_str, p_path in zip(paths, files):
                self.assertEqual(p_str, p_path)
                self.assertEqual(p_path, Path(ctxt2, p_str))

        # Assigning with Paths from another context doesn't rebase them
        l2 = MyList(ctxt2)
        l2 += l

        for _, files in l2.walk():
            for p_str, p_path in zip(paths, files):
                self.assertEqual(p_str, p_path)
                self.assertEqual(p_path, Path(ctxt1, p_str))
Exemplo n.º 16
0
    def test_path_typed_hierarchy_list(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        paths = [
            '!../bar/qux',
            '!/qux/qux',
            '!qux',
            '../bar/qux',
            '/qux/qux',
            'qux',
        ]

        MyList = ContextDerivedTypedHierarchicalStringList(Path)
        l = MyList(ctxt1)
        l += paths
        l.subdir += paths

        for _, files in l.walk():
            for p_str, p_path in zip(paths, files):
                self.assertEqual(p_str, p_path)
                self.assertEqual(p_path, Path(ctxt1, p_str))
                self.assertEqual(p_path.join('foo'),
                                 Path(ctxt1, mozpath.join(p_str, 'foo')))

        l2 = MyList(ctxt2)
        l2 += paths
        l2.subdir += paths

        for _, files in l2.walk():
            for p_str, p_path in zip(paths, files):
                self.assertEqual(p_str, p_path)
                self.assertEqual(p_path, Path(ctxt2, p_str))

        # Assigning with Paths from another context doesn't rebase them
        l2 = MyList(ctxt2)
        l2 += l

        for _, files in l2.walk():
            for p_str, p_path in zip(paths, files):
                self.assertEqual(p_str, p_path)
                self.assertEqual(p_path, Path(ctxt1, p_str))
Exemplo n.º 17
0
    def test_context_dirs(self):
        class Config(object): pass
        config = Config()
        config.topsrcdir = mozpath.abspath(os.curdir)
        config.topobjdir = mozpath.abspath('obj')
        test = Context(config=config)
        foo = mozpath.abspath('foo')
        test.push_source(foo)

        self.assertEqual(test.srcdir, config.topsrcdir)
        self.assertEqual(test.relsrcdir, '')
        self.assertEqual(test.objdir, config.topobjdir)
        self.assertEqual(test.relobjdir, '')

        foobar = os.path.abspath('foo/bar')
        test.push_source(foobar)
        self.assertEqual(test.srcdir, mozpath.join(config.topsrcdir, 'foo'))
        self.assertEqual(test.relsrcdir, 'foo')
        self.assertEqual(test.objdir, config.topobjdir)
        self.assertEqual(test.relobjdir, '')
Exemplo n.º 18
0
    def test_dirs(self):
        class Config(object): pass
        config = Config()
        config.topsrcdir = mozpath.abspath(os.curdir)
        config.topobjdir = mozpath.abspath('obj')
        test = Context(config=config)
        foo = mozpath.abspath('foo')
        test.push_source(foo)

        self.assertEqual(test.srcdir, config.topsrcdir)
        self.assertEqual(test.relsrcdir, '')
        self.assertEqual(test.objdir, config.topobjdir)
        self.assertEqual(test.relobjdir, '')

        foobar = os.path.abspath('foo/bar')
        test.push_source(foobar)
        self.assertEqual(test.srcdir, mozpath.join(config.topsrcdir, 'foo'))
        self.assertEqual(test.relsrcdir, 'foo')
        self.assertEqual(test.objdir, config.topobjdir)
        self.assertEqual(test.relobjdir, '')
Exemplo n.º 19
0
    def test_path(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))

        path1 = Path(ctxt1, "qux")
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, "qux")
        self.assertEqual(path1.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))

        path2 = Path(ctxt2, "../foo/qux")
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, "../foo/qux")
        self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "foo", "qux"))

        self.assertEqual(path1, path2)

        self.assertEqual(path1.join("../../bar/qux").full_path, mozpath.join(config.topsrcdir, "bar", "qux"))

        path1 = Path(ctxt1, "/qux/qux")
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, "/qux/qux")
        self.assertEqual(path1.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))

        path2 = Path(ctxt2, "/qux/qux")
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, "/qux/qux")
        self.assertEqual(path2.full_path, mozpath.join(config.topsrcdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, "!qux")
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!qux")
        self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "foo", "qux"))

        path2 = Path(ctxt2, "!../foo/qux")
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!../foo/qux")
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "foo", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, "!/qux/qux")
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!/qux/qux")
        self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        path2 = Path(ctxt2, "!/qux/qux")
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!/qux/qux")
        self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        path2 = Path(ctxt2, path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!/qux/qux")
        self.assertEqual(path1.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path2 = Path(path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.full_path, mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)
Exemplo n.º 20
0
    def test_path(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        path1 = Path(ctxt1, 'qux')
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, 'qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topsrcdir, 'foo', 'qux'))

        path2 = Path(ctxt2, '../foo/qux')
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, '../foo/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'foo', 'qux'))

        self.assertEqual(path1, path2)

        self.assertEqual(path1.join('../../bar/qux').full_path,
                         mozpath.join(config.topsrcdir, 'bar', 'qux'))

        path1 = Path(ctxt1, '/qux/qux')
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, '/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topsrcdir, 'qux', 'qux'))

        path2 = Path(ctxt2, '/qux/qux')
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, '/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, '!qux')
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        path2 = Path(ctxt2, '!../foo/qux')
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!../foo/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, '!/qux/qux')
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        path2 = Path(ctxt2, '!/qux/qux')
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        path2 = Path(ctxt2, path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path2 = Path(path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)
Exemplo n.º 21
0
    def test_context_paths(self):
        test = Context()

        # Newly created context has no paths.
        self.assertIsNone(test.main_path)
        self.assertIsNone(test.current_path)
        self.assertEqual(test.all_paths, set())
        self.assertEqual(test.source_stack, [])

        foo = os.path.abspath("foo")
        test.add_source(foo)

        # Adding the first source makes it the main and current path.
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([foo]))
        self.assertEqual(test.source_stack, [foo])

        bar = os.path.abspath("bar")
        test.add_source(bar)

        # Adding the second source makes leaves main and current paths alone.
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([bar, foo]))
        self.assertEqual(test.source_stack, [foo])

        qux = os.path.abspath("qux")
        test.push_source(qux)

        # Pushing a source makes it the current path
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, qux)
        self.assertEqual(test.all_paths, set([bar, foo, qux]))
        self.assertEqual(test.source_stack, [foo, qux])

        hoge = os.path.abspath("hoge")
        test.push_source(hoge)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, hoge)
        self.assertEqual(test.all_paths, set([bar, foo, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux, hoge])

        fuga = os.path.abspath("fuga")

        # Adding a source after pushing doesn't change the source stack
        test.add_source(fuga)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, hoge)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux, hoge])

        # Adding a source twice doesn't change anything
        test.add_source(qux)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, hoge)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux, hoge])

        last = test.pop_source()

        # Popping a source returns the last pushed one, not the last added one.
        self.assertEqual(last, hoge)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, qux)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux])

        last = test.pop_source()
        self.assertEqual(last, qux)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo])

        # Popping the main path is allowed.
        last = test.pop_source()
        self.assertEqual(last, foo)
        self.assertEqual(test.main_path, foo)
        self.assertIsNone(test.current_path)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [])

        # Popping past the main path asserts.
        with self.assertRaises(AssertionError):
            test.pop_source()

        # Pushing after the main path was popped asserts.
        with self.assertRaises(AssertionError):
            test.push_source(foo)

        test = Context()
        test.push_source(foo)
        test.push_source(bar)

        # Pushing the same file twice is allowed.
        test.push_source(bar)
        test.push_source(foo)
        self.assertEqual(last, foo)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([bar, foo]))
        self.assertEqual(test.source_stack, [foo, bar, bar, foo])
Exemplo n.º 22
0
    def test_path(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, 'foo', 'moz.build'))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, 'bar', 'moz.build'))

        path1 = Path(ctxt1, 'qux')
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, 'qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topsrcdir, 'foo', 'qux'))

        path2 = Path(ctxt2, '../foo/qux')
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, '../foo/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'foo', 'qux'))

        self.assertEqual(path1, path2)

        self.assertEqual(path1.join('../../bar/qux').full_path,
                         mozpath.join(config.topsrcdir, 'bar', 'qux'))

        path1 = Path(ctxt1, '/qux/qux')
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, '/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topsrcdir, 'qux', 'qux'))

        path2 = Path(ctxt2, '/qux/qux')
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, '/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, '!qux')
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        path2 = Path(ctxt2, '!../foo/qux')
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!../foo/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'foo', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, '!/qux/qux')
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        path2 = Path(ctxt2, '!/qux/qux')
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        path2 = Path(ctxt2, path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path1 = Path(path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, '!/qux/qux')
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)

        path2 = Path(path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, '!/qux/qux')
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, 'qux', 'qux'))

        self.assertEqual(path1, path2)
Exemplo n.º 23
0
    def test_context_paths(self):
        test = Context()

        # Newly created context has no paths.
        self.assertIsNone(test.main_path)
        self.assertIsNone(test.current_path)
        self.assertEqual(test.all_paths, set())
        self.assertEqual(test.source_stack, [])

        foo = os.path.abspath('foo')
        test.add_source(foo)

        # Adding the first source makes it the main and current path.
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([foo]))
        self.assertEqual(test.source_stack, [foo])

        bar = os.path.abspath('bar')
        test.add_source(bar)

        # Adding the second source makes leaves main and current paths alone.
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([bar, foo]))
        self.assertEqual(test.source_stack, [foo])

        qux = os.path.abspath('qux')
        test.push_source(qux)

        # Pushing a source makes it the current path
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, qux)
        self.assertEqual(test.all_paths, set([bar, foo, qux]))
        self.assertEqual(test.source_stack, [foo, qux])

        hoge = os.path.abspath('hoge')
        test.push_source(hoge)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, hoge)
        self.assertEqual(test.all_paths, set([bar, foo, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux, hoge])

        fuga = os.path.abspath('fuga')

        # Adding a source after pushing doesn't change the source stack
        test.add_source(fuga)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, hoge)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux, hoge])

        # Adding a source twice doesn't change anything
        test.add_source(qux)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, hoge)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux, hoge])

        last = test.pop_source()

        # Popping a source returns the last pushed one, not the last added one.
        self.assertEqual(last, hoge)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, qux)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo, qux])

        last = test.pop_source()
        self.assertEqual(last, qux)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [foo])

        # Popping the main path is allowed.
        last = test.pop_source()
        self.assertEqual(last, foo)
        self.assertEqual(test.main_path, foo)
        self.assertIsNone(test.current_path)
        self.assertEqual(test.all_paths, set([bar, foo, fuga, hoge, qux]))
        self.assertEqual(test.source_stack, [])

        # Popping past the main path asserts.
        with self.assertRaises(AssertionError):
            test.pop_source()

        # Pushing after the main path was popped asserts.
        with self.assertRaises(AssertionError):
            test.push_source(foo)

        test = Context()
        test.push_source(foo)
        test.push_source(bar)

        # Pushing the same file twice is allowed.
        test.push_source(bar)
        test.push_source(foo)
        self.assertEqual(last, foo)
        self.assertEqual(test.main_path, foo)
        self.assertEqual(test.current_path, foo)
        self.assertEqual(test.all_paths, set([bar, foo]))
        self.assertEqual(test.source_stack, [foo, bar, bar, foo])
Exemplo n.º 24
0
    def _consume_jar_manifest(self, obj):
        # Ideally, this would all be handled somehow in the emitter, but
        # this would require all the magic surrounding l10n and addons in
        # the recursive make backend to die, which is not going to happen
        # any time soon enough.
        # Notably missing:
        # - DEFINES from config/config.mk
        # - L10n support
        # - The equivalent of -e when USE_EXTENSION_MANIFEST is set in
        #   moz.build, but it doesn't matter in dist/bin.
        pp = Preprocessor()
        if obj.defines:
            pp.context.update(obj.defines.defines)
        pp.context.update(self.environment.defines)
        pp.context.update(
            AB_CD='en-US',
            BUILD_FASTER=1,
        )
        pp.out = JarManifestParser()
        try:
            pp.do_include(obj.path.full_path)
        except DeprecatedJarManifest as e:
            raise DeprecatedJarManifest('Parsing error while processing %s: %s'
                                        % (obj.path.full_path, e.message))
        self.backend_input_files |= pp.includes

        for jarinfo in pp.out:
            jar_context = Context(
                allowed_variables=VARIABLES, config=obj._context.config)
            jar_context.push_source(obj._context.main_path)
            jar_context.push_source(obj.path.full_path)

            install_target = obj.install_target
            if jarinfo.base:
                install_target = mozpath.normpath(
                    mozpath.join(install_target, jarinfo.base))
            jar_context['FINAL_TARGET'] = install_target
            if obj.defines:
                jar_context['DEFINES'] = obj.defines.defines
            files = jar_context['FINAL_TARGET_FILES']
            files_pp = jar_context['FINAL_TARGET_PP_FILES']

            for e in jarinfo.entries:
                if e.is_locale:
                    if jarinfo.relativesrcdir:
                        src = '/%s' % jarinfo.relativesrcdir
                    else:
                        src = ''
                    src = mozpath.join(src, 'en-US', e.source)
                else:
                    src = e.source

                src = Path(jar_context, src)

                if '*' not in e.source and not os.path.exists(src.full_path):
                    if e.is_locale:
                        raise Exception(
                            '%s: Cannot find %s' % (obj.path, e.source))
                    if e.source.startswith('/'):
                        src = Path(jar_context, '!' + e.source)
                    else:
                        # This actually gets awkward if the jar.mn is not
                        # in the same directory as the moz.build declaring
                        # it, but it's how it works in the recursive make,
                        # not that anything relies on that, but it's simpler.
                        src = Path(obj._context, '!' + e.source)

                output_basename = mozpath.basename(e.output)
                if output_basename != src.target_basename:
                    src = RenamedSourcePath(jar_context,
                                            (src, output_basename))
                path = mozpath.dirname(mozpath.join(jarinfo.name, e.output))

                if e.preprocess:
                    if '*' in e.source:
                        raise Exception('%s: Wildcards are not supported with '
                                        'preprocessing' % obj.path)
                    files_pp[path] += [src]
                else:
                    files[path] += [src]

            if files:
                self.consume_object(FinalTargetFiles(jar_context, files))
            if files_pp:
                self.consume_object(
                    FinalTargetPreprocessedFiles(jar_context, files_pp))

            for m in jarinfo.chrome_manifests:
                entry = parse_manifest_line(
                    mozpath.dirname(jarinfo.name),
                    m.replace('%', mozpath.basename(jarinfo.name) + '/'))
                self.consume_object(ChromeManifestEntry(
                    jar_context, '%s.manifest' % jarinfo.name, entry))
Exemplo n.º 25
0
    def _consume_jar_manifest(self, obj):
        # Ideally, this would all be handled somehow in the emitter, but
        # this would require all the magic surrounding l10n and addons in
        # the recursive make backend to die, which is not going to happen
        # any time soon enough.
        # Notably missing:
        # - DEFINES from config/config.mk
        # - L10n support
        # - The equivalent of -e when USE_EXTENSION_MANIFEST is set in
        #   moz.build, but it doesn't matter in dist/bin.
        pp = Preprocessor()
        if obj.defines:
            pp.context.update(obj.defines.defines)
        pp.context.update(self.environment.defines)
        pp.context.update(
            AB_CD='en-US',
            BUILD_FASTER=1,
        )
        pp.out = JarManifestParser()
        try:
            pp.do_include(obj.path.full_path)
        except DeprecatedJarManifest as e:
            raise DeprecatedJarManifest(
                'Parsing error while processing %s: %s' %
                (obj.path.full_path, e.message))
        self.backend_input_files |= pp.includes

        for jarinfo in pp.out:
            jar_context = Context(allowed_variables=VARIABLES,
                                  config=obj._context.config)
            jar_context.push_source(obj._context.main_path)
            jar_context.push_source(obj.path.full_path)

            install_target = obj.install_target
            if jarinfo.base:
                install_target = mozpath.normpath(
                    mozpath.join(install_target, jarinfo.base))
            jar_context['FINAL_TARGET'] = install_target
            if obj.defines:
                jar_context['DEFINES'] = obj.defines.defines
            files = jar_context['FINAL_TARGET_FILES']
            files_pp = jar_context['FINAL_TARGET_PP_FILES']

            for e in jarinfo.entries:
                if e.is_locale:
                    if jarinfo.relativesrcdir:
                        src = '/%s' % jarinfo.relativesrcdir
                    else:
                        src = ''
                    src = mozpath.join(src, 'en-US', e.source)
                else:
                    src = e.source

                src = Path(jar_context, src)

                if '*' not in e.source and not os.path.exists(src.full_path):
                    if e.is_locale:
                        raise Exception('%s: Cannot find %s' %
                                        (obj.path, e.source))
                    if e.source.startswith('/'):
                        src = Path(jar_context, '!' + e.source)
                    else:
                        # This actually gets awkward if the jar.mn is not
                        # in the same directory as the moz.build declaring
                        # it, but it's how it works in the recursive make,
                        # not that anything relies on that, but it's simpler.
                        src = Path(obj._context, '!' + e.source)

                output_basename = mozpath.basename(e.output)
                if output_basename != src.target_basename:
                    src = RenamedSourcePath(jar_context,
                                            (src, output_basename))
                path = mozpath.dirname(mozpath.join(jarinfo.name, e.output))

                if e.preprocess:
                    if '*' in e.source:
                        raise Exception('%s: Wildcards are not supported with '
                                        'preprocessing' % obj.path)
                    files_pp[path] += [src]
                else:
                    files[path] += [src]

            if files:
                self.consume_object(FinalTargetFiles(jar_context, files))
            if files_pp:
                self.consume_object(
                    FinalTargetPreprocessedFiles(jar_context, files_pp))

            for m in jarinfo.chrome_manifests:
                entry = parse_manifest_line(
                    mozpath.dirname(jarinfo.name),
                    m.replace('%',
                              mozpath.basename(jarinfo.name) + '/'))
                self.consume_object(
                    ChromeManifestEntry(jar_context,
                                        '%s.manifest' % jarinfo.name, entry))
Exemplo n.º 26
0
    def test_path(self):
        config = self.config
        ctxt1 = Context(config=config)
        ctxt1.push_source(mozpath.join(config.topsrcdir, "foo", "moz.build"))
        ctxt2 = Context(config=config)
        ctxt2.push_source(mozpath.join(config.topsrcdir, "bar", "moz.build"))

        path1 = Path(ctxt1, "qux")
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, "qux")
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topsrcdir, "foo", "qux"))

        path2 = Path(ctxt2, "../foo/qux")
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, "../foo/qux")
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, "foo", "qux"))

        self.assertEqual(path1, path2)

        self.assertEqual(
            path1.join("../../bar/qux").full_path,
            mozpath.join(config.topsrcdir, "bar", "qux"),
        )

        path1 = Path(ctxt1, "/qux/qux")
        self.assertIsInstance(path1, SourcePath)
        self.assertEqual(path1, "/qux/qux")
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topsrcdir, "qux", "qux"))

        path2 = Path(ctxt2, "/qux/qux")
        self.assertIsInstance(path2, SourcePath)
        self.assertEqual(path2, "/qux/qux")
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topsrcdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, "!qux")
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!qux")
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, "foo", "qux"))

        path2 = Path(ctxt2, "!../foo/qux")
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!../foo/qux")
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "foo", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, "!/qux/qux")
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!/qux/qux")
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        path2 = Path(ctxt2, "!/qux/qux")
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(ctxt1, path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!/qux/qux")
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        path2 = Path(ctxt2, path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path1 = Path(path1)
        self.assertIsInstance(path1, ObjDirPath)
        self.assertEqual(path1, "!/qux/qux")
        self.assertEqual(path1.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)

        path2 = Path(path2)
        self.assertIsInstance(path2, ObjDirPath)
        self.assertEqual(path2, "!/qux/qux")
        self.assertEqual(path2.full_path,
                         mozpath.join(config.topobjdir, "qux", "qux"))

        self.assertEqual(path1, path2)