how to use path.basename with bjam? - bjam

I am currently using this action:
actions re2c {
re2c --tags -o `basename $(<)` $(>)
}
But I'd like to use the path.basename rule instead. Something along the lines:
rule re2c ( targets * : sources * : properties * )
{
import path ;
targets = [ path.basename $(targets) ] ;
}
This approach is not working for me.

Related

Getting the build type/variant inside a bjam Jamfile / echo a feature?

So, let's say, I call bjam debug, or bjam release, or bjam clean, possibly with other target names, and I'd like to have the build action or type (debug, release, clean) available in a script.
Here https://android.googlesource.com/platform/external/boost/+/ac861f8c0f33538060790a8e50701464ca9982d3/Jamroot I found an example, that I modified like this:
import modules ;
tbuildcmd = "" ;
if clean in [ modules.peek : ARGV ]
{
tbuildcmd = clean ;
}
else if release in [ modules.peek : ARGV ]
{
tbuildcmd = release ;
}
else if debug in [ modules.peek : ARGV ]
{
tbuildcmd = debug ;
}
echo "tbuildcmd $(tbuildcmd)" ;
And this works fine, it seems - but I was wondering, is there a better method to get the build command/type as a variable? For instance, they say in https://www.boost.org/doc/libs/1_35_0/doc/html/bbv2/tutorial.html :
The release and debug that we've seen in bjam invocations are just a shorthand way to specify values of the variant feature. For example, the command above could also have been written this way:
bjam variant=release inlining=off debug-symbols=on
So, there is apparently a "variant" "feature" - but how can I use / echo it? I tried echo $(<variant>) and that failed.

Getting NuGet Package Vulnerability Information from an API

We have been looking at ways that we can scan our code for NuGet packages that have vulnerabilities or are deprecated.
We have looked into using dotnet list package --vulnerable but this doesn't seem to be playing nicely with our Xamarin projects. It throws errors relating to missing project imports and we haven't found a way to get the tools to ignore the errors.
I think the issue is related to this: https://github.com/NuGet/Home/issues/9035
Is it possible to replicate what the CLI tool is doing by calling NuGet APIs?
I have had to check that for an old project of ours that was using packages.config (not supported by dotnet list) This is a powershell function that I have written and it helped in my case:
function Check-Package()
{
param([string]$id ,[string]$version)
$packages = Invoke-RestMethod "https://azuresearch-usnc.nuget.org/query?q=$id"
$packageDetailsUrl = $packages.data | ? { $_.id -eq $id} | %{ $_.versions } | ?{$_.version -eq $version } | %{ $_."#id"}
if($packageDetailsUrl)
{
$packageDetails = Invoke-RestMethod $packageDetailsUrl
$packageSuperDetails = Invoke-RestMethod $packageDetails.catalogEntry
if($packageSuperDetails.vulnerabilities -or $packageSuperDetails.deprecation)
{
if($packageSuperDetails.deprecation)
{
$deprectaion = "is deprecated"
}
if($packageSuperDetails.vulnerabilities)
{
$vulnerability = "has vulnerabilities"
}
Write-Host $id $version $deprectaion $vulnerability
}
}
else
{
Write-Host $id $version no longer listed on nuget.org
}
}
I use it like that:
nuget list -source .\packages\ | %{Check-Package -id $_.Split(" ")[0] -version $_.Split(" ")[1]

bjam: Use same actions for multiple rules

I have an action defined that generates coverage files, it takes some options.
actions coverage {
echo coverage $(OPTIONS) >> $(<)
}
I need a rule to set the $(OPTIONS) variable:
rule coverage ( targets * : sources * : properties * ) {
OPTIONS on $(targets) = ... # Get from environment variables
}
Once I have done that, I can use the rule to generate coverage files:
make cov.xml : : #coverage ;
What I want is a second rule (that computes the $(OPTIONS) variable in a different way), that uses the same actions. Is that possible without duplicating the action itself? In other words, is it possible to associate two rules with the same action?
What I want is something like this:
actions coverage-from-features {
# AVOID HAVING TO REPEAT THIS
echo coverage $(OPTIONS) >> $(<)
}
rule coverage-from-features ( targets * : sources * : properties * ) {
OPTIONS on $(targets) = ... # Get from feature values
}
make cov2.xml : : #coverage-from-features ;
Obviously without repeating the action commands itself (DRY and all that).
The key aspect you need is that: You don't need to use actions that mirror the rule invoked. A rule can call any, and multiple actions, to do the work. In your case you can do something like:
actions coverage-action {
echo coverage $(OPTIONS) >> $(<)
}
rule coverage ( targets * : sources * : properties * ) {
OPTIONS on $(targets) = ... ; # Get from environment variables
coverage-action $(target) : $(sources) ;
}
rule coverage-from-features ( targets * : sources * : properties * ) {
OPTIONS on $(targets) = ... ; # Get from feature values
coverage-action $(target) : $(sources) ;
}
make cov.xml : : #coverage ;
make cov2.xml : : #coverage-from-features ;

specs2: Tag specification/individual test and exclude it from running using sbt

I need to skip specifications and individual tests while running my test suite.
Here's an example such test:
package models
import org.specs2.mutable._
import org.specs2.runner._
class SlowTaggedSpecification extends Specification{
"SLOW_SPEC" should {
"BAD!! Not Skipped" in {
"axbcd" must find( "bc".r )
}
} section( "SLOW_SPEC" )
}
class SlowFastTaggedSpecification extends Specification{
"SLOW_FAST_SPEC" should {
"run fast test" in {
"axbcd" must find( "bc".r )
} section( "FAST_TEST" )
"SLOW_TEST should be skipped (BAD!! NOT Skipped)" in {
"axbcd" must find( "bc".r )
} section( "SLOW_TEST" )
} section( "SLOW_FAST_SPEC" )
}
I need to skip SLOW_SPEC (entire spec) and SLOW_TEST (indvidual test only).
My build.sbt is:
scalaVersion := "2.11.1"
libraryDependencies += "org.specs2" %% "specs2" % "2.3.12" % "test"
When I run the following command line:
sbt '~testOnly models.* -- -l SLOW_SPEC'
sbt '~testOnly models.* -- -l SLOW_TEST'
none of the tests gets skipped. May I know how do I exclude a specification and an individual test using tags? Also, what would be the sbt syntax if I weren't using testOnly , but test?
sbt '~test -- -l SLOW_SPEC'
causes sbt to complain. My sbt version is 0.13.5
Any pointers would be appreciated.
The command line argument to exclude tags is
sbt> ~testOnly models.* -- exclude SLOW_SPEC
If you want to exclude tags when using the test command you need to use Test.Arguments in your build.sbt file:
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "exclude", "SLOW_SPEC")
If you want to specifically run a SLOW_SPEC test, then use the following:
sbt 'set testOptions in Test := Seq()' '~testOnly models.SlowTaggedSpecification'

Powershell Scheduled Task Open Web Page to Execute Script

In an effort to setup a "cron job" like scheduled task on Windows I've setup a Powershell script using code recommended via previous stackoverflow question.
I have some backups that I need to cleanup daily and delete old backups so I created a asp.net script to perform this task - the file name is BackupCleanup.aspx and I have confirmed that the ASP.net script does work when executed on its own by visiting the above url - I however cannot get it to execute using the Powershell script below.
The Powershell Script code I'm using is:
$request = [System.Net.WebRequest]::Create("http://127.0.0.1/BackupCleanup.aspx")
$response = $request.GetResponse()
$response.Close()
I have created this file with a PS1 extension, it shows properly in my os (Windows 2008) - I have tried both manually executing this task by right clicking and choosing "Run with Powershell" and also have scheduled this as a task - both to no avail.
I cannot figure out why the script does not work - any help would be GREATLY appreciated.
Here is the Powershell script I use to call up web pages using IE. Hopefully this will work for you as well.
Function NavigateTo([string] $url, [int] $delayTime = 100)
{
Write-Verbose "Navigating to $url"
$global:ie.Navigate($url)
WaitForPage $delayTime
}
Function WaitForPage([int] $delayTime = 100)
{
$loaded = $false
while ($loaded -eq $false) {
[System.Threading.Thread]::Sleep($delayTime)
#If the browser is not busy, the page is loaded
if (-not $global:ie.Busy)
{
$loaded = $true
}
}
$global:doc = $global:ie.Document
}
Function SetElementValueByName($name, $value, [int] $position = 0) {
if ($global:doc -eq $null) {
Write-Error "Document is null"
break
}
$elements = #($global:doc.getElementsByName($name))
if ($elements.Count -ne 0) {
$elements[$position].Value = $value
}
else {
Write-Warning "Couldn't find any element with name ""$name"""
}
}
Function ClickElementById($id)
{
$element = $global:doc.getElementById($id)
if ($element -ne $null) {
$element.Click()
WaitForPage
}
else {
Write-Error "Couldn't find element with id ""$id"""
break
}
}
Function ClickElementByName($name, [int] $position = 0)
{
if ($global:doc -eq $null) {
Write-Error "Document is null"
break
}
$elements = #($global:doc.getElementsByName($name))
if ($elements.Count -ne 0) {
$elements[$position].Click()
WaitForPage
}
else {
Write-Error "Couldn't find element with name ""$name"" at position ""$position"""
break
}
}
Function ClickElementByTagName($name, [int] $position = 0)
{
if ($global:doc -eq $null) {
Write-Error "Document is null"
break
}
$elements = #($global:doc.getElementsByTagName($name))
if ($elements.Count -ne 0) {
$elements[$position].Click()
WaitForPage
}
else {
Write-Error "Couldn't find element with tag name ""$name"" at position ""$position"""
break
}
}
#Entry point
# Setup references to IE
$global:ie = New-Object -com "InternetExplorer.Application"
$global:ie.Navigate("about:blank")
$global:ie.visible = $true
# Call the page
NavigateTo "http://127.0.0.1/BackupCleanup.aspx"
# Release resources
$global:ie.Quit()
$global:ie = $null
I had the same issue. I manually opened powershell and executed my script and I received "WebPage.ps1 cannot be loaded because running scripts is disabled on this system.".
You have to allow scripts to run
Execute the below in PowerShell
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine

Resources