Skip to content

Commit ae2b4d2

Browse files
committed
Store commands as arrays.
1 parent 3741a1d commit ae2b4d2

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

mesonbuild/interpreter/interpreter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,8 +1968,8 @@ def func_vcs_tag(self, node: mparser.BaseNode, args: T.List['TYPE_var'], kwargs:
19681968
vcs = mesonlib.detect_vcs(source_dir)
19691969
if vcs:
19701970
mlog.log('Found {} repository at {}'.format(vcs['name'], vcs['wc_dir']))
1971-
vcs_cmd = vcs['get_rev'].split()
1972-
regex_selector = vcs['rev_regex']
1971+
vcs_cmd = vcs.get_rev
1972+
regex_selector = vcs.rev_regex
19731973
else:
19741974
vcs_cmd = [' '] # executing this cmd will fail in vcstagger.py and force to use the fallback string
19751975
# vcstagger.py parameters: infile, outfile, fallback, source_dir, replace_string, regex_selector, command...

mesonbuild/utils/universal.py

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
if T.TYPE_CHECKING:
3232
from typing_extensions import Literal, Protocol
33+
from typing import TypedDict
3334

3435
from .._typing import ImmutableListProtocol
3536
from ..build import ConfigurationData
@@ -756,40 +757,61 @@ def windows_detect_native_arch() -> str:
756757
raise EnvironmentException('Unable to detect native OS architecture')
757758
return arch
758759

759-
def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[T.Dict[str, str]]:
760+
class VcsData:
761+
def __init__(self, *,
762+
name:str = '',
763+
cmd:str = '',
764+
repo_dir:str = '',
765+
get_rev: 'T.List[str]' = [''],
766+
rev_regex:str = '',
767+
dep:str = '',
768+
wc_dir:'T.Optional[str]' = None):
769+
self.name:str = name
770+
self.cmd:str = cmd
771+
self.repo_dir:str = repo_dir
772+
self.get_rev: 'T.List[str]' = get_rev
773+
self.rev_regex: str = rev_regex
774+
self.dep: str = dep
775+
self.wc_dir: 'T.Optional[str]' = wc_dir
776+
777+
def detect_vcs(source_dir: T.Union[str, Path]) -> 'VcsData':
760778
vcs_systems = [
761-
{
762-
'name': 'git',
763-
'cmd': 'git',
764-
'repo_dir': '.git',
765-
'get_rev': 'git describe --dirty=+ --always',
766-
'rev_regex': '(.*)',
767-
'dep': '.git/logs/HEAD'
768-
},
769-
{
770-
'name': 'mercurial',
771-
'cmd': 'hg',
772-
'repo_dir': '.hg',
773-
'get_rev': 'hg id -i',
774-
'rev_regex': '(.*)',
775-
'dep': '.hg/dirstate'
776-
},
777-
{
778-
'name': 'subversion',
779-
'cmd': 'svn',
780-
'repo_dir': '.svn',
781-
'get_rev': 'svn info',
782-
'rev_regex': 'Revision: (.*)',
783-
'dep': '.svn/wc.db'
784-
},
785-
{
786-
'name': 'bazaar',
787-
'cmd': 'bzr',
788-
'repo_dir': '.bzr',
789-
'get_rev': 'bzr revno',
790-
'rev_regex': '(.*)',
791-
'dep': '.bzr'
792-
},
779+
VcsData(
780+
name = 'git',
781+
cmd =' git',
782+
repo_dir = '.git',
783+
get_rev = ['git', 'describe', '--dirty=+', '--always'],
784+
rev_regex = '(.*)',
785+
dep = '.git/logs/HEAD',
786+
wc_dir = None,
787+
),
788+
VcsData(
789+
name = 'mercurial',
790+
cmd = 'hg',
791+
repo_dir = '.hg',
792+
get_rev = ['hg', 'id', '-i'],
793+
rev_regex = '(.*)',
794+
dep= '.hg/dirstate',
795+
wc_dir=None,
796+
),
797+
VcsData(
798+
name = 'subversion',
799+
cmd = 'svn',
800+
repo_dir = '.svn',
801+
get_rev = ['svn', 'info'],
802+
rev_regex = 'Revision: (.*)',
803+
dep = '.svn/wc.db',
804+
wc_dir = None,
805+
),
806+
VcsData(
807+
name = 'bazaar',
808+
cmd = 'bzr',
809+
repo_dir = '.bzr',
810+
get_rev = ['bzr', 'revno'],
811+
rev_regex = '(.*)',
812+
dep = '.bzr',
813+
wc_dir = None,
814+
),
793815
]
794816
if isinstance(source_dir, str):
795817
source_dir = Path(source_dir)
@@ -800,8 +822,10 @@ def detect_vcs(source_dir: T.Union[str, Path]) -> T.Optional[T.Dict[str, str]]:
800822
parent_paths_and_self.appendleft(source_dir)
801823
for curdir in parent_paths_and_self:
802824
for vcs in vcs_systems:
803-
if Path.is_dir(curdir.joinpath(vcs['repo_dir'])) and shutil.which(vcs['cmd']):
804-
vcs['wc_dir'] = str(curdir)
825+
repodir = vcs.repo_dir
826+
cmd = vcs.cmd
827+
if curdir.joinpath(repodir).is_dir() and shutil.which(cmd):
828+
vcs.wc_dir = str(curdir)
805829
return vcs
806830
return None
807831

0 commit comments

Comments
 (0)