Skip to content

Commit

Permalink
Support suffixed Rust versions
Browse files Browse the repository at this point in the history
Summary: I want to upgrade derive_more which involves introducing a suffix. We have ~15 libraries which are currently suffixed. Support them in github.

Reviewed By: bigfootjon

Differential Revision: D61774614

fbshipit-source-id: 9bbdd881aa96f079ba24c48a9db1d82c3bd9ef1a
  • Loading branch information
ndmitchell authored and facebook-github-bot committed Aug 26, 2024
1 parent 67c3f7d commit fb142f5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions shim/shims.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@ def _fix_dep(x: str) -> [
None,
str,
]:
def remove_version(x: str) -> str:
# When upgrading libraries we either suffix them as `-old` or with a version, e.g. `-1-08`
# Strip those so we grab the right one in open source.
if x.endswith("/md-5"): # md-5 is the one exception
return x
xs = x.split("-")
for i in range(len(xs)):
s = xs[i]
if s == "old" or isdigit(s):
xs.pop(i)
else:
break
return xs.join("-")

if x == "//common/rust/shed/fbinit:fbinit":
return "fbsource//third-party/rust:fbinit"
elif x == "//common/rust/shed/sorted_vector_map:sorted_vector_map":
Expand All @@ -417,9 +431,9 @@ def _fix_dep(x: str) -> [
elif x.startswith("fbcode//third-party-buck/platform010/build"):
return "shim//third-party" + x.removeprefix("fbcode//third-party-buck/platform010/build")
elif x.startswith("fbsource//third-party"):
return "shim//third-party" + x.removeprefix("fbsource//third-party")
return "shim//third-party" + remove_version(x.removeprefix("fbsource//third-party"))
elif x.startswith("third-party//"):
return "shim//third-party/" + x.removeprefix("third-party//")
return "shim//third-party/" + remove_version(x.removeprefix("third-party//"))
elif x.startswith("//folly"):
oss_depends_on_folly = read_config("oss_depends_on", "folly", False)
if oss_depends_on_folly:
Expand Down Expand Up @@ -451,3 +465,10 @@ def external_dep_to_target(t):

def external_deps_to_targets(ts):
return [external_dep_to_target(t) for t in ts]

def _assert_eq(x, y):
if x != y:
fail("Expected {} == {}".format(x, y))

def _test():
_assert_eq("fbsource//third-party/rust:derive_more-1", "shim//third-party/rust:derive_more")

0 comments on commit fb142f5

Please sign in to comment.