summaryrefslogtreecommitdiff
path: root/src/BuildPackage.pm
blob: afcb65a3cf45f88bd6513e865a782b71c86687ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package BuildPackage;

use strict;
use warnings;

use File::Basename "basename";
use Digest::MD5;

sub md5_sum{
    my ($file) = @_;

    open(my $fh, "<", $file) or die "Cannot open $file: $!";
    binmode($fh);

    return Digest::MD5->new->addfile($fh)->hexdigest;
}

sub extract_ver_hash{
    my $info_file = $_;
    open (my $fh, "<", $info_file) or warn "Cannot open $info_file";
    while (my $line = <$fh>) {
        if ($line =~ /^VER_HASH=(.+)$/) {
            return $1;
        }
    }
}
sub extract_ver_hash{
    my $info_file = $_;
    open (my $fh, "<", $info_file) or warn "Cannot open $info_file";
    while (my $line = <$fh>) {
        if ($line =~ /^VER_HASH=(.+)$/) {
            return $1;
        }
    }
}

sub get_built_version{
    my ($build_file) = @_;
    my @package_split = split(/\//, $build_file);
    my $repo = $package_split[-2];
    my $name = basename($build_file, ".xibuild");
    my $dest = "$main::export/repo/$repo/$name";

    my $pkg = "$dest.xipkg";
    my $info = "$dest.xipkg.info";
    my $used_build = "$dest.xibuild";
    
    if (-e $pkg && -e $info) {
        return md5_sum($used_build);
    }
}

sub clear_build_folder{
    rmtree("$main::chroot/build");
}

sub fetch_source{
    my $source_url = $_;
   
    mkdir("$main::chroot/build")
    mkdir("$main::chroot/build/source")

    # download source to $chroot/build/mysource.tgz
    # extract source to $chroot/build/source
}

sub build_package{
    my ($build_file) = @_;

    $existing_version = get_built_version($build_file);
    if (defined($existing_version) && $existing_version eq md5_sum($build_file)) {
        # do not build
        return
    } 
    # build
    

}