11class Sapling < Formula
22 desc "Source control client"
33 homepage "https://sapling-scm.com"
4- url "https://github.com/facebook/sapling/archive/refs/tags/0.2.20240718-145624+f4e9df48.tar.gz"
5- version "0.2.20240718-145624-f4e9df48"
6- sha256 "8081d405cddb9dc4eadd96f4c948b7686b0b61f641c068fc87b9c27518fb619e"
74 license "GPL-2.0-or-later"
85 head "https://github.com/facebook/sapling.git" , branch : "main"
96
7+ stable do
8+ url "https://github.com/facebook/sapling/archive/refs/tags/0.2.20240718-145624+f4e9df48.tar.gz"
9+ version "0.2.20240718-145624-f4e9df48"
10+ sha256 "8081d405cddb9dc4eadd96f4c948b7686b0b61f641c068fc87b9c27518fb619e"
11+
12+ # Backport fix for Python 3.12
13+ patch do
14+ url "https://github.com/facebook/sapling/commit/65a7e9097fb9280aef7c50ecdf08b5755288490a.patch?full_index=1"
15+ sha256 "ca59aebef870bad9887b927b68c1be76a01bb905f5eb76cf2f0d2499b3b0c306"
16+ end
17+ end
18+
1019 livecheck do
1120 url :stable
1221 regex ( /^v?(\d +(?:[.-]\d +)+[+-]\h +)$/i )
@@ -25,28 +34,67 @@ class Sapling < Formula
2534 end
2635
2736 depends_on "cmake" => :build
37+ depends_on "pkg-config" => :build
2838 depends_on "python-setuptools" => :build
2939 depends_on "rust" => :build
3040 depends_on "yarn" => :build
31- # The `cargo` crate requires http2, which `curl-config` from macOS reports to
32- # be missing despite its presence.
33- # Try switching to `uses_from_macos` when that's resolved.
34- depends_on "curl"
3541 depends_on "gh"
42+ depends_on "libssh2"
3643 depends_on "node"
3744 depends_on "openssl@3"
38453946
4047 uses_from_macos "bzip2"
48+ uses_from_macos "curl"
4149 uses_from_macos "zlib"
4250
43- on_linux do
44- depends_on "pkg-config" => :build # for `curl-sys` crate to find `curl`
45- end
46-
4751 conflicts_with "sl" , because : "both install `sl` binaries"
4852
53+ def watchman_rev
54+ watchman_repo = "https://github.com/facebook/watchman.git"
55+ max_date = version . patch . to_s . match ( /^(\d {4})(\d {2})(\d {2})\b / ) . captures . join ( "." )
56+ tags = Utils . safe_popen_read ( "git" , "ls-remote" , "--sort=-version:refname" , "--tags" , watchman_repo )
57+ tags . scan ( %r{^(\S +)\t refs/tags/v(\d {4}\. \d {2}\. \d {2})(?:\. \d +)+$} ) do |rev , date |
58+ return rev if date <= max_date
59+ end
60+ odie "Unable to pick watchman tag based on sapling patch version #{ version . patch } !"
61+ end
62+
4963 def install
64+ # Workaround to improve reproducibility as Cargo.toml uses branch for some dependencies.
65+ # Actual reproducible builds won't be possible without a Cargo.lock.
66+ #
67+ # Related issue: https://github.com/facebook/sapling/issues/547
68+ if build . stable?
69+ github_hashes = buildpath . glob ( "build/deps/github_hashes/*/*-rev.txt" ) . to_h do |revfile |
70+ commit = revfile . read [ /commit ([0-9a-f]+)$/i , 1 ]
71+ odie "Unable to parse commit from #{ revfile } !" if commit . nil?
72+ [ "#{ revfile . dirname . basename } /#{ revfile . basename ( "-rev.txt" ) } " , commit ]
73+ end
74+ odie "Unable to find any revision files in build/deps/github_hashes!" if github_hashes . empty?
75+
76+ # Watchman doesn't have a revision file. To avoid using HEAD, scan through tags
77+ # and use revision from tag created on or before date in Sapling patch version
78+ odie "Remove workaround for handling facebook/watchman!" if github_hashes . key? ( "facebook/watchman" )
79+ github_hashes [ "facebook/watchman" ] = watchman_rev
80+
81+ no_modification = true
82+ Dir . glob ( "**/Cargo.toml" ) do |manifest |
83+ inreplace manifest do |s |
84+ github_hashes . each do |repo , rev |
85+ result = s . gsub! %r{(git = "https://github.com/#{ repo } (?:\. git)?",) branch = "[^"]*"} ,
86+ "\\ 1 rev = \" #{ rev } \" " ,
87+ audit_result : false
88+ no_modification &&= result . nil?
89+ end
90+ end
91+ if ( git_branch = File . read ( manifest ) [ /git = "[^"]*", branch = "[^"]*"/ ] )
92+ odie "#{ manifest } tracks a branch for #{ git_branch } !"
93+ end
94+ end
95+ odie "Inreplace did not modify any branch usage in Cargo.toml manifests!" if no_modification
96+ end
97+
5098 if OS . mac?
5199 # Avoid vendored libcurl.
52100 inreplace %w[
@@ -59,8 +107,9 @@ def install
59107 end
60108
61109 python3 = "python3.12"
110+ ENV [ "LIBSSH2_SYS_USE_PKG_CONFIG" ] = "1"
62111 ENV [ "OPENSSL_DIR" ] = Formula [ "openssl@3" ] . opt_prefix
63- ENV [ "PYTHON " ] = ENV [ "PYTHON3" ] = python3
112+ ENV [ "PYTHON_SYS_EXECUTABLE " ] = which ( python3 )
64113 ENV [ "SAPLING_VERSION" ] = if build . stable?
65114 version
66115 else
@@ -69,7 +118,7 @@ def install
69118
70119 # Don't allow the build to break our shim configuration.
71120 inreplace "eden/scm/distutils_rust/__init__.py" , '"HOMEBREW_CCCFG"' , '"NONEXISTENT"'
72- system "make" , "-C" , "eden/scm" , "install-oss" , "PREFIX=#{ prefix } "
121+ system "make" , "-C" , "eden/scm" , "install-oss" , "PREFIX=#{ prefix } " , "PYTHON= #{ python3 } " , "PYTHON3= #{ python3 } "
73122 end
74123
75124 def check_binary_linkage ( binary , library )
@@ -93,9 +142,19 @@ def check_binary_linkage(binary, library)
93142 assert_equal "first" , shell_output ( "#{ bin } /sl log -l 1 -T {desc}" ) . chomp
94143 end
95144
96- [
97- Formula [ "curl" ] . opt_lib /shared_library ( "libcurl" ) ,
98- ] . each do |library |
145+ dylibs = [
146+ Formula [ "libssh2" ] . opt_lib /shared_library ( "libssh2" ) ,
147+ Formula [ "openssl@3" ] . opt_lib /shared_library ( "libssl" ) ,
148+ Formula [ "openssl@3" ] . opt_lib /shared_library ( "libcrypto" ) ,
149+ ]
150+ if OS . mac?
151+ assert ( bin /"sl" ) . dynamically_linked_libraries . any? { |dll | dll . start_with? ( "/usr/lib/libcurl." ) } ,
152+ "No linkage with system curl! Cargo is likely using a vendored version."
153+ else
154+ dylibs << ( Formula [ "curl" ] . opt_lib /shared_library ( "libcurl" ) )
155+ end
156+
157+ dylibs . each do |library |
99158 assert check_binary_linkage ( bin /"sl" , library ) ,
100159 "No linkage with #{ library . basename } ! Cargo is likely using a vendored version."
101160 end
0 commit comments