summaryrefslogtreecommitdiff
path: root/src/BuildPackage.pm
blob: 61087f2511768da1f979392e9b07cb6434c7f5ad (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
79
80
81
82
83
84
85
package BuildPackage;

use strict;
use warnings;

use File::Basename;
use XibUtil qw/extract_from_file extract md5_sum/;

sub extract_source{
    return XibUtil::extract_from_file(@_, qr/^SOURCE=(.+)$/);
}

sub extract_branch{
    return XibUtil::extract_from_file(@_, qr/^BRANCH=(.+)$/);
}

sub extract_version{
    return XibUtil::extract_from_file(@_, qr/^PKG_VER=(.+)$/);
}

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 ($build_file) = @_;
   
    mkdir("$main::chroot/build");
    mkdir("$main::chroot/build/source");
    chdir("$main::chroot/build/source");

    my $source = extract_source($build_file);
    my $branch = extract_branch($build_file);
    my $PKG_VER = extract_version($build_file);

    if (XibUtil::is_git_repo($source, $branch)) {
        print("Fetching git repo $source version $PKG_VER\n");
        system("git clone $source .");
        system("git checkout $branch");

    } else {
        print("downloading file $source\n");
        my $downloaded_file = basename($source);
        system("curl $source $downloaded_file");
        extract("$downloaded_file");
        system("pwd; cp -r */* .")
    
    }

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

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

    my $existing_version = get_built_version($build_file);
    if (defined($existing_version) && $existing_version eq md5_sum($build_file)) {
        # do not build
        print("do not build\n");
        return
    } 
    # build
    fetch_source($build_file);
    
    

}
1;