commit 318443a32dc3c5a9628e24d943c87e5ebcc69e2f
parent 613f01c50bd01ebc63cb283dcfdbcc7b4b1cdb8d
Author: lash <dev@holbrook.no>
Date:   Thu, 20 Jun 2024 02:54:56 +0100
Create output tree structure
Diffstat:
7 files changed, 125 insertions(+), 41 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1 @@
+*_build/
diff --git a/Bluto.pm b/Bluto.pm
@@ -6,18 +6,20 @@ use SemVer;
 use Log::Term::Ansi qw/error info debug warn trace/;
 use Bluto::Archive;
 use Bluto::Announce;
+use Bluto::Tree;
 
 use constant { VCS_TAG_PREFIX => 'v' };
 use constant { VERSION => '0.0.1' };
 
-my %config;
-my @m_tech;
-my @m_url;
-my @m_vcs;
-my @m_src;
-my @m_author_maintainer = [undef, undef, undef];
-my @m_author_origin = [undef, undef, undef];
-my %m_main = (
+our %config;
+our $have_version_match = undef;
+our @m_tech;
+our @m_url;
+our @m_vcs;
+our @m_src;
+our @m_author_maintainer = [undef, undef, undef];
+our @m_author_origin = [undef, undef, undef];
+our %m_main = (
 	name => undef,
 	slug => undef,
 	version => undef,
@@ -35,7 +37,6 @@ my %m_main = (
 	author_origin => \@m_author_origin,
 	engine => undef,
 );
-my $have_version_match = undef;
 
 sub _set_single {
 	my $cfg = shift;
@@ -102,6 +103,18 @@ sub _set_author {
 	return 0;
 }
 
+sub _check_ini {
+	my $env = shift;
+
+	my $fp = File::Spec->catfile($env->{src_dir}, 'bluto.ini');
+	if ( ! -f $fp ) {
+		error('ini file not found: ' . $fp);
+		return 1;
+	}
+	info('using ini file: ' . $fp);
+	return 0;
+}
+
 sub _check_readme {
 	my $env = shift;
 	my $f;
@@ -120,11 +133,19 @@ sub _check_readme {
 	return 1;
 }
 
+sub _prepare_out {
+	my $release = shift;
+	my $env = shift;
+
+	return Bluto::Tree::prepare($release, $env);
+}
+
 sub check_sanity {
 	my $env = shift;
 	my $r = 0;
 
 	$r += _check_readme($env);	
+	$r += _check_ini($env);
 
 	return $r;
 }
@@ -202,9 +223,16 @@ sub from_config {
 	if (!defined $have_version_match) {
 		error("no changelog found for version " . $m_main{version});
 		return undef;
-	} 
+	}
+
+	$r = _prepare_out(\%m_main, $env);
+	if ($r > 0) {
+		error('output location preparations fail');
+		return undef;	
+	}
 
-	my $targz = Bluto::Archive::create($m_main{slug}, $m_main{version}, $m_main{author_maintainer}[2], $m_main{tag_prefix}, $env->{src_dir}, 0);
+	#my $targz = Bluto::Archive::create($m_main{slug}, $m_main{version}, $m_main{author_maintainer}[2], $m_main{tag_prefix}, $env->{src_dir}, $env->{out_dir}, 0);
+	my $targz = Bluto::Archive::create(\%m_main, $env, 0);
 	if (!defined $targz) {
 		error('failed to generate archive');
 		return undef;
@@ -278,12 +306,13 @@ sub from_config {
 	return $have_version_match;
 }
 
-sub get_rss {
+sub create_rss {
 	my $env = shift;
 
 	my $out = Bluto::Announce::get_asciidoc(\%m_main, $env);
 
-	return Bluto::RSS::to_string(\%m_main, $env, $out);
+	#return Bluto::RSS::to_string(\%m_main, $env, $out);
+	return Bluto::RSS::to_file(\%m_main, $env, $out);
 }
 
 1;
diff --git a/Bluto/Announce.pm b/Bluto/Announce.pm
@@ -17,7 +17,6 @@ sub _adapt_headings {
 				$this = '=' x length($last);
 			} elsif ($_ =~ /^---/) {
 				if ($last !~ /^\W+$/) {
-					debug('last is ' . $last);
 					$this = '-' x (length($last) - 1);
 				} else {
 					$this = $_;
diff --git a/Bluto/Archive.pm b/Bluto/Archive.pm
@@ -1,16 +1,18 @@
 package Bluto::Archive;
 
 use Cwd;
-use File::Basename qw/ basename /;
+use File::Basename qw/ basename fileparse /;
 use Digest::SHA;
 
 use Log::Term::Ansi qw/error info debug warn trace/;
+use Bluto::Tree;
 
 
 sub seal {
 	my $targz = shift;
 	my $keygrip = shift;
-	my $safe = shift;
+	# TODO: intended to be numeric flags but now we just use the first bit to force sign or not
+	my $safe = shift; 
 
 	if (!defined $keygrip) {
 		if ($safe) {
@@ -46,27 +48,37 @@ sub seal {
 }
 
 sub create {
-	my $slug = shift;
-	my $version = shift;
-	my $keygrip = shift;
-	my $git_prefix = shift;
-	my $src_dir = shift;
+	my $release = shift;
+	my $env = shift;
 	my $flags = shift;
 
+	my $keygrip = $release->{author_maintainer}[2];
+
 	my $old_dir = cwd;
 
-	chdir($src_dir);
+	chdir($env->{src_dir});
 
-	my $targz = $slug . '-' . $version . '.tar.gz';
-	my $targz_local = File::Spec->catfile($src_dir, $targz);
-	if (! -f $targz_local ) {
-		debug("no package file found, looked for: " . $targz);
+	my $targz_local = undef;
+	my $targz_stem = $release->{slug} . '-' . $release->{version};
+
+	my $rev = `git rev-parse HEAD --abbrev-ref`;
+	if (!defined $rev) {
+		error('unable to determine revision');
+		chdir($old_dir);
+		return undef;
+	}
+	chomp($rev);
+	my $targz = $targz_stem . '+build.' . $rev . '.tar.gz';
+	$targz_local = File::Spec->catfile(Bluto::Tree->release_path, $targz);
 
-		my @cmd = ('git', 'archive', $git_prefix . $version, '--format', 'tar.gz', '-o', $targz);
+	if (! -f $targz_local ) {
+		debug("no package file found, looked for: " . $targz_local);
+		my @cmd = ('git', 'archive', $release->{tag_prefix} . $release->{version}, '--format', 'tar.gz', '-o', $targz_local);
 		system(@cmd);
 		if ($?) {
 			error("package file generation fail: " . $e);
 			unlink($targz);
+			chdir($old_dir);
 			return undef;
 		}
 
@@ -79,18 +91,20 @@ sub create {
 
 		if (! -f $targz_local ) {
 			error("package generation reported ok but still no file");
+			chdir($old_dir);
 			return undef;
 		}
 
 		my $seal = seal($targz_local, $keygrip, $flags & 1);
 		if (!defined $seal) {
 			error("failed sealing archive");
-			unlink($targz);
+			unlink($targz_local);
+			chdir($old_dir);
 			return undef;
 		}
 		info('sealed archive as sha256 ' . $seal . ' signed by ' . $keygrip);
 	} else {
-		info("using existing package file: " . $targz);
+		info("using existing package file: " . $targz_local);
 		warn("existing package file is not being checked in any way 8|");
 	}
 
diff --git a/Bluto/RSS.pm b/Bluto/RSS.pm
@@ -7,14 +7,16 @@ use XML::RSS;
 use Template;
 
 use Log::Term::Ansi qw/error info debug warn trace/;
+use Bluto::Tree qw /announce_path/;
 
 
 sub get_feed_filepath {
 	my $release = shift;
 	my $env = shift;
-	
+
 	my $fn = $release->{slug} . '.bluto.rss';
-	my $fp = File::Spec->catfile($env->{feed_dir}, $fn);
+	#my $fp = File::Spec->catfile($env->{feed_dir}, $fn);
+	my $fp = File::Spec->catfile(Bluto::Tree->announce_path, $fn);
 	return $fp;
 }
 
@@ -22,6 +24,7 @@ sub process {
 	my $release = shift;
 	my $env = shift;
 	my $body = shift;
+	my $force = 1;
 
 	my $rss_title = $release->{slug} . ' ' . $release->{version};
 	my $rss;
@@ -96,7 +99,9 @@ sub to_string {
 	my $body = shift;
 
 	my $rss = process($release, $env, $body);
-	return $rss->as_string;
+	if (!defined $rss) {
+		return undef;
+	}
 }
 
 sub to_file {
@@ -105,7 +110,11 @@ sub to_file {
 	my $body = shift;
 
 	my $rss = process($release, $env, $body);
+	if (!defined $rss) {
+		return undef;
+	}
 	$rss->save(get_feed_filepath($release, $env));
+	return get_feed_filepath($release, $env);
 }
 
 1;
diff --git a/Bluto/Tree.pm b/Bluto/Tree.pm
@@ -0,0 +1,29 @@
+package Bluto::Tree;
+
+
+use File::Spec qw/ catfile /;
+use File::Path qw/ make_path /;
+
+our $_release_path;
+our $_announce_path;
+
+sub release_path() {
+	return $_release_path;
+}
+sub announce_path() {
+	return $_announce_path;
+}
+
+sub prepare {
+	my $release = shift;
+	my $env = shift;
+
+	$_release_path = File::Spec->catfile($env->{out_dir}, $release->{slug}, 'release');
+	File::Path->make_path(release_path);
+	$_announce_path = File::Spec->catfile($env->{out_dir}, $release->{slug}, 'announce');
+	File::Path->make_path(announce_path);
+
+	return 0;
+}
+
+1;
diff --git a/to_std.pl b/to_std.pl
@@ -6,9 +6,10 @@ use strict;
 
 # standard imports
 use Getopt::Long qw/ :config auto_help /;
-use File::Temp qw/ tempdir /;
+#use File::Temp qw/ tempdir /;
 use File::Basename qw/ dirname /;
 use File::Spec qw/ catfile /;
+use File::Path qw/ make_path /;
 use Cwd qw/ getcwd abs_path /;
 
 # external imports
@@ -28,17 +29,13 @@ sub croak {
 
 my %env = (
 	src_dir => File::Spec->catfile(getcwd, '.bluto'),
-	out_dir => getcwd,
-	feed_dir => getcwd,
+	out_dir => File::Spec->catfile(getcwd, 'bluto_build'),
+	feed_dir => undef,
 	content_dir => getcwd,
 	template_path => 'base.tt',
 	engine => undef,
 	readme => undef,
 );
-#my $src_dir = 
-#my $out_dir = getcwd;
-#my $feed_dir = getcwd;
-#my $content_dir = getcwd;
 GetOptions(
 	'd:s', \$env{src_dir},
 	'o:s', \$env{out_dir},
@@ -51,6 +48,10 @@ foreach my $k (keys %env ) {
 	}
 }
 
+if (!defined $env{feed_dir}) {
+	$env{feed_dir} = $env{out_dir};
+}
+
 $env{engine} = 'bluto v' . SemVer->new(Bluto::VERSION). " (perl $^V)";
 foreach my $k (keys %env ) {
 	if (defined $env{$k}) {
@@ -71,7 +72,9 @@ if (!defined $version) {
 	die("config processing failed");
 }
 
-my $rss = Bluto::get_rss(\%env);
-print($rss);
+my $rss = Bluto::create_rss(\%env);
+if (!defined $rss) {
+	die("rss processing failed");
+}
 
 #my @change = $cfg->vars();