diff options
author | Bruno Haible <bruno@clisp.org> | 2022-07-31 18:39:19 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2022-07-31 23:52:27 +0200 |
commit | 6bdf668e5748a511082efed773b2b127e93fcb1d (patch) | |
tree | 4096874c27798c4bb6a647899436b1aa0304a3b0 /pygnulib/GLImport.py | |
parent | 18dcc627ddeced96bc192e169bf19e1a38c53374 (diff) | |
download | gnulib-6bdf668e5748a511082efed773b2b127e93fcb1d.tar.gz |
gnulib-tool.py: Follow gnulib-tool changes, part 19.
Follow gnulib-tool changes
2015-12-09 Pavel Raiskup <praiskup@redhat.com>
gnulib-tool: allow multiple --local-dir usage
2019-02-14 Bruno Haible <bruno@clisp.org>
gnulib-tool: Improve handling of multiple --local-dir options.
* gnulib-tool (func_reconstruct_cached_dir): When the argument is
absolute, return it unmodified.
(func_compute_relative_local_gnulib_path): Renamed from
func_count_relative_local_gnulib_path. Add comment.
* gnulib-tool.py: Accept multiple --local-dir options and collect the
values into localpath.
* pygnulib/GLConfig.py: Take a localpath argument instead of a localdir
argument.
(getLocalDir, setLocalDir, resetLocalDir): Remove methods.
(getLocalPath, setLocalPath, resetLocalPath): New methods.
* pygnulib/GLFileSystem.py (CopyAction): New class.
(GLFileSystem.lookup): Consider all dirs in localpath.
(GLFileSystem.shouldLink): New method.
(GLFileAssistant): Use shouldLink.
* pygnulib/GLModuleSystem.py (GLModuleSystem.exists): Iterate over all
dirs in localpath.
(GLModuleSystem.list): Likewise.
* pygnulib/GLEmiter.py: Update.
* pygnulib/GLImport.py (GLImport.__init__): Put the argument of
gl_LOCAL_DIR into localpath, not localdir.
(GLImport.actioncmd): Consider all dirs in localpath.
(GLImport.relative_to_destdir, GLImport.relative_to_currdir): New
methods.
(GLImport.gnulib_cache): Combine all dirs in localpath. Use
self.relative_to_destdir.
* pygnulib/GLTestDir.py (GLTestDir.execute): Use shouldLink.
Diffstat (limited to 'pygnulib/GLImport.py')
-rw-r--r-- | pygnulib/GLImport.py | 87 |
1 files changed, 52 insertions, 35 deletions
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index b2691a976d..2b16ce0ea4 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -52,7 +52,6 @@ TESTS = constants.TESTS compiler = constants.compiler joinpath = constants.joinpath cleaner = constants.cleaner -relpath = constants.relativize isabs = os.path.isabs isdir = os.path.isdir isfile = os.path.isfile @@ -181,7 +180,7 @@ class GLImport(object): if tempdict['gl_LIB']: self.cache.setLibName(cleaner(tempdict['gl_LIB'])) if tempdict['gl_LOCAL_DIR']: - self.cache.setLocalDir(cleaner(tempdict['gl_LOCAL_DIR'])) + self.cache.setLocalPath(cleaner(tempdict['gl_LOCAL_DIR']).split(':')) if tempdict['gl_MODULES']: self.cache.setModules(cleaner(tempdict['gl_MODULES'].split())) if tempdict['gl_AVOID']: @@ -217,23 +216,14 @@ class GLImport(object): pattern = compiler(regex, re.S | re.M) self.cache.setFiles(pattern.findall(data)[-1].strip().split()) - # The self.config['localdir'] defaults to the cached one. Recall that the - # cached one is relative to $destdir, whereas the one we use is relative - # to . or absolute. - if not self.config['localdir']: - if self.cache['localdir']: - if isabs(self.config['destdir']): - localdir = joinpath( - self.config['destdir'], self.cache['localdir']) - else: # if not isabs(self.config['destdir']) - if isabs(self.cache['localdir']): - localdir = joinpath( - self.config['destdir'], self.cache['localdir']) - else: # if not isabs(self.cache['localdir']) - # NOTE: I NEED TO IMPLEMENT RELATIVE_CONCAT - localdir = os.path.relpath(joinpath(self.config['destdir'], - self.cache['localdir'])) - self.config.setLocalDir(localdir) + # The self.config['localpath'] defaults to the cached one. Recall that + # the cached one is relative to self.config['destdir'], whereas the one + # we use is relative to . or absolute. + if len(self.config['localpath']) == 0: + if len(self.cache['localpath']) > 0: + localpath = [ self.relative_to_currdir(localdir) + for localdir in self.cache['localpath'] ] + self.config.setLocalPath(localpath) if self.mode != MODES['import']: if self.cache['m4base'] and \ @@ -367,7 +357,7 @@ class GLImport(object): modules = self.config.getModules() avoids = self.config.getAvoids() destdir = self.config.getDestDir() - localdir = self.config.getLocalDir() + localpath = self.config.getLocalPath() auxdir = self.config.getAuxDir() sourcebase = self.config.getSourceBase() m4base = self.config.getM4Base() @@ -389,7 +379,7 @@ class GLImport(object): # Create command-line invocation comment. actioncmd = 'gnulib-tool --import' actioncmd += ' --dir=%s' % destdir - if localdir: + for localdir in localpath: actioncmd += ' --local-dir=%s' % localdir actioncmd += ' --lib=%s' % libname actioncmd += ' --source-base=%s' % sourcebase @@ -443,17 +433,49 @@ class GLImport(object): actioncmd += ' '.join(modules) return actioncmd + def relative_to_destdir(self, dir): + '''GLImport.relative_to_destdir(dir) -> str + + Convert a filename that represents dir, relative to the current directory, + to a filename relative to destdir. + GLConfig: destdir.''' + destdir = self.config['destdir'] + if dir.startswith('/'): + return dir + else: + if destdir.startswith('/'): + # XXX This doesn't look right. + return dir + else: + return constants.relativize(destdir, dir) + + def relative_to_currdir(self, dir): + '''GLImport.relative_to_currdir(dir) -> str + + The opposite of GLImport.relative_to_destdir: + Convert a filename that represents dir, relative to destdir, + to a filename relative to the current directory. + GLConfig: destdir.''' + destdir = self.config['destdir'] + if dir.startswith('/'): + return dir + else: + if destdir.startswith('/'): + # XXX This doesn't look right. + return joinpath(destdir, dir) + else: + return constants.relconcat(destdir, dir) + def gnulib_cache(self): '''GLImport.gnulib_cache() -> str Emit the contents of generated $m4base/gnulib-cache.m4 file. - GLConfig: destdir, localdir, tests, sourcebase, m4base, pobase, docbase, + GLConfig: destdir, localpath, tests, sourcebase, m4base, pobase, docbase, testsbase, conddeps, libtool, macro_prefix, podomain, vc_files.''' emit = '' moduletable = self.moduletable actioncmd = self.actioncmd() - destdir = self.config['destdir'] - localdir = self.config['localdir'] + localpath = self.config['localpath'] testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] m4base = self.config['m4base'] @@ -482,13 +504,11 @@ class GLImport(object): # Specification in the form of a command-line invocation: # %s -# Specification in the form of a few \ -gnulib-tool.m4 macro invocations:\n''' % actioncmd - if not localdir or localdir.startswith('/'): - relative_localdir = localdir - else: # if localdir or not localdir.startswith('/') - relative_localdir = constants.relativize(destdir, localdir) - emit += 'gl_LOCAL_DIR([%s])\n' % relative_localdir +# Specification in the form of a few gnulib-tool.m4 macro invocations:\n''' % actioncmd + # Store the localpath relative to destdir. + relative_localpath = [ self.relative_to_destdir(localdir) + for localdir in localpath ] + emit += 'gl_LOCAL_DIR([%s])\n' % ':'.join(relative_localpath) emit += 'gl_MODULES([\n' emit += ' %s\n' % '\n '.join(modules) emit += '])\n' @@ -532,13 +552,12 @@ gnulib-tool.m4 macro invocations:\n''' % actioncmd '''GLImport.gnulib_comp(files) -> str Emit the contents of generated $m4base/gnulib-comp.m4 file. - GLConfig: destdir, localdir, tests, sourcebase, m4base, pobase, docbase, + GLConfig: destdir, localpath, tests, sourcebase, m4base, pobase, docbase, testsbase, conddeps, libtool, macro_prefix, podomain, vc_files.''' emit = '' assistant = self.assistant moduletable = self.moduletable destdir = self.config['destdir'] - localdir = self.config['localdir'] auxdir = self.config['auxdir'] testflags = list(self.config['testflags']) sourcebase = self.config['sourcebase'] @@ -740,7 +759,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix '''Make all preparations before the execution of the code. Returns filetable and sed transformers, which change the license.''' destdir = self.config['destdir'] - localdir = self.config['localdir'] auxdir = self.config['auxdir'] modules = list(self.config['modules']) avoids = list(self.config['avoids']) @@ -963,7 +981,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix if key not in filetable: raise KeyError('filetable must contain key %s' % repr(key)) destdir = self.config['destdir'] - localdir = self.config['localdir'] auxdir = self.config['auxdir'] modules = list(self.config['modules']) avoids = list(self.config['avoids']) |