diff --git a/ConfigProvider/config_provider.rb b/ConfigProvider/config_provider.rb deleted file mode 100644 index de74fb9..0000000 --- a/ConfigProvider/config_provider.rb +++ /dev/null @@ -1,72 +0,0 @@ -require 'json' - -class ConfigProvider - ## - # Creates a ConfigProvider which helps in reading values from the bottle's config file - # in the bottle-configs directory. - # Json files are used so that it is easy to modify them by bot - - CONFIG_DIR = File.join(File.dirname(__FILE__), "..", "bottle-configs") - - def initialize(name, config_file_path=nil) - unless config_file_path.nil? - file = File.read(config_file_path) - else - file = File.read(File.join(CONFIG_DIR, "#{name.downcase}.json")) - end - - @config_data = JSON.parse(file) - end - - def name - @config_data['name'] - end - - def version - @config_data['version'] - end - - def bin - @config_data['bin'] - end - - def url - @config_data['url'] - end - - def sha256 - @config_data['sha256'] - end - - def root_url - @config_data['bottle']['root_url'] - end - - def sierra_hash - @config_data['bottle']['sha256']['sierra'] - end - - def arm64_big_sur_hash - @config_data['bottle']['sha256']['arm64_big_sur'] - end - - def linux_hash - @config_data['bottle']['sha256']['linux'] - end - - def linux_arm_hash - @config_data['bottle']['sha256']['linux_arm'] - end - - def native_root_url - @config_data['native']['root_url'] - end - - def native_linux_x86_file - @config_data['native']['linux_x86']['file'] - end - - def native_linux_x86_hash - @config_data['native']['linux_x86']['sha256'] - end -end diff --git a/Formula/smithy-cli.rb b/Formula/smithy-cli.rb index c539e0b..19986c1 100644 --- a/Formula/smithy-cli.rb +++ b/Formula/smithy-cli.rb @@ -1,58 +1,52 @@ -# -*- coding: utf-8 -*- -require_relative '../ConfigProvider/config_provider' - class SmithyCli < Formula - $config_provider = ConfigProvider.new('smithy-cli') - desc "Smithy CLI - A CLI for building, validating, querying, and iterating on Smithy models" - homepage "https://smithy.io" - version $config_provider.version + desc "Smithy CLI - A CLI for building, validating, querying, and iterating on Smithy models" + homepage "https://smithy.io" + + + livecheck do + url :stable + strategy :github_latest + regex(/^v?(\d+(?:\.\d+)+)$/i) + end + + # Default to macos-x86 + platform = OS.mac? ? "darwin" : "linux" + arch = Hardware::CPU.intel? ? "x86_64" : "aarch64" + + version `curl -L -s https://github.com/smithy-lang/smithy/releases/latest/download/VERSION`.strip + url "https://github.com/smithy-lang/smithy/releases/latest/download/smithy-cli-#{platform}-#{arch}.zip" + sha256 `curl -L -s https://github.com/smithy-lang/smithy/releases/latest/download/smithy-cli-#{platform}-#{arch}.zip.sha256`.split(' ').first + + def install + # install everything in archive into libexec, so that + # the contents are private to homebrew, which means it won't try + # to symlink anything in this directory automatically + libexec.install Dir["*"] + # create a symlink to the private executable + bin.install_symlink "#{libexec}/bin/smithy" => "smithy" + end + def post_install + # brew relocates dylibs and assigns different ids, which is problematic since + # we package a runtime image ourselves if OS.mac? - if Hardware::CPU.intel? - url "#{$config_provider.root_url}-darwin-x86_64.tar.gz" - sha256 $config_provider.sierra_hash - elsif Hardware::CPU.arm? - url "#{$config_provider.root_url}-darwin-aarch64.tar.gz" - sha256 $config_provider.arm64_big_sur_hash - end - elsif OS.linux? - if Hardware::CPU.intel? - url "#{$config_provider.root_url}-linux-x86_64.tar.gz" - sha256 $config_provider.linux_hash - elsif Hardware::CPU.arm? - url "#{$config_provider.root_url}-linux-aarch64.tar.gz" - sha256 $config_provider.linux_arm_hash + Dir["#{libexec}/lib/**/*.dylib"].each do |dylib| + chmod 0664, dylib + MachO::Tools.change_dylib_id(dylib, "@rpath/#{File.basename(dylib)}") + # we also need to resign the dylibs, so that their ad-hoc signatures are not invalid + MachO.codesign!(dylib) + chmod 0444, dylib end end + # call warmup command to generate the jsa + system "#{bin}/smithy" " warmup" + puts "Successfully installed smithy: #{`#{bin}/smithy --version`}" + end - def install - # install everything in archive into libexec, so that - # the contents are private to homebrew, which means it won't try - # to symlink anything in this directory automatically - libexec.install Dir["*"] - # create a symlink to the private executable - bin.install_symlink "#{libexec}/bin/smithy" => "smithy" - end + test do + assert_predicate lib/smithy.jsa, :exist? + assert_match version, shell_output("#{bin}/smithy --version") + assert_match "Usage: smithy", shell_output("#{bin}/smithy --help") + end - def post_install - # brew relocates dylibs and assigns different ids, which is problematic since - # we package a runtime image ourselves - if OS.mac? - Dir["#{libexec}/lib/**/*.dylib"].each do |dylib| - chmod 0664, dylib - MachO::Tools.change_dylib_id(dylib, "@rpath/#{File.basename(dylib)}") - # we also need to resign the dylibs, so that their ad-hoc signatures are not invalid - MachO.codesign!(dylib) - chmod 0444, dylib - end - end - # call warmup command to generate the jsa - system "#{bin}/#{$config_provider.bin}" " warmup" - end - - test do - assert_predicate lib/"#{$config_provider.bin}.jsa", :exist? - assert_match $config_provider.version, shell_output("#{bin}/#{$config_provider.bin} --version") - assert_match "Usage: #{$config_provider.bin}", shell_output("#{bin}/#{$config_provider.bin} --help") - end end diff --git a/bottle-configs/smithy-cli.json b/bottle-configs/smithy-cli.json deleted file mode 100644 index e396256..0000000 --- a/bottle-configs/smithy-cli.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "version": "1.43.0", - "name": "smithy-cli", - "bin": "smithy", - "bottle": { - "root_url": "https://github.com/smithy-lang/smithy/releases/download/1.43.0/smithy-cli", - "sha256": { - "arm64_big_sur": "e8d8a4a7b379a588f5522b2b891882e4aad0a8d0c70a43d7805065a8114772b6", - "sierra": "a209487a6cd1e32801e994ed1169e888ed89658e5bd95ed2d66e66686882ba72", - "linux": "35a344e76c644fd394d322af5d1dc578aa20046339003bbae596fab50b76c6c6", - "linux_arm": "26b4fca8c6f287b83ac28faae925e4e8a9ac2889185909e1cc5e5e15c2dc7938" - } - } -}