Commit 6fdc4fe0 authored by Mike Hommey's avatar Mike Hommey
Browse files

Bug 1618775 - Uniformize preprocessor-inserted paths between platforms. r=froydnj

The preprocessor adds line markers in preprocessed files with line
numbers and file they came from. Bug 1528892 changed those markers
to be independent of the topobjdir and topsrcdir, by replacing them
with $OBJDIR and $SRCDIR, respectively.

This goes further, making these paths always use forward-slash, and
never backwards-slash, making the preprocessed files identical whether
the build occurred on Windows or Unix. (well, except when building
for different targets for target-specific sections)

Differential Revision: https://phabricator.services.mozilla.com/D64714

--HG--
extra : moz-landing-system : lando
parent 01879b59
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import six
import sys

from mozbuild.makeutil import Makefile
from mozpack.path import normsep

# hack around win32 mangling our line endings
# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65443
@@ -828,9 +829,9 @@ class Preprocessor:
            self.curdir = os.path.dirname(abspath)
            self.includes.add(six.ensure_text(abspath))
            if self.topobjdir and path_starts_with(abspath, self.topobjdir):
                abspath = '$OBJDIR' + abspath[len(self.topobjdir):]
                abspath = '$OBJDIR' + normsep(abspath[len(self.topobjdir):])
            elif self.topsrcdir and path_starts_with(abspath, self.topsrcdir):
                abspath = '$SRCDIR' + abspath[len(self.topsrcdir):]
                abspath = '$SRCDIR' + normsep(abspath[len(self.topsrcdir):])
            self.context['FILE'] = abspath
            self.context['DIRECTORY'] = os.path.dirname(abspath)
        self.context['LINE'] = 0
+12 −12
Original line number Diff line number Diff line
@@ -148,8 +148,8 @@ class TestBuild(unittest.TestCase):

    def validate(self, config):
        self.maxDiff = None
        test_path = os.sep.join(('$SRCDIR', 'python', 'mozbuild', 'mozbuild',
                                 'test', 'backend', 'data', 'build')) + os.sep
        test_path = mozpath.join('$SRCDIR', 'python', 'mozbuild', 'mozbuild',
                                 'test', 'backend', 'data', 'build')

        result = {
            p: f.open(mode='r').read()
@@ -171,24 +171,24 @@ class TestBuild(unittest.TestCase):
                'chrome://bar/bar.svg#hello\n',
            'bin/chrome/foo/bar.js': 'bar.js\n',
            'bin/chrome/foo/child/baz.jsm':
                '//@line 2 "%sbaz.jsm"\nbaz.jsm: FOO is foo\n' % (test_path),
                '//@line 2 "%s/baz.jsm"\nbaz.jsm: FOO is foo\n' % (test_path),
            'bin/chrome/foo/child/hoge.js':
                '//@line 2 "%sbar.js"\nbar.js: FOO is foo\n' % (test_path),
                '//@line 2 "%s/bar.js"\nbar.js: FOO is foo\n' % (test_path),
            'bin/chrome/foo/foo.css': 'foo.css: FOO is foo\n',
            'bin/chrome/foo/foo.js': 'foo.js\n',
            'bin/chrome/foo/qux.js': 'bar.js\n',
            'bin/components/bar.js':
                '//@line 2 "%sbar.js"\nbar.js: FOO is foo\n' % (test_path),
                '//@line 2 "%s/bar.js"\nbar.js: FOO is foo\n' % (test_path),
            'bin/components/components.manifest':
                'component {foo} foo.js\ncomponent {bar} bar.js\n',
            'bin/components/foo.js': 'foo.js\n',
            'bin/defaults/pref/prefs.js': 'prefs.js\n',
            'bin/foo.ini': 'foo.ini\n',
            'bin/modules/baz.jsm':
                '//@line 2 "%sbaz.jsm"\nbaz.jsm: FOO is foo\n' % (test_path),
                '//@line 2 "%s/baz.jsm"\nbaz.jsm: FOO is foo\n' % (test_path),
            'bin/modules/child/bar.jsm': 'bar.jsm\n',
            'bin/modules/child2/qux.jsm':
                '//@line 4 "%squx.jsm"\nqux.jsm: BAR is not defined\n'
                '//@line 4 "%s/qux.jsm"\nqux.jsm: BAR is not defined\n'
                % (test_path),
            'bin/modules/foo.jsm': 'foo.jsm\n',
            'bin/res/resource': 'resource\n',
@@ -207,14 +207,14 @@ class TestBuild(unittest.TestCase):
                'chrome://bar/bar.svg#hello\n',
            'bin/app/chrome/foo/bar.js': 'bar.js\n',
            'bin/app/chrome/foo/child/baz.jsm':
                '//@line 2 "%sbaz.jsm"\nbaz.jsm: FOO is bar\n' % (test_path),
                '//@line 2 "%s/baz.jsm"\nbaz.jsm: FOO is bar\n' % (test_path),
            'bin/app/chrome/foo/child/hoge.js':
                '//@line 2 "%sbar.js"\nbar.js: FOO is bar\n' % (test_path),
                '//@line 2 "%s/bar.js"\nbar.js: FOO is bar\n' % (test_path),
            'bin/app/chrome/foo/foo.css': 'foo.css: FOO is bar\n',
            'bin/app/chrome/foo/foo.js': 'foo.js\n',
            'bin/app/chrome/foo/qux.js': 'bar.js\n',
            'bin/app/components/bar.js':
                '//@line 2 "%sbar.js"\nbar.js: FOO is bar\n' % (test_path),
                '//@line 2 "%s/bar.js"\nbar.js: FOO is bar\n' % (test_path),
            'bin/app/components/components.manifest':
                'component {foo} foo.js\ncomponent {bar} bar.js\n',
            'bin/app/components/foo.js': 'foo.js\n',
@@ -222,10 +222,10 @@ class TestBuild(unittest.TestCase):
            'bin/app/foo.css': 'foo.css: FOO is bar\n',
            'bin/app/foo.ini': 'foo.ini\n',
            'bin/app/modules/baz.jsm':
                '//@line 2 "%sbaz.jsm"\nbaz.jsm: FOO is bar\n' % (test_path),
                '//@line 2 "%s/baz.jsm"\nbaz.jsm: FOO is bar\n' % (test_path),
            'bin/app/modules/child/bar.jsm': 'bar.jsm\n',
            'bin/app/modules/child2/qux.jsm':
                '//@line 2 "%squx.jsm"\nqux.jsm: BAR is defined\n'
                '//@line 2 "%s/qux.jsm"\nqux.jsm: BAR is defined\n'
                % (test_path),
            'bin/app/modules/foo.jsm': 'foo.jsm\n',
        })
+1 −1
Original line number Diff line number Diff line
@@ -629,7 +629,7 @@ class TestPreprocessor(unittest.TestCase):
                        '//@line 1 "$OBJDIR/baz.js"\n'
                        'baz\n'
                        '//@line 6 "$SRCDIR/f.js"\n'
                        'fin\n').replace('DIR/', 'DIR' + os.sep)
                        'fin\n')

        # Try with separate srcdir/objdir
        with MockedOpen(files):
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ baz@SUFFIX@


class TestPreprocessManifest(unittest.TestCase):
    MANIFEST_PATH = os.path.join('$OBJDIR', 'manifest')
    MANIFEST_PATH = mozpath.join('$OBJDIR', 'manifest')

    EXPECTED_LOG = [
        ((MANIFEST_PATH, 2), 'add', '', 'bar/*'),