Skip to content

Commit

Permalink
Merge pull request #1342 from peter279k/add_snmp_variant
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Apr 27, 2023
2 parents c22340c + d850bef commit 816c356
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/PhpBrew/VariantBuilder.php
Expand Up @@ -767,6 +767,28 @@ public function __construct()
return $parameters->withOption('--with-pear', $value);
};

/*
* --with-snmp option
*
* --with-snmp=[dir]
*
* On macOS, you need to use the brew to install the net-snmp
*
* On ubuntu you need to install libsnmp-dev
* On Ubuntu 18.04+, it should ensure the /usr/include/net-snmp/net-snmp-config.h is available.
* On Ubuntu 20.04+, it should ensure the pkg-config --variable=prefix netsnmp can find the net-snmp prefix.
*/
$this->variants['snmp'] = function (ConfigureParameters $parameters, Build $build, $value) {
$prefix = Utils::findPrefix(array(
new UserProvidedPrefix($value),
new BrewPrefixFinder('net-snmp'),
new PkgConfigPrefixFinder('netsnmp'),
new IncludePrefixFinder('net-snmp/net-snmp-config.h'),
));

return $parameters->withOptionOrPkgConfigPath($build, '--with-snmp', $prefix);
};

// merge virtual variants with config file
$customVirtualVariants = Config::getConfigParam('variants');
$customVirtualVariantsToAdd = array();
Expand Down
33 changes: 33 additions & 0 deletions tests/PhpBrew/VariantBuilderTest.php
Expand Up @@ -119,6 +119,10 @@ public function variantOptionProvider()
array('zlib'),
array('--with-zlib'),
),
'snmp' => array(
array('snmp'),
array('--with-snmp'),
),
);
}

Expand Down Expand Up @@ -326,4 +330,33 @@ public static function ztsProvider()
array('8.0.0', '--enable-zts'),
);
}

/**
* @param string $version
* @param string $expected
*
* @dataProvider snmpProvider
*/
public function testSnmp($version, $expected)
{
$build = new Build($version);
$build->enableVariant('snmp');

$builder = new VariantBuilder();
$options = $builder->build($build)->getOptions();

$this->assertArrayHasKey($expected, $options);
}

public static function snmpProvider()
{
return array(
array('5.6.0', '--with-snmp'),
array('7.0.0', '--with-snmp'),
array('7.1.0', '--with-snmp'),
array('7.3.0', '--with-snmp'),
array('7.4.0', '--with-snmp'),
array('8.0.0', '--with-snmp'),
);
}
}

0 comments on commit 816c356

Please sign in to comment.