-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix homebrew bottle generation (#767)
Summary: [sl] fix homebrew bottle generation Pull Request resolved: #767 Reviewed By: muirdm Differential Revision: D51093087 Pulled By: sggutier fbshipit-source-id: f0f46ebc7c3a3b838e54287f605c5c1148694ece
- Loading branch information
1 parent
20f30b4
commit 6d06c8f
Showing
5 changed files
with
147 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 16,7 @@ class Sapling < Formula | |
|
||
depends_on "[email protected]" | ||
depends_on "node" | ||
depends_on "openssl@1.1" | ||
depends_on "openssl@3" | ||
depends_on "gh" | ||
depends_on "cmake" => :build | ||
depends_on "rustup-init" => :build | ||
|
@@ -29,7 29,7 @@ def install | |
# force some specific location by setting the OPENSSL_DIR environment | ||
# variable. This is necessary since the installed OpenSSL library | ||
# might not match the architecture of the destination one. | ||
ENV["OPENSSL_DIR"] = "%TMPDIR%/openssl@1.1/1.1.1s" | ||
ENV["OPENSSL_DIR"] = Formula["openssl@3"].opt_prefix | ||
ENV["PYTHON_SYS_EXECUTABLE"] = Formula["[email protected]"].opt_prefix/"bin/python3.11" | ||
ENV["PYTHON"] = Formula["[email protected]"].opt_prefix/"bin/python3.11" | ||
ENV["PYTHON3"] = Formula["[email protected]"].opt_prefix/"bin/python3.11" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,105 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# | ||
# This software may be used and distributed according to the terms of the | ||
# GNU General Public License version 2. | ||
|
||
import argparse | ||
import os | ||
import re | ||
import shutil | ||
import subprocess | ||
import tempfile | ||
from typing import List | ||
|
||
|
||
# Create the parser | ||
parser = argparse.ArgumentParser( | ||
description="""Creates a homebrew bottle for the specified architecture | ||
Also downloads additional brew bottles as required. | ||
""" | ||
) | ||
|
||
parser.add_argument( | ||
"-t", | ||
"--target", | ||
default=None, | ||
type=str, | ||
help="Compilation target (e.g. aarch64-apple-darwin)", | ||
required=True, | ||
) | ||
|
||
parser.add_argument( | ||
"-r", | ||
"--release-version", | ||
default=None, | ||
type=str, | ||
help="Version for Sapling", | ||
required=True, | ||
) | ||
|
||
parser.add_argument( | ||
"-d", | ||
"--dotdir", | ||
default="git", | ||
type=str, | ||
help="Dot directory of the current repo (e.g. .git, .hg, .sl)", | ||
required=False, | ||
) | ||
|
||
parser.add_argument( | ||
"-o", | ||
"--formula-out", | ||
default="sapling.rb", | ||
type=str, | ||
help="Location of the resultant filled in formula", | ||
required=False, | ||
) | ||
|
||
|
||
def run_cmd(cmd: List[str]) -> str: | ||
return subprocess.check_output(cmd).decode("utf-8").rstrip() | ||
|
||
|
||
def create_repo_tarball(dotdir): | ||
run_cmd( | ||
[ | ||
"tar", | ||
"--exclude", | ||
f".{dotdir}/**", | ||
"--exclude", | ||
"sapling.tar.gz", | ||
"-czf", | ||
"./sapling.tar.gz", | ||
".", | ||
] | ||
) | ||
|
||
|
||
def fill_in_formula_template(target, version, tmpdir, filled_formula_dir): | ||
brew_formula_rb = os.path.join(os.path.dirname(__file__), "brew_formula.rb") | ||
with open(brew_formula_rb, "r") as f: | ||
formula = f.read() | ||
sha256 = run_cmd(["shasum", "-a", "256", "./sapling.tar.gz"]).split()[0] | ||
cachedir = run_cmd(["brew", "--cache"]) | ||
formula = formula.replace( | ||
"%URL%", | ||
f"file://{os.path.join(os.path.abspath(os.getcwd()), 'sapling.tar.gz')}", | ||
) | ||
formula = formula.replace("%VERSION%", version) | ||
formula = formula.replace("%SHA256%", sha256) | ||
formula = formula.replace("%TMPDIR%", tmpdir) | ||
formula = formula.replace("%TARGET%", target) | ||
formula = formula.replace("�CHEDIR%", cachedir) | ||
with open(filled_formula_dir, "w") as f: | ||
f.write(formula) | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
tmpdir = tempfile.mkdtemp() | ||
create_repo_tarball(args.dotdir) | ||
fill_in_formula_template( | ||
args.target, args.release_version, tmpdir, args.formula_out | ||
) |