diff options
| author | Jussi Pakkanen <jpakkane@gmail.com> | 2025-01-06 22:22:01 +0200 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2025-01-08 01:47:13 +0200 |
| commit | dfe5cbb3e432bb632731f853df05e2023ab233d6 (patch) | |
| tree | cf6f4b3f22cbe5ea9ed519c528ede56f8c6535bb /mesonbuild | |
| parent | 5b3914629884c4e3977ed4c97323b5c5b4ce9563 (diff) | |
| download | meson-dfe5cbb3e432bb632731f853df05e2023ab233d6.tar.gz | |
Store commands as arrays.
Diffstat (limited to 'mesonbuild')
| -rw-r--r-- | mesonbuild/interpreter/interpreter.py | 6 | ||||
| -rw-r--r-- | mesonbuild/utils/universal.py | 83 |
2 files changed, 51 insertions, 38 deletions
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index d717485e8..4933ba65a 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1967,9 +1967,9 @@ class Interpreter(InterpreterBase, HoldableObject): else: vcs = mesonlib.detect_vcs(source_dir) if vcs: - mlog.log('Found {} repository at {}'.format(vcs['name'], vcs['wc_dir'])) - vcs_cmd = vcs['get_rev'].split() - regex_selector = vcs['rev_regex'] + mlog.log('Found {} repository at {}'.format(vcs.name, vcs.wc_dir)) + vcs_cmd = vcs.get_rev + regex_selector = vcs.rev_regex else: vcs_cmd = [' '] # executing this cmd will fail in vcstagger.py and force to use the fallback string # vcstagger.py parameters: infile, outfile, fallback, source_dir, replace_string, regex_selector, command... diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index dc327373a..eede9fd2d 100644 --- a/mesonbuild/utils/universal.py +++ b/mesonbuild/utils/universal.py @@ -24,6 +24,7 @@ import textwrap import pickle import errno import json +import dataclasses from mesonbuild import mlog from .core import MesonException, HoldableObject @@ -756,40 +757,50 @@ def windows_detect_native_arch() -> str: raise EnvironmentException('Unable to detect native OS architecture') return arch -def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[T.Dict[str, str]]: +@dataclasses.dataclass +class VcsData: + name: str + cmd: str + repo_dir: str + get_rev: T.List[str] + rev_regex: str + dep: str + wc_dir: T.Optional[str] = None + +def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[VcsData]: vcs_systems = [ - { - 'name': 'git', - 'cmd': 'git', - 'repo_dir': '.git', - 'get_rev': 'git describe --dirty=+ --always', - 'rev_regex': '(.*)', - 'dep': '.git/logs/HEAD' - }, - { - 'name': 'mercurial', - 'cmd': 'hg', - 'repo_dir': '.hg', - 'get_rev': 'hg id -i', - 'rev_regex': '(.*)', - 'dep': '.hg/dirstate' - }, - { - 'name': 'subversion', - 'cmd': 'svn', - 'repo_dir': '.svn', - 'get_rev': 'svn info', - 'rev_regex': 'Revision: (.*)', - 'dep': '.svn/wc.db' - }, - { - 'name': 'bazaar', - 'cmd': 'bzr', - 'repo_dir': '.bzr', - 'get_rev': 'bzr revno', - 'rev_regex': '(.*)', - 'dep': '.bzr' - }, + VcsData( + name = 'git', + cmd = 'git', + repo_dir = '.git', + get_rev = ['git', 'describe', '--dirty=+', '--always'], + rev_regex = '(.*)', + dep = '.git/logs/HEAD', + ), + VcsData( + name = 'mercurial', + cmd = 'hg', + repo_dir = '.hg', + get_rev = ['hg', 'id', '-i'], + rev_regex = '(.*)', + dep= '.hg/dirstate', + ), + VcsData( + name = 'subversion', + cmd = 'svn', + repo_dir = '.svn', + get_rev = ['svn', 'info'], + rev_regex = 'Revision: (.*)', + dep = '.svn/wc.db', + ), + VcsData( + name = 'bazaar', + cmd = 'bzr', + repo_dir = '.bzr', + get_rev = ['bzr', 'revno'], + rev_regex = '(.*)', + dep = '.bzr', + ), ] if isinstance(source_dir, str): source_dir = Path(source_dir) @@ -800,8 +811,10 @@ def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[T.Dict[str, str]]: parent_paths_and_self.appendleft(source_dir) for curdir in parent_paths_and_self: for vcs in vcs_systems: - if Path.is_dir(curdir.joinpath(vcs['repo_dir'])) and shutil.which(vcs['cmd']): - vcs['wc_dir'] = str(curdir) + repodir = vcs.repo_dir + cmd = vcs.cmd + if curdir.joinpath(repodir).is_dir() and shutil.which(cmd): + vcs.wc_dir = str(curdir) return vcs return None |
