From 9d2d6e357535e3e669051385fcddd4f110687cfe Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Fri, 24 Jan 2014 10:43:00 -0500 Subject: [PATCH] add arch_only to caveats mini-DSL Relevant to points raised by @goxberry in #2581 --- CONTRIBUTING.md | 1 + lib/cask/caveats.rb | 27 +++++++++++++++++++++++++++ test/support/Casks/with-caveats.rb | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f7c5c1304181..ae803e19cc6a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -264,6 +264,7 @@ The following methods may be called to generate standard warning messages: | `logout` | The user should log out and log back in to complete installation | `reboot` | The user should reboot to complete installation | `files_in_usr_local` | The Cask installs files to `/usr/local`, which may confuse Homebrew +| `arch_only(list)` | The Cask only supports certain architectures. Currently valid elements of `list` are `intel-32` and `intel-64` Example: diff --git a/lib/cask/caveats.rb b/lib/cask/caveats.rb index 81189963edfa..1c07fa63133c 100644 --- a/lib/cask/caveats.rb +++ b/lib/cask/caveats.rb @@ -77,6 +77,33 @@ def reboot EOS end + # minor bug: because output from arch_only is conditional, the + # existence of this directive causes "===> Caveats" header to + # appear even if no warning is output. One workaround would + # be to spin out arch-detection from caveats into a separate + # Cask stanza, and that is probably a sensible design. + def arch_only(*supported_arches) + known_arches = %w{intel-64 intel-32} + supported_arches.each do |arch| + unless known_arches.include?(arch) + # There ought to be some standard exceptions for Cask validation errors + raise "The only valid arguments to caveats arch_only in #{@cask} are: #{known_arches.join(', ')}" + end + end + this_arch = "#{Hardware::CPU.type}-#{Hardware::CPU.bits}" + unless supported_arches.include?(this_arch) + puts <<-EOS.undent + Cask #{@cask} provides binaries for these architectures: #{supported_arches.join(', ')}. + But you appear to be running on an unsupported architecture: + + #{this_arch} + + Therefore #{@cask} is not expected to work on your system. + + EOS + end + end + def method_missing(method, *args) poo = <<-EOPOO.undent Unexpected method #{method} called on caveats in Cask #{@cask}. diff --git a/test/support/Casks/with-caveats.rb b/test/support/Casks/with-caveats.rb index 29f87130554b..78d3605b4b3f 100644 --- a/test/support/Casks/with-caveats.rb +++ b/test/support/Casks/with-caveats.rb @@ -17,4 +17,9 @@ class WithCaveats < TestCask puts 'Custom text via puts followed by DSL-generated text:' manual_installer('Installer.app') end + caveats do + # since both valid arches are specified, no output should be + # generated here during the test + arch_only('intel-32', 'intel-64') + end end