Skip to content

Commit

Permalink
Merge pull request #39 from pine613/develop
Browse files Browse the repository at this point in the history
Update version to v1.1.4
  • Loading branch information
pine committed Jan 23, 2016
2 parents a9fc30a + e9b9cac commit e9ab057
Show file tree
Hide file tree
Showing 36 changed files with 799 additions and 368 deletions.
1 change: 0 additions & 1 deletion .proverc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
--color
--failures
--trap
--verbose
12 changes: 11 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------

| JSON::PP
| http://search.cpan.org/~makamaka/JSON-PP-2.27300/lib/JSON/PP.pm
| https://metacpan.org/pod/JSON::PP

Copyright 2005-2013 by Makamaka Hannyaharamitu

Expand All @@ -52,6 +52,16 @@ under the same terms as Perl itself.

-----------------------------------------------------------

| File::Which
| https://metacpan.org/pod/File::Which

This software is copyright (c) 2002 by Per Einar Ellefsen <[email protected]>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

-----------------------------------------------------------

| crystal-build

(The MIT license)
Expand Down
25 changes: 1 addition & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,5 @@ $ carton exec -- prove t/<dir>/<file>.t
- 1.0.0 - First release

## License
(The MIT license)

MIT License<br />
Copyright (c) 2015 Pine Mizune

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

## Author
Pine Mizune
10 changes: 2 additions & 8 deletions bin/crystal-build
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use lib (
);

use Cwd qw/abs_path/;
use HTTP::Command::Wrapper;

use CrystalBuild;
use CrystalBuild::Utils;
use CrystalBuild::Fetcher;

sub main {
my $args = CrystalBuild::Utils::parse_args(@ARGV);
Expand All @@ -32,7 +32,7 @@ sub main {
cache_url => $cache_url,
shards_url => $shards_url,
cache_dir => abs_path($cache_dir),
fetcher => CrystalBuild::Fetcher->create(fetcher_type()),
fetcher => HTTP::Command::Wrapper->create,
github_repo => $github_repo,
);

Expand All @@ -45,12 +45,6 @@ sub main {
}
}

sub fetcher_type {
`which curl` ? 'curl' :
`which wget` ? 'wget' :
die 'Need curl or wget';
}

main unless caller;

# vim: se et ts=4 sw=4 sts=4 ft=perl :
4 changes: 4 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
requires 'JSON::PP', '2.27300';
requires 'SemVer::V2::Strict', '0.10';
requires 'HTTP::Command::Wrapper', '0.04';

on test => sub {
requires 'Data::Dumper', '2.154';
Expand All @@ -8,13 +9,16 @@ on test => sub {
requires 'Capture::Tiny', '0.30';
requires 'File::Touch', '0.08';
requires 'File::Path', '2.09';
requires 'File::Temp', '0.2304';
requires 'File::Slurp', '9999.19';
requires 'Module::Find', '0.13';

requires 'Test::More', '1.001014';
requires 'Test::Deep', '0.117';
requires 'Test::Deep::Matcher', '0.01';
requires 'Test::Exception', '0.40';

requires 'Test::Mock::Cmd', '0.6';
requires 'Test::Mock::Guard', '0.10';
requires 'Test::MockObject', '1.20150527';
requires 'Test::TCP', '2.12';
Expand Down
2 changes: 1 addition & 1 deletion lib/CrystalBuild.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use strict;
use warnings;
use utf8;
use feature qw/say/;
our $VERSION = '1.1.3';
our $VERSION = '1.1.4';

use File::Path qw/rmtree mkpath/;
use JSON::PP;
Expand Down
26 changes: 16 additions & 10 deletions lib/CrystalBuild/Builder/Shards.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@ use CrystalBuild::Utils;

sub new {
my $class = shift;
bless {} => $class;
return bless {} => $class;
}

sub build {
my ($self, $target_dir, $crystal_dir) = @_;

$self->install_libyaml($target_dir);

my $crystal_bin = abs_path("$crystal_dir/bin/crystal");
my $env_crystal_path = abs_path("$crystal_dir/libs").':.';

my $command = <<"EOF";
CRYSTAL_PATH=$env_crystal_path \
LD_LIBRARY_PATH=$target_dir:\$LD_LIBRARY_PATH \
cd "$target_dir" && "$crystal_bin" build --release src/shards.cr -o bin/shards
EOF
my $command = $self->_create_build_command(
abs_path("$crystal_dir/libs").':.',
$target_dir,
abs_path("$crystal_dir/bin/crystal"),
);

system($command) == 0
or CrystalBuild::Utils::error_and_exit("shards build faild: $target_dir");
or die "shards build faild: $target_dir";

return "$target_dir/bin/shards";
}
Expand Down Expand Up @@ -70,4 +67,13 @@ sub fetch_libyaml_prefix_with_brew {
return $prefix;
}

sub _create_build_command {
my ($self, $env_crystal_path, $target_dir, $crystal_bin) = @_;
return <<"EOF";
CRYSTAL_PATH=$env_crystal_path \\
LD_LIBRARY_PATH=$target_dir:\$LD_LIBRARY_PATH \\
cd "$target_dir" && "$crystal_bin" build --release src/shards.cr -o bin/shards
EOF
}

1;
17 changes: 0 additions & 17 deletions lib/CrystalBuild/Fetcher.pm

This file was deleted.

35 changes: 0 additions & 35 deletions lib/CrystalBuild/Fetcher/Curl.pm

This file was deleted.

35 changes: 0 additions & 35 deletions lib/CrystalBuild/Fetcher/Wget.pm

This file was deleted.

2 changes: 1 addition & 1 deletion lib/CrystalBuild/GitHub.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sub new {

sub fetch {
my ($self, $url) = @_;
$self->{fetcher}->fetch_from_github($url);
$self->{fetcher}->fetch($url, ['Accept: application/vnd.github.v3+json' ]);
}

sub base_url {
Expand Down
42 changes: 24 additions & 18 deletions lib/CrystalBuild/Installer/Shards.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use strict;
use warnings;
use utf8;

use File::Path qw/mkpath/; # >= perl 5.001
use File::Copy qw/copy/; # >= 5.002
use File::Path qw/mkpath/; # >= 5.001
use File::Spec; # >= 5.00405

use CrystalBuild::Utils;
use CrystalBuild::Resolver::Shards;
Expand All @@ -22,21 +24,25 @@ sub cache_dir { shift->{cache_dir} }
sub install {
my ($self, $crystal_version, $crystal_dir) = @_;

print "Resolving shards download URL ... ";
my $tarball_url = $self->_resolve($crystal_version);
print "ok\n";
eval {
print "Resolving shards download URL ... ";
my $tarball_url = $self->_resolve($crystal_version);
print "ok\n";

print "Downloading shards tarball ... ";
my $target_dir = $self->_download($tarball_url);
print "ok\n";
print "Downloading shards tarball ...\n";
my $target_dir = $self->_download($tarball_url);
print "ok\n";

print "Building shards ... ";
my $shards_bin = $self->_build($target_dir, $crystal_dir);
print "ok\n";
print "Building shards ... ";
my $shards_bin = $self->_build($target_dir, $crystal_dir);
print "ok\n";

print "Copying shards binary ... ";
$self->_copy($shards_bin, $crystal_dir);
print "ok\n";
print "Copying shards binary ... ";
$self->_copy($shards_bin, $crystal_dir);
print "ok\n";
};

CrystalBuild::Utils::error_and_exit($@) if $@;
}

sub _resolve {
Expand Down Expand Up @@ -65,13 +71,13 @@ sub _build {
sub _copy {
my ($self, $shards_bin, $crystal_dir) = @_;

my $target_dir = $crystal_dir.'/bin';
my $target_path = $target_dir.'/shards';
my $target_dir = File::Spec->catfile($crystal_dir, 'bin');
my $target_path = File::Spec->catfile($target_dir, 'shards');

# unlink $target_path if -f $target_path;
# mkpath $target_dir unless -d $target_dir;
system("cp \"$shards_bin\" \"$target_path\"") == 0
copy($shards_bin, $target_path)
or CrystalBuild::Utils::error_and_exit('shards binary copy failed: '.$target_path);

chmod 0755, $target_path;
}

1;
8 changes: 8 additions & 0 deletions script/dev/update_vendor_modules.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@ VENDOR_LIB=vendor/lib
rm -rf $VENDOR_LIB
mkdir -p $VENDOR_LIB

mkdir -p $VENDOR_LIB/File
cp -rf $LOCAL_LIB/File/Which.pm $VENDOR_LIB/File/Which.pm

mkdir -p $VENDOR_LIB/HTTP/Command
cp -rf $LOCAL_LIB/HTTP/Command/Wrapper $VENDOR_LIB/HTTP/Command/Wrapper
cp -rf $LOCAL_LIB/HTTP/Command/Wrapper.pm $VENDOR_LIB/HTTP/Command/Wrapper.pm

mkdir -p $VENDOR_LIB/JSON
cp -rf $LOCAL_LIB/JSON/PP $VENDOR_LIB/JSON/PP
cp -rf $LOCAL_LIB/JSON/PP.pm $VENDOR_LIB/JSON/PP.pm

mkdir -p $VENDOR_LIB/SemVer/V2
cp -rf $LOCAL_LIB/SemVer/V2/Strict.pm $VENDOR_LIB/SemVer/V2/Strict.pm

4 changes: 2 additions & 2 deletions t/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ sub create_crenv {
my (%opt) = @_;

require CrystalBuild;
require CrystalBuild::Fetcher::Wget;
require HTTP::Command::Wrapper;

$opt{fetcher} ||= CrystalBuild::Fetcher::Wget->new;
$opt{fetcher} ||= HTTP::Command::Wrapper->create('wget');
$opt{github_repo} ||= 'author/repo';
$opt{prefix} ||= 't/tmp/.crenv/versions/0.7.4';
$opt{cache} ||= 1;
Expand Down
25 changes: 25 additions & 0 deletions t/crystal_build/builder/shards/_create_build_command.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use strict;
use warnings;
use utf8;

use t::Util;

use CrystalBuild::Builder::Shards;

subtest basic => sub {
my $env_crystal_path = '__ENV_CRYSTAL_PATH__';
my $target_dir = '__TARGET_DIR__';
my $crystal_bin = '__CRYSTAL_BIN__';

my $builder = CrystalBuild::Builder::Shards->new;
my $actual = $builder->_create_build_command($env_crystal_path, $target_dir, $crystal_bin);
my $expected = <<'EOF';
CRYSTAL_PATH=__ENV_CRYSTAL_PATH__ \
LD_LIBRARY_PATH=__TARGET_DIR__:$LD_LIBRARY_PATH \
cd "__TARGET_DIR__" && "__CRYSTAL_BIN__" build --release src/shards.cr -o bin/shards
EOF

is $actual, $expected;
};

done_testing;
Loading

0 comments on commit e9ab057

Please sign in to comment.