mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 780414 - Fix ConfigStatus.py for the case where top_srcdir is a path relative to topobjdir. r=khuey
This commit is contained in:
parent
ea0bad742e
commit
f1a1e37b00
@ -124,7 +124,8 @@ class ConfigEnvironment(object):
|
||||
|
||||
ConfigEnvironment expects a "top_srcdir" subst to be set with the top
|
||||
source directory, in msys format on windows. It is used to derive a
|
||||
"srcdir" subst when treating config files.
|
||||
"srcdir" subst when treating config files. It can either be an absolute
|
||||
path or a path relative to the topobjdir.
|
||||
'''
|
||||
|
||||
def __init__(self, topobjdir = '.', topsrcdir = '.',
|
||||
@ -147,12 +148,22 @@ class ConfigEnvironment(object):
|
||||
return dir
|
||||
return '.'
|
||||
|
||||
def get_top_srcdir(self, file):
|
||||
'''Returns a normalized top_srcdir for the given file: if
|
||||
substs['top_srcdir'] is a relative path, it is relative to the
|
||||
topobjdir. Adjust it to be relative to the file path.'''
|
||||
top_srcdir = self.substs['top_srcdir']
|
||||
if posixpath.isabs(top_srcdir):
|
||||
return top_srcdir
|
||||
return posixpath.normpath(posixpath.join(self.get_depth(file), top_srcdir))
|
||||
|
||||
def get_file_srcdir(self, file):
|
||||
'''Returns the srcdir for the given file, where srcdir is in msys
|
||||
format on windows, thus derived from top_srcdir.
|
||||
'''
|
||||
dir = self.get_relative_srcdir(file)
|
||||
return posixpath.normpath(posixpath.join(self.substs['top_srcdir'], dir))
|
||||
top_srcdir = self.get_top_srcdir(file)
|
||||
return posixpath.normpath(posixpath.join(top_srcdir, dir))
|
||||
|
||||
def get_depth(self, file):
|
||||
'''Returns the DEPTH for the given file, that is, the path to the
|
||||
@ -181,6 +192,7 @@ class ConfigEnvironment(object):
|
||||
input = self.get_input(path)
|
||||
pp = Preprocessor()
|
||||
pp.context.update(self.substs)
|
||||
pp.context.update(top_srcdir = self.get_top_srcdir(path))
|
||||
pp.context.update(srcdir = self.get_file_srcdir(path))
|
||||
pp.context.update(relativesrcdir = self.get_relative_srcdir(path))
|
||||
pp.context.update(DEPTH = self.get_depth(path))
|
||||
|
@ -1,5 +1,5 @@
|
||||
from __future__ import with_statement
|
||||
import os
|
||||
import os, posixpath
|
||||
from StringIO import StringIO
|
||||
import unittest
|
||||
from mozunit import main, MockedOpen
|
||||
@ -11,7 +11,10 @@ class ConfigEnvironment(ConfigStatus.ConfigEnvironment):
|
||||
ConfigStatus.ConfigEnvironment.__init__(self, **args)
|
||||
# Be helpful to unit tests
|
||||
if not 'top_srcdir' in self.substs:
|
||||
self.substs['top_srcdir'] = self.topsrcdir.replace(os.sep, '/')
|
||||
if os.path.isabs(self.topsrcdir):
|
||||
self.substs['top_srcdir'] = self.topsrcdir.replace(os.sep, '/')
|
||||
else:
|
||||
self.substs['top_srcdir'] = ConfigStatus.relpath(self.topsrcdir, self.topobjdir).replace(os.sep, '/')
|
||||
|
||||
class TestFileAvoidWrite(unittest.TestCase):
|
||||
def test_file_avoid_write(self):
|
||||
@ -140,24 +143,34 @@ class TestPathsLocalBuildDir(TestPaths):
|
||||
return env
|
||||
|
||||
def test_paths_local_build_local_src(self):
|
||||
# topsrcdir = . ; topobjdir = .
|
||||
env = self.get_env('.')
|
||||
self.assertEqual(env.get_input('file'), 'file.in')
|
||||
self.assertEqual(env.get_input('dir/file'), os.path.join('dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('file'), '.')
|
||||
self.assertEqual(env.get_top_srcdir('dir/file'), '..')
|
||||
self.assertEqual(env.get_file_srcdir('file'), '.')
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), 'dir')
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../dir')
|
||||
|
||||
def test_paths_local_build_parent_src(self):
|
||||
# topsrcdir = .. ; topobjdir = .
|
||||
env = self.get_env('..')
|
||||
self.assertEqual(env.get_input('file'), os.path.join('..', 'file.in'))
|
||||
self.assertEqual(env.get_input('dir/file'), os.path.join('..', 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('file'), '..')
|
||||
self.assertEqual(env.get_top_srcdir('dir/file'), '../..')
|
||||
self.assertEqual(env.get_file_srcdir('file'), '..')
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../dir')
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../../dir')
|
||||
|
||||
def test_paths_local_build_absolute_src(self):
|
||||
# topsrcdir = /absolute ; topobjdir = /absolute
|
||||
env = self.get_env(self.absolute)
|
||||
self.assertEqual(env.get_input('file'), os.path.join(self.absolute, 'file.in'))
|
||||
self.assertEqual(env.get_input('dir/file'), os.path.join(self.absolute, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_input('%s/file' % self.dir), os.path.join(self.absolute, self.dir, 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('file'), '/absolute')
|
||||
self.assertEqual(env.get_top_srcdir('dir/file'), '/absolute')
|
||||
self.assertEqual(env.get_top_srcdir('%s/file' % dir), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '/absolute/dir')
|
||||
self.assertEqual(env.get_file_srcdir('%s/file' % dir), '/absolute/%s' % dir)
|
||||
@ -176,28 +189,40 @@ class TestPathsParentBuildDir(TestPaths):
|
||||
return env
|
||||
|
||||
def test_paths_parent_build_parent_src(self):
|
||||
# topsrcdir = .. ; topobjdir = ..
|
||||
env = self.get_env('..')
|
||||
self.assertEqual(env.get_input('../file'), os.path.join('..', 'file.in'))
|
||||
self.assertEqual(env.get_input('file'), os.path.join('..', self.dir, 'file.in'))
|
||||
self.assertEqual(env.get_input('dir/file'), os.path.join('..', self.dir, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_file_srcdir('../file'), '..')
|
||||
self.assertEqual(env.get_top_srcdir('../file'), '.')
|
||||
self.assertEqual(env.get_top_srcdir('file'), '..')
|
||||
self.assertEqual(env.get_top_srcdir('dir/file'), '../..')
|
||||
self.assertEqual(env.get_file_srcdir('../file'), '.')
|
||||
self.assertEqual(env.get_file_srcdir('file'), '../%s' % self.dir)
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../%s/dir' % self.dir)
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../../%s/dir' % self.dir)
|
||||
|
||||
def test_paths_parent_build_ancestor_src(self):
|
||||
# topsrcdir = ../.. ; topobjdir = ..
|
||||
env = self.get_env('../..')
|
||||
self.assertEqual(env.get_input('../file'), os.path.join('..', '..', 'file.in'))
|
||||
self.assertEqual(env.get_input('file'), os.path.join('..', '..', self.dir, 'file.in'))
|
||||
self.assertEqual(env.get_input('dir/file'), os.path.join('..', '..', self.dir, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_file_srcdir('../file'), '../..')
|
||||
self.assertEqual(env.get_top_srcdir('../file'), '..')
|
||||
self.assertEqual(env.get_top_srcdir('file'), '../..')
|
||||
self.assertEqual(env.get_top_srcdir('dir/file'), '../../..')
|
||||
self.assertEqual(env.get_file_srcdir('../file'), '..')
|
||||
self.assertEqual(env.get_file_srcdir('file'), '../../%s' % self.dir)
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../../%s/dir' % self.dir)
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '../../../%s/dir' % self.dir)
|
||||
|
||||
def test_paths_parent_build_absolute_src(self):
|
||||
# topsrcdir = /absolute ; topobjdir = ..
|
||||
env = self.get_env(self.absolute)
|
||||
self.assertEqual(env.get_input('../file'), os.path.join(self.absolute, 'file.in'))
|
||||
self.assertEqual(env.get_input('file'), os.path.join(self.absolute, self.dir, 'file.in'))
|
||||
self.assertEqual(env.get_input('dir/file'), os.path.join(self.absolute, self.dir, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('../file'), '/absolute')
|
||||
self.assertEqual(env.get_top_srcdir('file'), '/absolute')
|
||||
self.assertEqual(env.get_top_srcdir('dir/file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('../file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('file'), '/absolute/%s' % self.dir)
|
||||
self.assertEqual(env.get_file_srcdir('dir/file'), '/absolute/%s/dir' % self.dir)
|
||||
@ -214,30 +239,42 @@ class TestPathsRelativeBuild(TestPaths):
|
||||
return env
|
||||
|
||||
def test_paths_relative_build_relative_src(self):
|
||||
# topsrcdir = relative ; topobjdir = relative
|
||||
env = self.get_env('relative')
|
||||
self.assertEqual(env.get_input('relative/file'), os.path.join('relative', 'file.in'))
|
||||
self.assertEqual(env.get_input('relative/dir/file'), os.path.join('relative', 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), 'relative')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), 'relative/dir')
|
||||
self.assertEqual(env.get_top_srcdir('relative/file'), '.')
|
||||
self.assertEqual(env.get_top_srcdir('relative/dir/file'), '..')
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), '.')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), '../dir')
|
||||
|
||||
def test_paths_relative_build_local_src(self):
|
||||
# topsrcdir = . ; topobjdir = relative
|
||||
env = self.get_env('.')
|
||||
self.assertEqual(env.get_input('relative/file'), 'file.in')
|
||||
self.assertEqual(env.get_input('relative/dir/file'), os.path.join('dir', 'file.in'))
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), '.')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), 'dir')
|
||||
self.assertEqual(env.get_top_srcdir('relative/file'), '..')
|
||||
self.assertEqual(env.get_top_srcdir('relative/dir/file'), '../..')
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), '..')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), '../../dir')
|
||||
|
||||
def test_paths_relative_build_parent_src(self):
|
||||
# topsrcdir = .. ; topobjdir = relative
|
||||
env = self.get_env('..')
|
||||
self.assertEqual(env.get_input('relative/file'), os.path.join('..', 'file.in'))
|
||||
self.assertEqual(env.get_input('relative/dir/file'), os.path.join('..', 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), '..')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), '../dir')
|
||||
self.assertEqual(env.get_top_srcdir('relative/file'), '../..')
|
||||
self.assertEqual(env.get_top_srcdir('relative/dir/file'), '../../..')
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), '../..')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), '../../../dir')
|
||||
|
||||
def test_paths_relative_build_absolute_src(self):
|
||||
# topsrcdir = /absolute ; topobjdir = relative
|
||||
env = self.get_env(self.absolute)
|
||||
self.assertEqual(env.get_input('relative/file'), os.path.join(self.absolute, 'file.in'))
|
||||
self.assertEqual(env.get_input('relative/dir/file'), os.path.join(self.absolute, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('relative/file'), '/absolute')
|
||||
self.assertEqual(env.get_top_srcdir('relative/dir/file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('relative/file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('relative/dir/file'), '/absolute/dir')
|
||||
|
||||
@ -256,25 +293,34 @@ class TestPathsAbsoluteBuild(unittest.TestCase):
|
||||
return env
|
||||
|
||||
def test_paths_absolute_build_same_src(self):
|
||||
# topsrcdir = /absolute/build ; topobjdir = /absolute/build
|
||||
env = self.get_env(self.absolute_build)
|
||||
self.assertEqual(env.get_input('/absolute/build/file'), os.path.join(self.absolute_build, 'file.in'))
|
||||
self.assertEqual(env.get_input('/absolute/build/dir/file'), os.path.join(self.absolute_build, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('/absolute/build/file'), '/absolute/build')
|
||||
self.assertEqual(env.get_top_srcdir('/absolute/build/dir/file'), '/absolute/build')
|
||||
self.assertEqual(env.get_file_srcdir('/absolute/build/file'), '/absolute/build')
|
||||
self.assertEqual(env.get_file_srcdir('/absolute/build/dir/file'), '/absolute/build/dir')
|
||||
|
||||
def test_paths_absolute_build_ancestor_src(self):
|
||||
# topsrcdir = /absolute ; topobjdir = /absolute/build
|
||||
absolute = os.path.dirname(self.absolute_build)
|
||||
env = self.get_env(absolute)
|
||||
self.assertEqual(env.get_input('/absolute/build/file'), os.path.join(absolute, 'file.in'))
|
||||
self.assertEqual(env.get_input('/absolute/build/dir/file'), os.path.join(absolute, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('/absolute/build/file'), '/absolute')
|
||||
self.assertEqual(env.get_top_srcdir('/absolute/build/dir/file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('/absolute/build/file'), '/absolute')
|
||||
self.assertEqual(env.get_file_srcdir('/absolute/build/dir/file'), '/absolute/dir')
|
||||
|
||||
def test_paths_absolute_build_different_src(self):
|
||||
# topsrcdir = /some/path ; topobjdir = /absolute/build
|
||||
absolute = os.path.normpath('/some/path')
|
||||
env = self.get_env(absolute)
|
||||
self.assertEqual(env.get_input('/absolute/build/file'), os.path.join(absolute, 'file.in'))
|
||||
self.assertEqual(env.get_input('/absolute/build/dir/file'), os.path.join(absolute, 'dir', 'file.in'))
|
||||
self.assertEqual(env.get_top_srcdir('/absolute/build/file'), '/some/path')
|
||||
self.assertEqual(env.get_top_srcdir('/absolute/build/dir/file'), '/some/path')
|
||||
self.assertEqual(env.get_file_srcdir('/absolute/build/file'), '/some/path')
|
||||
self.assertEqual(env.get_file_srcdir('/absolute/build/dir/file'), '/some/path/dir')
|
||||
|
||||
|
@ -124,7 +124,8 @@ class ConfigEnvironment(object):
|
||||
|
||||
ConfigEnvironment expects a "top_srcdir" subst to be set with the top
|
||||
source directory, in msys format on windows. It is used to derive a
|
||||
"srcdir" subst when treating config files.
|
||||
"srcdir" subst when treating config files. It can either be an absolute
|
||||
path or a path relative to the topobjdir.
|
||||
'''
|
||||
|
||||
def __init__(self, topobjdir = '.', topsrcdir = '.',
|
||||
@ -147,12 +148,22 @@ class ConfigEnvironment(object):
|
||||
return dir
|
||||
return '.'
|
||||
|
||||
def get_top_srcdir(self, file):
|
||||
'''Returns a normalized top_srcdir for the given file: if
|
||||
substs['top_srcdir'] is a relative path, it is relative to the
|
||||
topobjdir. Adjust it to be relative to the file path.'''
|
||||
top_srcdir = self.substs['top_srcdir']
|
||||
if posixpath.isabs(top_srcdir):
|
||||
return top_srcdir
|
||||
return posixpath.normpath(posixpath.join(self.get_depth(file), top_srcdir))
|
||||
|
||||
def get_file_srcdir(self, file):
|
||||
'''Returns the srcdir for the given file, where srcdir is in msys
|
||||
format on windows, thus derived from top_srcdir.
|
||||
'''
|
||||
dir = self.get_relative_srcdir(file)
|
||||
return posixpath.normpath(posixpath.join(self.substs['top_srcdir'], dir))
|
||||
top_srcdir = self.get_top_srcdir(file)
|
||||
return posixpath.normpath(posixpath.join(top_srcdir, dir))
|
||||
|
||||
def get_depth(self, file):
|
||||
'''Returns the DEPTH for the given file, that is, the path to the
|
||||
@ -181,6 +192,7 @@ class ConfigEnvironment(object):
|
||||
input = self.get_input(path)
|
||||
pp = Preprocessor()
|
||||
pp.context.update(self.substs)
|
||||
pp.context.update(top_srcdir = self.get_top_srcdir(path))
|
||||
pp.context.update(srcdir = self.get_file_srcdir(path))
|
||||
pp.context.update(relativesrcdir = self.get_relative_srcdir(path))
|
||||
pp.context.update(DEPTH = self.get_depth(path))
|
||||
|
Loading…
Reference in New Issue
Block a user