Skip to content

Commit

Permalink
Merge pull request #104 from flavorjones/flavorjones-add-source-direc…
Browse files Browse the repository at this point in the history
…tory-support

add source directory support
  • Loading branch information
flavorjones authored May 31, 2021
2 parents a6c83cf + a21efe8 commit d0bd6aa
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 15 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## mini_portile changelog

### next / unreleased

### Added

Recipes may build against a local directory by specifying `source_directory` instead of `files`. In
particular, this may be useful for debugging problems with the upstream dependency (e.g., use `git
bisect` in a local clone).


### 2.5.2 / 2021-05-28

#### Dependencies
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ system-wide installation.
Same as above, but instead of `MiniPortile.new`, call `MiniPortileCMake.new`.


### Local source directories

Instead of downloading a remote file, you can also point mini_portile2 at a local source
directory. In particular, this may be useful for testing or debugging:

``` ruby
gem "mini_portile2", "~> 2.0.0" # NECESSARY if used in extconf.rb. see below.
require "mini_portile2"
recipe = MiniPortile.new("libiconv", "1.13.1")
recipe.source_directory = "/path/to/local/source/for/library-1.2.3"
```

### Directory Structure Conventions

`mini_portile2` follows the principle of **convention over configuration** and
Expand Down
16 changes: 9 additions & 7 deletions examples/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ recipes.push zlib
namespace :ports do
directory "ports"

task :before do
FileUtils.rm_rf(File.expand_path("tmp"), verbose: true);
recipes.each do |recipe|
FileUtils.rm_rf(recipe.path, verbose: true)
end
end
task :all => :before

recipes.each do |recipe|
desc "Install port #{recipe.name} #{recipe.version}"
task recipe.name => ["ports"] do |t|
checkpoint = "ports/.#{recipe.name}-#{recipe.version}-#{recipe.host}.installed"

unless File.exist?(checkpoint)
recipe.cook
touch checkpoint
end

recipe.cook
recipe.activate
end

Expand Down
33 changes: 25 additions & 8 deletions lib/mini_portile2/mini_portile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def edit_path(path)
class MiniPortile
attr_reader :name, :version, :original_host
attr_writer :configure_options
attr_accessor :host, :files, :patch_files, :target, :logger
attr_accessor :host, :files, :patch_files, :target, :logger, :source_directory

def self.windows?
RbConfig::CONFIG['target_os'] =~ /mswin|mingw/
Expand All @@ -55,10 +55,22 @@ def initialize(name, version)
@patch_files = []
@log_files = {}
@logger = STDOUT
@source_directory = nil

@original_host = @host = detect_host
end

def source_directory=(path)
@source_directory = File.expand_path(path)
end

def prepare_build_directory
raise "source_directory is not set" if source_directory.nil?
output "Building #{@name} #{@version} from source at '#{source_directory}'"
FileUtils.mkdir_p(File.join(tmp_path, [name, version].join("-")))
FileUtils.rm_rf(port_path) # make sure we always re-install
end

def download
files_hashs.each do |file|
download_file(file[:url], file[:local_path])
Expand Down Expand Up @@ -110,15 +122,16 @@ def configure_options
def configure
return if configured?

FileUtils.mkdir_p(tmp_path)
cache_file = File.join(tmp_path, 'configure.options_cache')
File.open(cache_file, "w") { |f| f.write computed_options.to_s }

command = Array(File.join((source_directory || "."), "configure"))
if RUBY_PLATFORM=~/mingw|mswin/
# Windows doesn't recognize the shebang.
execute('configure', %w(sh ./configure) + computed_options)
else
execute('configure', %w(./configure) + computed_options)
command.unshift("sh")
end
execute('configure', command + computed_options)
end

def compile
Expand All @@ -139,7 +152,7 @@ def downloaded?
end

def configured?
configure = File.join(work_path, 'configure')
configure = File.join((source_directory || work_path), 'configure')
makefile = File.join(work_path, 'Makefile')
cache_file = File.join(tmp_path, 'configure.options_cache')

Expand All @@ -157,9 +170,13 @@ def installed?
end

def cook
download unless downloaded?
extract
patch
if source_directory
prepare_build_directory
else
download unless downloaded?
extract
patch
end
configure unless configured?
compile
install unless installed?
Expand Down
29 changes: 29 additions & 0 deletions test/test_cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,32 @@ def test_patch
end
end
end

class TestCookAgainstSourceDirectory < TestCase
attr_accessor :recipe

def setup
super

@recipe ||= MiniPortile.new("test mini portile", "1.0.0").tap do |recipe|
recipe.source_directory = File.expand_path("../assets/test mini portile-1.0.0", __FILE__)
end
end

def test_source_directory
recipe.cook

path = File.join(work_dir, "configure.txt")
assert(File.exist?(path))
assert_equal((recipe.configure_options + ["--prefix=#{recipe.path}"]).inspect,
File.read(path).chomp);

path = File.join(work_dir, "compile.txt")
assert(File.exist?(path))
assert_equal("[\"all\"]", File.read(path).chomp);

path = File.join(work_dir, "install.txt")
assert(File.exist?(path))
assert_equal("[\"install\"]", File.read(path).chomp);
end
end

0 comments on commit d0bd6aa

Please sign in to comment.