File tree Expand file tree Collapse file tree 5 files changed +63
-6
lines changed
Expand file tree Collapse file tree 5 files changed +63
-6
lines changed Original file line number Diff line number Diff line change 22
33## Unreleased
44
5+ ### Added
6+
7+ * ` optional_rust_extension ` option - prints a warning to STDERR instead of raising an exception, if
8+ Cargo is unavailable and ` github_releases ` is either disabled or unavailable. Useful for projects
9+ where either fallback code exists, or a native extension is desirable but not required. (#4 , #6 )
10+
511## [ 0.5.0] - 2016-07-18
612
713### Added
Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ Possible options:
6060 precompiled Rust tarballs. One group must be specified that indicates the version number to be
6161 used in the tarball filename. Defaults to ` vN.N.N ` , where ` N ` is any n-digit number. In this case,
6262 the group is around the entire expression.
63+ * ` optional_rust_extension ` - prints a warning to STDERR instead of raising an exception, if Cargo
64+ is unavailable and ` github_releases ` is either disabled or unavailable. Useful for projects where
65+ either fallback code exists, or a native extension is desirable but not required. Defaults
66+ to ` false ` .
6367* ` ruby_project_path ` - the top-level directory of the Ruby gem's project. Defaults to the
6468 current working directory.
6569
Original file line number Diff line number Diff line change @@ -58,18 +58,43 @@ def run_cargo_build(target)
5858 run_cargo ( *cargo_args )
5959 end
6060
61- # :nocov:
61+ #
62+ # Inform the user about cargo if it doesn't exist.
63+ #
64+ # If `optional_rust_extension` is true, print message to STDERR. Otherwise, raise an exception.
65+ #
66+ def inform_user_about_cargo
67+ raise cargo_required_msg unless options [ :optional_rust_extension ]
68+
69+ $stderr. write ( cargo_recommended_msg )
70+ end
6271
6372 #
64- # Message used when cargo is required but not found.
73+ # Message used when cargo is not found.
6574 #
66- def cargo_required_msg
75+ # `require_severity` is the verb that indicates how important Rust is to the library.
76+ #
77+ def cargo_msg ( require_severity )
6778 <<EOM
6879****
69- Rust's Cargo is required to build this extension. Please install Rust and put
70- it in the PATH, or set the CARGO environment variable appropriately.
80+ Rust's Cargo is #{ require_severity } to build this extension. Please install
81+ Rust and put it in the PATH, or set the CARGO environment variable appropriately.
7182****
7283EOM
7384 end
85+
86+ #
87+ # Message used when cargo is required but not found.
88+ #
89+ def cargo_required_msg
90+ cargo_msg ( 'required' )
91+ end
92+
93+ #
94+ # Message used when cargo is recommended but not found.
95+ #
96+ def cargo_recommended_msg
97+ cargo_msg ( 'recommended (but not required)' )
98+ end
7499 end
75100end
Original file line number Diff line number Diff line change @@ -70,6 +70,10 @@ class Tasks < Rake::TaskLib
7070 # releases to look for precompiled Rust tarballs. One group must be specified that indicates
7171 # the version number to be used in the tarball filename. Defaults to `vN.N.N`, where `N` is
7272 # any n-digit number. In this case, the group is around the entire expression.
73+ # * `optional_rust_extension` - prints a warning to STDERR instead of raising an exception, if
74+ # Cargo is unavailable and `github_releases` is either disabled or unavailable. Useful for
75+ # projects where either fallback code exists, or a native extension is desirable but not
76+ # required. Defaults to `false`.
7377 # * `ruby_project_path` - the toplevel directory of the Ruby gem's project. Defaults to the
7478 # current working directory.
7579 #
@@ -109,7 +113,7 @@ def define_build_task
109113 FileUtils . cp ( config . rust_path ( 'target' , target , config . shared_library ) ,
110114 config . ruby_path ( 'lib' ) )
111115 elsif !download_binary
112- raise cargo_required_msg
116+ inform_user_about_cargo
113117 end
114118 end
115119 end
Original file line number Diff line number Diff line change @@ -32,6 +32,24 @@ def test_run_cargo_release_build
3232 mock_module . run_cargo_build ( 'release' )
3333 end
3434
35+ def test_inform_user_about_cargo_exception
36+ _ , err = capture_io do
37+ assert_raises RuntimeError do
38+ mock_module ( optional_rust_extension : false ) . inform_user_about_cargo
39+ end
40+ end
41+
42+ assert_equal '' , err
43+ end
44+
45+ def test_inform_user_about_cargo_warning
46+ _ , err = capture_io do
47+ mock_module ( optional_rust_extension : true ) . inform_user_about_cargo
48+ end
49+
50+ assert_equal mock_module . cargo_recommended_msg , err
51+ end
52+
3553 def described_class
3654 Tester
3755 end
You can’t perform that action at this time.
0 commit comments