Support lists in go files.
This commit is contained in:
parent
5b7cf25d14
commit
f08359c73c
1 changed files with 23 additions and 6 deletions
|
@ -1144,6 +1144,24 @@ class Cargo(BuildSystem):
|
||||||
return Cargo(os.path.join(path, "Cargo.toml"))
|
return Cargo(os.path.join(path, "Cargo.toml"))
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_go_mod(f):
|
||||||
|
line = f.readline()
|
||||||
|
while f:
|
||||||
|
parts = line.strip().split(' ')
|
||||||
|
if not parts:
|
||||||
|
continue
|
||||||
|
if len(parts) == 2 and parts[1] == '(':
|
||||||
|
line = f.readline()
|
||||||
|
while line.strip() != ')':
|
||||||
|
yield [parts[0]] + list(line.strip().split(' '))
|
||||||
|
line = f.readline()
|
||||||
|
if not line:
|
||||||
|
raise AssertionError('list of %s interrupted?' % parts[0])
|
||||||
|
else:
|
||||||
|
yield parts
|
||||||
|
line = f.readline()
|
||||||
|
|
||||||
|
|
||||||
class Golang(BuildSystem):
|
class Golang(BuildSystem):
|
||||||
"""Go builds."""
|
"""Go builds."""
|
||||||
|
|
||||||
|
@ -1171,17 +1189,16 @@ class Golang(BuildSystem):
|
||||||
go_mod_path = os.path.join(self.path, 'go.mod')
|
go_mod_path = os.path.join(self.path, 'go.mod')
|
||||||
if not os.path.exists(go_mod_path):
|
if not os.path.exists(go_mod_path):
|
||||||
with open(go_mod_path, 'r') as f:
|
with open(go_mod_path, 'r') as f:
|
||||||
for line in f:
|
for parts in _parse_go_mod(f):
|
||||||
parts = line.strip().split(' ')
|
|
||||||
if not parts:
|
|
||||||
continue
|
|
||||||
if parts[0] == 'go':
|
if parts[0] == 'go':
|
||||||
yield "build", GoRequirement(parts[1])
|
yield "build", GoRequirement(parts[1])
|
||||||
elif parts[0] == 'require':
|
elif parts[0] == 'require':
|
||||||
yield "build", GoPackageRequirement(
|
yield "build", GoPackageRequirement(
|
||||||
parts[1], parts[2] if len(parts) > 2 else None)
|
parts[1], parts[2] if len(parts) > 2 else None)
|
||||||
elif parts[0] in ('module', 'exclude', 'replace'):
|
elif parts[0] == 'exclude':
|
||||||
pass
|
pass # TODO(jelmer): Create conflicts?
|
||||||
|
elif parts[0] == 'replace':
|
||||||
|
pass # TODO(jelmer): do.. something?
|
||||||
else:
|
else:
|
||||||
logging.warning(
|
logging.warning(
|
||||||
'Unknown directive %s in go.mod',
|
'Unknown directive %s in go.mod',
|
||||||
|
|
Loading…
Add table
Reference in a new issue