giteapc: improve config selection (#3, #4)

* Reject invalid configs
* Overwrite even if giteapc-config.make is broken
* Allow ':' as a specification to remove the current config

Fixes: #3, #4
This commit is contained in:
Lephenixnoir 2024-04-07 14:26:36 +02:00
parent 3881b12ba4
commit 5f2757e11b
No known key found for this signature in database
GPG key ID: 1BBA026E13FC0495
2 changed files with 15 additions and 4 deletions

View file

@ -105,7 +105,7 @@ def pretty_repo(r):
class Spec: class Spec:
# A spec in REPOSITORY[@VERSION][:CONFIGURATION] # A spec in REPOSITORY[@VERSION][:CONFIGURATION]
RE_SPEC = re.compile(r'^([^@:]+)(?:@([^@:]+))?(?:[:]([^@:]+))?') RE_SPEC = re.compile(r'^([^@:]+)(?:@([^@:]+))?(?:([:])([^@:]*))?')
def __init__(self, string): def __init__(self, string):
m = re.match(Spec.RE_SPEC, string) m = re.match(Spec.RE_SPEC, string)
@ -114,7 +114,7 @@ class Spec:
self.name = m[1] self.name = m[1]
self.version = m[2] self.version = m[2]
self.config = m[3] self.config = m[4] or (m[3] and "")
self.repo = None self.repo = None
def resolve(self, local_only=False, remote_only=False): def resolve(self, local_only=False, remote_only=False):
@ -286,7 +286,7 @@ def build(*args, install=False, skip_configure=False):
raise Error(f"{r.fullname} has no giteapc.make") raise Error(f"{r.fullname} has no giteapc.make")
env = os.environ.copy() env = os.environ.copy()
if s.config: if s.config is not None:
env["GITEAPC_CONFIG"] = s.config env["GITEAPC_CONFIG"] = s.config
r.set_config(s.config) r.set_config(s.config)
env["GITEAPC_PREFIX"] = PREFIX_FOLDER env["GITEAPC_PREFIX"] = PREFIX_FOLDER

View file

@ -165,8 +165,19 @@ class LocalRepo:
source = self.folder + f"/giteapc-config.make" source = self.folder + f"/giteapc-config.make"
target = self.folder + f"/giteapc-config-{config}.make" target = self.folder + f"/giteapc-config-{config}.make"
if os.path.exists(source): if config == "":
if os.path.islink(source):
os.remove(source)
return
if not os.path.exists(target):
raise Error(f"config '{config}' does not exist")
if os.path.islink(source):
os.remove(source) os.remove(source)
elif os.path.exists(source):
raise Error("giteapc-config.make is not a link, was it altered?")
os.symlink(target, source) os.symlink(target, source)
# Metadata # Metadata