summaryrefslogtreecommitdiff
path: root/Build/Collax.pm
blob: 2fc332c431b123f8722ecb039f9afaf88964a1fc (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
#
# Copyright 2015  Zarafa B.V. and its licensors
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
package Build::Collax;

use strict;

sub parse {
	my($buildconf, $fn) = @_;
	my @bscript;

	if (ref($fn) eq "ARRAY") {
		@bscript = @$fn;
		$fn = undef;
	} elsif (ref($fn) ne "") {
		die "Unhandled ref type in collax";
	} else {
		local *FH;
		if (!open(FH, "<", $fn)) {
			return {"error" => "$fn: $!"};
		}
		@bscript = <FH>;
		chomp(@bscript);
		close(FH);
	}

	my $ret = {"deps" => []};
	for (my $i = 0; $i <= $#bscript; ++$i) {
		next unless $bscript[$i] =~ m{^\w+=};
		my $key = lc(substr($&, 0, -1));
		my $value = $';
		if ($value =~ m{^([\'\"])}) {
			$value = substr($value, 1);
			while ($value !~ m{[\'\"]}) {
				my @cut = splice(@bscript, $i + 1, 1);
				$value .= $cut[0];
			}
			$value =~ s{[\'\"]}{}s;
			$value =~ s{\n}{ }gs;
		}
		if ($key eq "package") {
			$ret->{"name"} = $value;
		} elsif ($key eq "version") {
			$ret->{$key} = $value;
		} elsif ($key eq "builddepends" || $key eq "extradepends") {
			$value =~ s{^\s+}{}gs;
			$value =~ s{\s+$}{}gs;
			$value =~ s{,}{ }gs;
			push(@{$ret->{"deps"}}, split(/\s+/, $value));
		}
	}
	return $ret;
}

1;