Skip to content

Commit ac0f7c9

Browse files
committed
base, parser, fetch: add NOGIX and NOGIX__ARCH var in spec file to control use gix fetch src
1 parent 2326d95 commit ac0f7c9

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

acbs/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88
class ACBSSourceInfo(object):
9-
def __init__(self, type: str, url: str, revision=None, branch=None, depth=None) -> None:
9+
def __init__(self, type: str, url: str, revision=None, branch=None, depth=None, no_gix=False) -> None:
1010
self.type = type
1111
self.url = url
1212
self.revision: Optional[str] = revision
@@ -21,9 +21,10 @@ def __init__(self, type: str, url: str, revision=None, branch=None, depth=None)
2121
self.copy_repo: bool = False
2222
# this is a tristate: 0 - off; 1 - on (non-recursive); 2 - recursive
2323
self.submodule: int = 2
24+
self.no_gix: bool = no_gix
2425

2526
def __repr__(self) -> str:
26-
return '<ACBSSourceInfo {type}: {url}:{branch}@{revision} integrity: {checksum}>'.format(type=self.type, url=self.url, branch=self.branch, revision=self.revision, checksum=self.chksum)
27+
return '<ACBSSourceInfo {type}: {url}:{branch}@{revision} integrity: {checksum} no_gix: {no_gix}>'.format(type=self.type, url=self.url, branch=self.branch, revision=self.revision, checksum=self.chksum, no_gix=self.no_gix)
2728

2829

2930
class ACBSPackageInfo(object):

acbs/fetch.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,28 @@ def blob_processor(package: ACBSPackageInfo, index: int, source_name: str) -> No
119119
return tarball_processor_innner(package, index, source_name, False)
120120

121121

122-
def git_fetch(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]:
123-
try:
124-
# Try use gix
125-
return gix_fetch(info, source_location, name)
126-
except:
127-
# Fallback to git
128-
full_path = os.path.join(source_location, name)
129-
if not os.path.exists(full_path):
130-
subprocess.check_call(['git', 'clone', '--bare', info.url, full_path])
131-
else:
132-
logging.info('Updating repository...')
133-
subprocess.check_call(
122+
def git_fetch_fallback(info: ACBSSourceInfo, source_location: str, name: str) -> Optional[ACBSSourceInfo]:
123+
if info.no_gix:
124+
return git_fetch(info, source_location, name)
125+
else:
126+
try:
127+
# Try use gix
128+
return gix_fetch(info, source_location, name)
129+
except:
130+
# Fallback to git
131+
return git_fetch(info, source_location, name)
132+
133+
134+
def git_fetch(info, source_location, name):
135+
full_path = os.path.join(source_location, name)
136+
if not os.path.exists(full_path):
137+
subprocess.check_call(['git', 'clone', '--bare', info.url, full_path])
138+
else:
139+
logging.info('Updating repository...')
140+
subprocess.check_call(
134141
['git', 'fetch', 'origin', '+refs/heads/*:refs/heads/*', '--prune'], cwd=full_path)
135-
info.source_location = full_path
136-
return info
142+
info.source_location = full_path
143+
return info
137144

138145

139146
def gix_hack(path: str):
@@ -334,7 +341,7 @@ def fossil_processor(package: ACBSPackageInfo, index: int, source_name: str) ->
334341

335342

336343
handlers: Dict[str, pair_signature] = {
337-
'GIT': (git_fetch, git_processor),
344+
'GIT': (git_fetch_fallback, git_processor),
338345
'SVN': (svn_fetch, svn_processor),
339346
'BZR': (bzr_fetch, bzr_processor),
340347
'HG': (hg_fetch, hg_processor),

acbs/parser.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def get_defines_file_path(location: str, stage2: bool) -> str:
2323
return os.path.join(location, 'defines')
2424

2525

26-
def parse_url_schema(url: str, checksum: str) -> ACBSSourceInfo:
26+
def parse_url_schema(url: str, checksum: str, no_gix=False) -> ACBSSourceInfo:
2727
acbs_source_info = ACBSSourceInfo('none', '', '')
2828
url_split = url.split('::', 2)
2929
schema = ''
@@ -51,6 +51,7 @@ def parse_url_schema(url: str, checksum: str) -> ACBSSourceInfo:
5151
acbs_source_info.chksum = (
5252
chksum_[0], chksum_[1]) if checksum != 'SKIP' else ('none', '')
5353
acbs_source_info.url = url_plain
54+
acbs_source_info.no_gix = no_gix
5455
return acbs_source_info
5556

5657

@@ -84,12 +85,15 @@ def parse_package_url(var: Dict[str, str]) -> List[ACBSSourceInfo]:
8485
arch=arch.upper())) or var.get('SRCS')
8586
checksums = var.get('CHKSUMS__{arch}'.format(
8687
arch=arch.upper())) or var.get('CHKSUMS')
88+
no_gix = var.get('NOGIX__{arch}'.format(
89+
arch=arch.upper())) or var.get('NOGIX')
8790
if sources is None:
8891
logging.debug('Using legacy source directives')
8992
return [parse_package_url_legacy(var)]
9093
if checksums is None and not generate_mode:
9194
raise ValueError(
9295
'Missing checksums. You can use `SKIP` for VCS sources.')
96+
no_gix_bool = True if no_gix else False
9397
sources_list = sources.strip().split()
9498
checksums_list = checksums.strip().split() if checksums else [
9599
'::'] * len(sources_list)
@@ -98,7 +102,7 @@ def parse_package_url(var: Dict[str, str]) -> List[ACBSSourceInfo]:
98102
f'Sources array and checksums array must have the same length (Sources: {len(sources_list)}, Checksums: {len(checksums_list)}).'
99103
)
100104
for s, c in zip(sources_list, checksums_list):
101-
acbs_source_info.append(parse_url_schema(s, c))
105+
acbs_source_info.append(parse_url_schema(s, c, no_gix_bool))
102106
return acbs_source_info
103107

104108

0 commit comments

Comments
 (0)