Bug 1063414 - Make DIRS relative to the file they were added from. r=gps
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 02 Oct 2014 09:14:07 +0900
changeset 221095 6986ab0f163ef2597dc2f72d4f808eeb5a598f15
parent 221094 8ed602393f8d09adecf9865ffc4c67f28ee1c63a
child 221096 729b1324a3ce5938856a8bcf79026067ee2bd5fd
push idunknown
push userunknown
push dateunknown
reviewersgps
bugs1063414
milestone35.0a1
Bug 1063414 - Make DIRS relative to the file they were added from. r=gps
b2g/app.mozbuild
b2g/dev/app.mozbuild
browser/app.mozbuild
mobile/android/app.mozbuild
python/mozbuild/mozbuild/frontend/context.py
python/mozbuild/mozbuild/test/frontend/test_context.py
python/mozbuild/mozbuild/test/frontend/test_sandbox.py
toolkit/toolkit.mozbuild
tools/update-packaging/app.mozbuild
xulrunner/app.mozbuild
--- a/b2g/app.mozbuild
+++ b/b2g/app.mozbuild
@@ -1,17 +1,17 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if not CONFIG['LIBXUL_SDK']:
     include('/toolkit/toolkit.mozbuild')
 elif CONFIG['ENABLE_TESTS']:
-    DIRS += ['testing/mochitest']
+    DIRS += ['/testing/mochitest']
 
 if CONFIG['MOZ_EXTENSIONS']:
-    DIRS += ['extensions']
+    DIRS += ['/extensions']
 
 DIRS += [
-    CONFIG['MOZ_BRANDING_DIRECTORY'],
-    'b2g',
+    '/%s' % CONFIG['MOZ_BRANDING_DIRECTORY'],
+    '/b2g',
 ]
--- a/b2g/dev/app.mozbuild
+++ b/b2g/dev/app.mozbuild
@@ -2,24 +2,24 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if not CONFIG['LIBXUL_SDK']:
     include('/toolkit/toolkit.mozbuild')
 
 if CONFIG['MOZ_EXTENSIONS']:
-    DIRS += ['extensions']
+    DIRS += ['/extensions']
 
-DIRS += [CONFIG['MOZ_BRANDING_DIRECTORY']]
+DIRS += ['/%s' % CONFIG['MOZ_BRANDING_DIRECTORY']]
 
 if CONFIG['MOZ_WEBAPP_RUNTIME']:
-    DIRS += ['webapprt']
+    DIRS += ['/webapprt']
 
 DIRS += [
-    'b2g/chrome',
-    'b2g/components',
-    'b2g/dev/app',
+    '/b2g/chrome',
+    '/b2g/components',
+    '/b2g/dev/app',
 
     # Never add dirs after browser because they apparently won't get
     # packaged properly on Mac.
-    'browser',
+    '/browser',
 ]
--- a/browser/app.mozbuild
+++ b/browser/app.mozbuild
@@ -2,19 +2,19 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if not CONFIG['LIBXUL_SDK']:
     include('/toolkit/toolkit.mozbuild')
 
 if CONFIG['MOZ_EXTENSIONS']:
-    DIRS += ['extensions']
+    DIRS += ['/extensions']
 
-DIRS += [CONFIG['MOZ_BRANDING_DIRECTORY']]
+DIRS += ['/%s' % CONFIG['MOZ_BRANDING_DIRECTORY']]
 
 if CONFIG['MOZ_WEBAPP_RUNTIME']:
-    DIRS += ['webapprt']
+    DIRS += ['/webapprt']
 
 # Never add dirs after browser because they apparently won't get
 # packaged properly on Mac.
-DIRS += ['browser']
+DIRS += ['/browser']
 
--- a/mobile/android/app.mozbuild
+++ b/mobile/android/app.mozbuild
@@ -2,20 +2,20 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if not CONFIG['LIBXUL_SDK']:
     include('/toolkit/toolkit.mozbuild')
 
 elif CONFIG['ENABLE_TESTS']:
-    DIRS += ['testing/mochitest']
+    DIRS += ['/testing/mochitest']
 
 if CONFIG['ENABLE_TESTS']:
-    DIRS += ['testing/instrumentation']
+    DIRS += ['/testing/instrumentation']
 
 if CONFIG['MOZ_EXTENSIONS']:
-    DIRS += ['extensions']
+    DIRS += ['/extensions']
 
 DIRS += [
-    CONFIG['MOZ_BRANDING_DIRECTORY'],
-    'mobile/android',
+    '/%s' % CONFIG['MOZ_BRANDING_DIRECTORY'],
+    '/mobile/android',
 ]
--- a/python/mozbuild/mozbuild/frontend/context.py
+++ b/python/mozbuild/mozbuild/frontend/context.py
@@ -135,30 +135,40 @@ class Context(KeyedDefaultDict):
         if not self.current_path:
             return []
         return self._all_paths[self._all_paths.index(self.main_path):]
 
     @memoized_property
     def objdir(self):
         return mozpath.join(self.config.topobjdir, self.relobjdir).rstrip('/')
 
-    @memoized_property
+    @memoize
+    def _srcdir(self, path):
+        return mozpath.join(self.config.topsrcdir,
+            self._relsrcdir(path)).rstrip('/')
+
+    @property
     def srcdir(self):
-        return mozpath.join(self.config.topsrcdir, self.relsrcdir).rstrip('/')
+        return self._srcdir(self.current_path or self.main_path)
+
+    @memoize
+    def _relsrcdir(self, path):
+        return mozpath.relpath(mozpath.dirname(path), self.config.topsrcdir)
+
+    @property
+    def relsrcdir(self):
+        assert self.main_path
+        return self._relsrcdir(self.current_path or self.main_path)
 
     @memoized_property
-    def relsrcdir(self):
+    def relobjdir(self):
         assert self.main_path
         return mozpath.relpath(mozpath.dirname(self.main_path),
             self.config.topsrcdir)
 
-    @memoized_property
-    def relobjdir(self):
-        return self.relsrcdir
-
     def _factory(self, key):
         """Function called when requesting a missing key."""
 
         defaults = self._allowed_variables.get(key)
         if not defaults:
             raise KeyError('global_ns', 'get_unknown', key)
 
         # If the default is specifically a lambda (or, rather, any function
@@ -285,33 +295,34 @@ class SourcePath(ContextDerivedValue, Us
     """
     def __new__(cls, context, value=None):
         if not isinstance(context, Context) and value is None:
             return unicode(context)
         return super(SourcePath, cls).__new__(cls)
 
     def __init__(self, context, value=None):
         self.context = context
+        self.srcdir = context.srcdir
         self.value = value
 
     @memoized_property
     def data(self):
         """Serializes the path for UserString."""
         if self.value.startswith('/'):
             ret = None
             # If the path starts with a '/' and is actually relative to an
             # external source dir, use that as base instead of topsrcdir.
             if self.context.config.external_source_dir:
                 ret = mozpath.join(self.context.config.external_source_dir,
                     self.value[1:])
             if not ret or not os.path.exists(ret):
                 ret = mozpath.join(self.context.config.topsrcdir,
                     self.value[1:])
         else:
-            ret = mozpath.join(self.context.srcdir, self.value)
+            ret = mozpath.join(self.srcdir, self.value)
         return mozpath.normpath(ret)
 
     def __unicode__(self):
         # UserString doesn't implement a __unicode__ function at all, so add
         # ours.
         return self.data
 
     @memoized_property
--- a/python/mozbuild/mozbuild/test/frontend/test_context.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_context.py
@@ -9,16 +9,18 @@ from mozunit import main
 
 from mozbuild.frontend.context import (
     Context,
     FUNCTIONS,
     SPECIAL_VARIABLES,
     VARIABLES,
 )
 
+from mozpack import path as mozpath
+
 
 class TestContext(unittest.TestCase):
     def test_defaults(self):
         test = Context({
             'foo': (int, int, '', None),
             'bar': (bool, bool, '', None),
             'baz': (dict, dict, '', None),
         })
@@ -195,16 +197,37 @@ class TestContext(unittest.TestCase):
         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])
 
+    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, '')
+
 
 class TestSymbols(unittest.TestCase):
     def _verify_doc(self, doc):
         # Documentation should be of the format:
         # """SUMMARY LINE
         #
         # EXTRA PARAGRAPHS
         # """
--- a/python/mozbuild/mozbuild/test/frontend/test_sandbox.py
+++ b/python/mozbuild/mozbuild/test/frontend/test_sandbox.py
@@ -263,21 +263,21 @@ class TestMozbuildSandbox(unittest.TestC
 
         self.assertIsNotNone(sle.exception.read_error)
 
     def test_include_relative_from_child_dir(self):
         # A relative path from a subdirectory should be relative from that
         # child directory.
         sandbox = self.sandbox(data_path='include-relative-from-child')
         sandbox.exec_file('child/child.build')
-        self.assertEqual(sandbox['DIRS'], [sandbox.normalize_path('child/foo')])
+        self.assertEqual(sandbox['DIRS'], [sandbox.normalize_path('foo')])
 
         sandbox = self.sandbox(data_path='include-relative-from-child')
         sandbox.exec_file('child/child2.build')
-        self.assertEqual(sandbox['DIRS'], [sandbox.normalize_path('child/foo')])
+        self.assertEqual(sandbox['DIRS'], [sandbox.normalize_path('foo')])
 
     def test_include_topsrcdir_relative(self):
         # An absolute path for include() is relative to topsrcdir.
 
         sandbox = self.sandbox(data_path='include-topsrcdir-relative')
         sandbox.exec_file('moz.build')
 
         self.assertEqual(sandbox['DIRS'], [sandbox.normalize_path('foo')])
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -2,204 +2,204 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 if CONFIG['LIBXUL_SDK']:
     error('toolkit.mozbuild is not compatible with --enable-libxul-sdk=')
 
 if CONFIG['MOZ_SANDBOX']:
-    DIRS += ['security/sandbox']
+    DIRS += ['/security/sandbox']
 
 DIRS += [
     # Depends on NSS and NSPR, and must be built after sandbox or else B2G emulator
     # builds fail.
-    'security/certverifier',
+    '/security/certverifier',
     # Depends on certverifier
-    'security/apps',
+    '/security/apps',
 ]
 
 # the signing related bits of libmar depend on nss
 if CONFIG['MOZ_UPDATER']:
-    DIRS += ['modules/libmar']
+    DIRS += ['/modules/libmar']
 
 if CONFIG['NS_TRACE_MALLOC']:
-    DIRS += ['tools/trace-malloc/lib']
+    DIRS += ['/tools/trace-malloc/lib']
 
 if CONFIG['MOZ_DMD']:
-    DIRS += ['memory/replace/dmd']
+    DIRS += ['/memory/replace/dmd']
 
 DIRS += [
-    'config/external/freetype2',
-    'xpcom',
-    'modules/libpref',
-    'intl',
-    'netwerk',
+    '/config/external/freetype2',
+    '/xpcom',
+    '/modules/libpref',
+    '/intl',
+    '/netwerk',
 ]
 
 if CONFIG['MOZ_AUTH_EXTENSION']:
-    DIRS += ['extensions/auth']
+    DIRS += ['/extensions/auth']
 
 if CONFIG['MOZ_UPDATER']:
-    DIRS += ['other-licenses/bsdiff']
+    DIRS += ['/other-licenses/bsdiff']
 
 # Gecko/Core components.
 
 DIRS += [
-    'ipc',
-    'js/ipc',
-    'hal',
-    'js/xpconnect',
-    'intl/chardet',
-    'media/libyuv',
-    'modules/libjar',
-    'storage',
+    '/ipc',
+    '/js/ipc',
+    '/hal',
+    '/js/xpconnect',
+    '/intl/chardet',
+    '/media/libyuv',
+    '/modules/libjar',
+    '/storage',
 ]
 
 if CONFIG['MOZ_PERMISSIONS']:
     DIRS += [
-        'extensions/cookie',
-        'extensions/permissions',
+        '/extensions/cookie',
+        '/extensions/permissions',
     ]
 
 DIRS += [
-    'rdf',
+    '/rdf',
 ]
 
 if CONFIG['MOZ_WEBRTC']:
     DIRS += [
-        'media/webrtc',
-        'media/mtransport/third_party',
-        'media/mtransport/build',
-        'media/mtransport/standalone',
+        '/media/webrtc',
+        '/media/mtransport/third_party',
+        '/media/mtransport/build',
+        '/media/mtransport/standalone',
     ]
 
 if CONFIG['MOZ_OMX_PLUGIN']:
     DIRS += [
-        'media/omx-plugin/lib/ics/libutils',
-        'media/omx-plugin/lib/ics/libstagefright',
-        'media/omx-plugin/lib/ics/libvideoeditorplayer',
-        'media/omx-plugin/lib/gb/libutils',
-        'media/omx-plugin/lib/gb/libstagefright',
-        'media/omx-plugin/lib/gb/libstagefright_color_conversion',
-        'media/omx-plugin/lib/gb235/libstagefright',
-        'media/omx-plugin',
-        'media/omx-plugin/gb',
-        'media/omx-plugin/gb235',
-        'media/omx-plugin/lib/hc/libstagefright',
-        'media/omx-plugin/hc',
-        'media/omx-plugin/kk',
+        '/media/omx-plugin/lib/ics/libutils',
+        '/media/omx-plugin/lib/ics/libstagefright',
+        '/media/omx-plugin/lib/ics/libvideoeditorplayer',
+        '/media/omx-plugin/lib/gb/libutils',
+        '/media/omx-plugin/lib/gb/libstagefright',
+        '/media/omx-plugin/lib/gb/libstagefright_color_conversion',
+        '/media/omx-plugin/lib/gb235/libstagefright',
+        '/media/omx-plugin',
+        '/media/omx-plugin/gb',
+        '/media/omx-plugin/gb235',
+        '/media/omx-plugin/lib/hc/libstagefright',
+        '/media/omx-plugin/hc',
+        '/media/omx-plugin/kk',
     ]
 
 if CONFIG['ENABLE_TESTS']:
-    DIRS += ['testing/specialpowers']
+    DIRS += ['/testing/specialpowers']
 
 DIRS += [
-    'testing/gtest',
-    'uriloader',
-    'caps',
-    'parser',
-    'gfx',
-    'image',
-    'dom',
-    'view',
-    'widget',
-    'content',
-    'editor',
-    'layout',
-    'docshell',
-    'embedding',
-    'xpfe/appshell'
+    '/testing/gtest',
+    '/uriloader',
+    '/caps',
+    '/parser',
+    '/gfx',
+    '/image',
+    '/dom',
+    '/view',
+    '/widget',
+    '/content',
+    '/editor',
+    '/layout',
+    '/docshell',
+    '/embedding',
+    '/xpfe/appshell'
 ]
 
 # This needs to be built after the gfx/ directory
 # to ensure all dependencies for skia (e.g. mozalloc, xpcom)
 # have been built
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
-    DIRS += ['other-licenses/skia-npapi']
+    DIRS += ['/other-licenses/skia-npapi']
 
 if CONFIG['MOZ_UNIVERSALCHARDET']:
-    DIRS += ['extensions/universalchardet']
+    DIRS += ['/extensions/universalchardet']
 
 if CONFIG['ACCESSIBILITY']:
-    DIRS += ['accessible']
+    DIRS += ['/accessible']
 
 # toolkit
 
-DIRS += ['profile']
+DIRS += ['/profile']
 
 # This must precede xpfe.
 if CONFIG['MOZ_JPROF']:
-    DIRS += ['tools/jprof']
+    DIRS += ['/tools/jprof']
 
 DIRS += [
-    'tools/profiler',
-    'xpfe/components',
+    '/tools/profiler',
+    '/xpfe/components',
 ]
 
 if CONFIG['MOZ_ENABLE_XREMOTE']:
-    DIRS += ['widget/xremoteclient']
+    DIRS += ['/widget/xremoteclient']
 
 if CONFIG['MOZ_SPELLCHECK']:
-    DIRS += ['extensions/spellcheck']
+    DIRS += ['/extensions/spellcheck']
 
 DIRS += [
-    'security/manager',
-    'toolkit',
+    '/security/manager',
+    '/toolkit',
 ]
 
 if CONFIG['MOZ_PREF_EXTENSIONS']:
-    DIRS += ['extensions/pref']
+    DIRS += ['/extensions/pref']
 
 DIRS += [
-    'services',
-    'startupcache',
-    'js/ductwork/debugger',
-    'other-licenses/snappy',
+    '/services',
+    '/startupcache',
+    '/js/ductwork/debugger',
+    '/other-licenses/snappy',
 ]
 
 if CONFIG['MOZ_GIO_COMPONENT']:
-    DIRS += ['extensions/gio']
+    DIRS += ['/extensions/gio']
 
 DIRS += [
-    'toolkit/library/StaticXULComponentsEnd',
-    'toolkit/library',
+    '/toolkit/library/StaticXULComponentsEnd',
+    '/toolkit/library',
 ]
 
 if CONFIG['MOZ_REPLACE_MALLOC']:
-    DIRS += ['memory/replace']
+    DIRS += ['/memory/replace']
 
 if CONFIG['NS_TRACE_MALLOC']:
-    DIRS += ['tools/trace-malloc']
+    DIRS += ['/tools/trace-malloc']
 
 if CONFIG['MOZ_ENABLE_GNOME_COMPONENT']:
-    DIRS += ['toolkit/system/gnome']
+    DIRS += ['/toolkit/system/gnome']
 
 # if QtNetwork is present, it will do its own network monitoring
 if not CONFIG['MOZ_ENABLE_QTNETWORK'] and CONFIG['MOZ_ENABLE_DBUS']:
-    DIRS += ['toolkit/system/dbus']
+    DIRS += ['/toolkit/system/dbus']
 
-DIRS += ['addon-sdk']
+DIRS += ['/addon-sdk']
 
 if CONFIG['ENABLE_MARIONETTE'] or CONFIG['MOZ_WIDGET_TOOLKIT'] not in ('gonk', 'android'):
-    DIRS += ['testing/marionette']
+    DIRS += ['/testing/marionette']
 
 DIRS += [
-    'tools/quitter',
-    'media/gmp-clearkey/0.1',
+    '/tools/quitter',
+    '/media/gmp-clearkey/0.1',
 ]
 
 if CONFIG['ENABLE_TESTS']:
     DIRS += [
-        'testing/mochitest',
-        'testing/xpcshell',
-        'testing/tools/screenshot',
-        'testing/profiles',
-        'testing/mozbase',
-        'testing/modules',
-        'testing/web-platform',
+        '/testing/mochitest',
+        '/testing/xpcshell',
+        '/testing/tools/screenshot',
+        '/testing/profiles',
+        '/testing/mozbase',
+        '/testing/modules',
+        '/testing/web-platform',
     ]
 
     if CONFIG['MOZ_WEBRTC'] and CONFIG['MOZ_WIDGET_TOOLKIT'] != 'gonk':
             DIRS += [
-                'media/webrtc/signaling/test',
-                'media/mtransport/test',
+                '/media/webrtc/signaling/test',
+                '/media/mtransport/test',
             ]
--- a/tools/update-packaging/app.mozbuild
+++ b/tools/update-packaging/app.mozbuild
@@ -1,10 +1,10 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DIRS += [
-    'modules/libbz2',
-    'modules/libmar',
-    'other-licenses/bsdiff',
+    '/modules/libbz2',
+    '/modules/libmar',
+    '/other-licenses/bsdiff',
 ]
--- a/xulrunner/app.mozbuild
+++ b/xulrunner/app.mozbuild
@@ -1,15 +1,15 @@
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 include('/toolkit/toolkit.mozbuild')
 
 if CONFIG['MOZ_EXTENSIONS']:
-    DIRS += ['extensions']
+    DIRS += ['/extensions']
 
 if CONFIG['OS_ARCH'] == 'WINNT' and (CONFIG['ENABLE_TESTS'] or
         CONFIG['MOZILLA_OFFICIAL']):
-    DIRS += ['embedding/tests/winEmbed']
+    DIRS += ['/embedding/tests/winEmbed']
 
-DIRS += ['xulrunner']
+DIRS += ['/xulrunner']