Skip to content

Commit

Permalink
Merge branch 'trs/envdir'
Browse files Browse the repository at this point in the history
  • Loading branch information
tsibley committed Jun 5, 2023
2 parents 19bf02d + c01044a commit a8bfdd2
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
4 changes: 3 additions & 1 deletion devel/build
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ build() {
}

lock() {
log "Copying $repo/src to $repo/locked"
cp -a src locked

# XXX TODO: It would be extra nice to prepend channel specifiers to each
# locked dep (e.g. conda-forge::nextstrain-cli ==x.y.z hbadcafe_0_locked).
# Boa has that info at build time, but it doesn't seem to make it into the
# rendered recipe included in the package. Would have to reach into Boa
# somehow or leverage libmamba directly to obtain it…
# -14 Oct 2022
log "Updating $repo/locked/recipe.yaml"
mkdir -p locked
yq \
--yaml-roundtrip \
--slurpfile rendered <(rendered-recipe | yaml-to-json) \
Expand Down
4 changes: 4 additions & 0 deletions src/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail -x
mkdir -p "$PREFIX"/bin
cp -v "$SRC_DIR"/envdir "$PREFIX"/bin/envdir
84 changes: 84 additions & 0 deletions src/envdir
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/env perl
# A pure-Perl port of djb's envdir <https://cr.yp.to/daemontools/envdir.html>,
# for quick, no-thought portability (because `perl` is available ~everywhere).
#
# There are many copies of envdir, this is mine.
#
# Copied from <https://github.com/tsibley/envdir/blob/a3099699/envdir>.
#
# Comments quote text from https://cr.yp.to/daemontools/envdir.html
#
# envdir runs another program with environment modified according to files in a
# specified directory.
#
use strict;
use warnings;
use FindBin qw< $Script >;

# Interface:
#
# envdir <d> <child>
#
# <d> is a single argument. <child> consists of one or more arguments.
#
my $d = shift;
my @child = @ARGV;

fatal("usage: %s <d> <child>", $Script)
unless defined $d and @child;

# envdir sets various environment variables as specified by files in the
# directory named <d>. It then runs <child>.
#
opendir my $dh, $d
or fatal("cannot read <%s>: %s", $d, $!);

# If <d> contains a file named s whose first line is t, envdir removes an
# environment variable named s if one exists, and then adds an environment
# variable named s with value t.
#
for my $s (readdir $dh) {
next if $s =~ /^[.]{1,2}$/;

# The name s must not contain =.
next if $s =~ /=/;

delete $ENV{$s};

# If the file s is completely empty (0 bytes long), envdir removes an
# environment variable named s if one exists, without adding a new
# variable.
#
next if -z "$d/$s";

open my $fh, "<", "$d/$s"
or fatal("cannot read <%s>: %s", "$d/$s", $!);

my $t = <$fh>;

close $fh
or fatal("cannot close <%s>: %s", "$d/$s", $!);

# Spaces and tabs at the end of t are removed.
$t =~ s/\s+$//;

# Nulls in t are changed to newlines in the environment variable.
$t =~ s/\0/\n/g;

$ENV{$s} = $t;
}
closedir $dh
or fatal("cannot close <%s>: %s", $d, $!);

# envdir exits 111 if it has trouble reading <d>, if it runs out of memory for
# environment variables, or if it cannot run <child>. Otherwise its exit code
# is the same as that of <child>.
#
exec @child
or fatal("Failed to exec([%s]): %s", join(" ", @child), $!);

sub fatal {
my ($msg, @rest) = @_;
warn sprintf($msg, @rest), "\n";
exit 111;
}
3 changes: 3 additions & 0 deletions src/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ build:
#
#pin_depends: strict

source:
path: .

about:
home: https://nextstrain.org
doc_url: https://docs.nextstrain.org/
Expand Down

0 comments on commit a8bfdd2

Please sign in to comment.