--- /dev/null
+#!/usr/bin/perl -w
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2017 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, 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 Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# This script sets the host_hostflags for a FreeBSD job based on the runvars
+# provided and the contents of the extra_hostflags runvar.
+#
+# If the freebsd_distpath runvar is set the installer image will be retrieved
+# from "freebsd_distpath"/install.img, and the FreeBSD version from the
+# freebsd_version runvar. Note that both those runvars should be set on the
+# current job.
+#
+# If freebsd_distpath is not set, it is assumed that freebsdbuildjob runvar is
+# set and the installer image will be retrieved from the path pointed to by
+# "path_freebsdddist"/install.img, and the FreeBSD version will be obtained
+# from the "freebsd_buildversion" runvar. Both of those runvars belong to the
+# flight and job pointed to by freebsdbuildjob.
+#
+# As output upon successful completion this script will set the host_hostflags
+# runvar for the current job. Note that this _must_ be done before running
+# ts-host-allocate.
+#
+
+use strict qw(vars);
+use DBI;
+use POSIX;
+
+unshift @INC, qw(.);
+use Osstest;
+use Osstest::TestSupport;
+
+tsreadconfig();
+
+our $share;
+if (@ARGV && $ARGV[0] eq "--share") {
+ $share = 1;
+ shift @ARGV;
+}
+
+sub get_freebsd_image_hash() {
+ my $distpath = $r{"freebsd_distpath"} ||
+ get_stashed("path_freebsddist", $r{"freebsdbuildjob"});
+
+ return sha256file("$distpath/install.img", 16);
+}
+
+sub get_freebsd_version() {
+ return $r{"freebsd_version"} ||
+ get_runvar("freebsd_buildversion", $r{"freebsdbuildjob"});
+}
+
+while (@ARGV) {
+ my $ident = shift @ARGV;
+
+ die "Unexpected argument $ident" if $ident =~ m/^-/;
+
+ my $version = get_freebsd_version();
+ set_runtime_hostflag($ident, "PropMinVer:Freebsd:$version");
+
+ if ($share) {
+ my $hash = get_freebsd_image_hash();
+
+ set_runtime_hostflag($ident, "share-build-freebsd-$hash");
+ }
+}