Skip to content

Commit

Permalink
Adjusted logic for wildcard libs
Browse files Browse the repository at this point in the history
  • Loading branch information
mindstorm38 committed Jun 23, 2024
1 parent 0be876d commit f141ba2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 14 additions & 10 deletions portablemc/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ def _resolve_libraries(self, watcher: Watcher) -> None:

watcher.handle(LibrariesResolvingEvent())

lib_names = set()
# This set contains all unique library specifiers that have been found so far.
# It also contains libs that have been filtered out by rules.
unique_specs = set()

# Recursion order is important for libraries resolving, root libraries should
# be placed first.
Expand All @@ -622,7 +624,6 @@ def _resolve_libraries(self, watcher: Watcher) -> None:
raise ValueError(f"metadata: /libraries/{library_idx}/name must be a string")

spec = LibrarySpecifier.from_str(name)
spec_name = (spec.group, spec.artifact)

# Old metadata files provides a 'natives' mapping from OS to the classifier
# specific for this OS, this kind of libs are "native libs", we need to
Expand All @@ -642,11 +643,18 @@ def _resolve_libraries(self, watcher: Watcher) -> None:
if minecraft_arch_bits is not None:
spec.classifier = spec.classifier.replace("${arch}", str(minecraft_arch_bits))

# We just abort here if the lib name has already been specified.
if spec_name in lib_names:
# Create a wildcard copy of the spec without version, because we don't
# want to match against version, regardless of its version, a library
# should not be added twice.
spec_wild = spec.copy()
spec_wild.version = "*"

# We just abort here if the lib name has already been specified. It is
# really important to do that here after natives resolution because it
# adds a classifier to the lib spec.
if spec_wild in unique_specs:
continue

lib_names.add(spec_name)
unique_specs.add(spec_wild)

# Changed in 4.3.1, rules are checked after natives
rules = library.get("rules")
Expand All @@ -656,10 +664,6 @@ def _resolve_libraries(self, watcher: Watcher) -> None:
raise ValueError(f"metadata: /libraries/{library_idx}/rules must be a list")

if not interpret_rule(rules, self._features, f"metadata: /libraries/{library_idx}/rules"):

if spec.version != "*":
lib_names.remove(spec_name)

continue

lib_entry: Optional[DownloadEntry] = None
Expand Down
3 changes: 3 additions & 0 deletions portablemc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ def file_path(self) -> str:
f".{self.extension}"

return "/".join([*self.group.split("."), self.artifact, self.version, file_name])

def copy(self) -> "LibrarySpecifier":
return LibrarySpecifier(self.group, self.artifact, self.version, self.classifier, self.extension)

0 comments on commit f141ba2

Please sign in to comment.