How to run Dart tests in IntelliJ with NNBD experiment enabled? - dart

I am on Dart 2.10.0-92.0.dev and I am trying to port my libraries to use null-saftey / non-nullable / NNBD.
I've enabled the experiment in analysis_options.yaml and the analyzer in IntelliJ is correctly displaying errors and warning.
I can successfully run tests from the command line, and in IntelliJ using a Dart Command Line App by passing --enable-experiment=non-nullable as a VM option.
It is unclear to me how I can run a Dart Test in IntelliJ? I keep on getting the following error, and I can't figure out how to pass the experiment flag?
Error: This requires the null safety language feature, which is experimental.
You can enable the experiment using the '--enable-experiment=non-nullable' command line option.

Today's Dart plugin update adds 'VM Options' field to the Dart Test run configuration. Click Help -> Check for Updates... in the IDE to get it.

What you need to do it's to put --enable-experiment=non-nullable in the VM options while Editing the configuration:

To run Dart tests configuration with NNBD enabled, you need to add the VMOptions in the "run configuration" file :
Check the "Store as project file" options in the "Edit configuration" window,
Open the generated configuration file ( YOUR_PROJECT/.idea/runConfigurations/YOUR_RUN_TEST.xml ) and add this line before the filePath option :
<option name="VMOptions" value="--enable-experiment=non-nullable --no-sound-null-safety" />
Your file should look like :
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="my tests" type="DartTestRunConfigurationType" factoryName="Dart Test" nameIsGenerated="true">
<option name="VMOptions" value="--enable-experiment=non-nullable --no-sound-null-safety" />
<option name="filePath" value="$PROJECT_DIR$/srv/ytbx021-run-api/app" />
<option name="scope" value="FOLDER" />
<method v="2" />
</configuration>
</component>
Then run your tests, it will fail one more time, but on the next run it should run in null safety mode.

Related

Process leaked file descriptors jenkins ERROR on Jenkins

Can someone help me to solve an issue "process leaked file descriptors jenkins"?
I tried whit BUIL_ID = dontkillme but it doesnt work.
Thx
It would help to know more about what you're trying to run but this question came up as a result of troubleshooting an issue I was having so here's how I resolved it. I am using Windows so if you're using something else it may not work for you.
First of all you need to read and understand the Jenkins documentation on the issue: https://jenkins.io/redirect/troubleshooting/process-leaked-file-descriptors
I had to install Ant first since it was not installed.
https://ant.apache.org/bindownload.cgi
The Jenkins documentation gives you an example Ant script:
<exec executable="cscript.exe">
<env key="ANTRUN_TITLE" value="Title for Window" /> <!-- optional -->
<env key="ANTRUN_OUTPUT" value="output.log" /> <!-- optional -->
<arg value="//NoLogo" />
<arg value="antRunAsync.js" /> <!-- this script -->
<arg value="real executable" />
</exec>
You will change the "real executable" to be the executable you are wanting to run.
See that .js file in the 2nd arg value? You will need to create that. There's a link to this on the Jenkins documentation page too. Grab it here: https://wiki.jenkins.io/download/attachments/1835010/antRunAsync.js?version=1&modificationDate=1184046328000&api=v2
I didn't make any edits to the contents, just pasted it right in and saved it as antRunAsync.js
So now you take your Ant example script I posted above and throw that in a text editor, save as build.xml
From this point you should be able to test on the command line by typing ant and pressing enter. Your application should load in a different window.
If you haven't set up Ant in the Jenkins Global Tool Configuration do so now and point it to your Ant install (might have to uncheck the Install checkbox). In the Jenkins project add a build step Invoke Ant. Set that up how you like according to Ant documentation.
Hope this answer helps someone else who has stumbled across this problem and this question.

Can't access ArtifactStagingDirectory variable in MSBuild

During my build process I'm trying to copy a folder to the artifacts folder (\myserver\d$\TFBuild-Agent01\66\a).
So I put this in the .csproj file:
<Target Name="BeforeBuild">
<Exec
Command="xcopy.exe Databases "$(Build.ArtifactStagingDirectory)\Databases" /i /e /y /d" />
</Target>
This gets me
Error MSB4184: The expression """.ArtifactStagingDirectory" cannot be evaluated. Method 'System.String.ArtifactStagingDirectory' not found*
Everything I can find online says that $(Build.ArtifactStagingDirectory) is the way to do it. But it doesn't work.
Building with Visual Studio 2015 on TFS 2015
This doesn't work either:
<Exec
Command="xcopy.exe Databases "$($Env:BUILD_ARTIFACTSTAGINGDIRECTORY)\Databases" /i /e /y /d" />
The expression "$Env:BUILD_ARTIFACTSTAGINGDIRECTORY" cannot be evaluated.*
This doesn't error, but it looks like %BUILD_ARTIFACTSTAGINGDIRECTORY% gets replaced as an empty string:
<Exec Command="xcopy.exe Databases "%BUILD_ARTIFACTSTAGINGDIRECTORY%\Databases" /i /e /y /d" />
You have been mixing ways to access the build variables that the agent allows you. The syntax using $(some.variable) is interpreted by the agent itself. MSBuild has a similar looking syntax - $(PropertyName) - which does something different - it gives access to msbuild properties and does not allow for dots (.) in it's name, since you can use the dot to call functions on the value (e.g. $(OutputPath.Substring(3))).
When you want to reference build variables from MSBuild, you need to reference the environment variable that the agent sets. This is possible because MSBuild makes all environment variables accessible as global properties using its property syntax. The environment variable for Build.ArtifactStagingDirectory is BUILD_ARTIFACTSTAGINGDIRECTORY so you can use it in MSBuild using $(BUILD_ARTIFACTSTAGINGDIRECTORY).
I have been using it successfully in this script to default a property when run as part of a TFS/VSTS build (PublishBaseDir is a custom property used later):
<PropertyGroup>
<!-- Default artifact staging directory when built via VSTS / TFS agent -->
<PublishBaseDir Condition="'$(PublishBaseDir)' == '' and '$(BUILD_ARTIFACTSTAGINGDIRECTORY)' != '' ">$(BUILD_ARTIFACTSTAGINGDIRECTORY)</PublishBaseDir>
<!-- If not built on a known agent, use a "publish" subdir next to this file -->
<PublishBaseDir Condition="'$(PublishBaseDir)' == ''">$(MSBuildThisFileDirectory)publish\</PublishBaseDir>
<!-- Normalize directory if set manually or through ENV var -->
<PublishBaseDir Condition="!HasTrailingSlash('$(PublishBaseDir)')">$(PublishBaseDir)\</PublishBaseDir>
</PropertyGroup>
OK, I guess that because I'm using Visual Studio to build my solution, I can't access $(Build.StagingDirectory) from the .csproj. However, it's being passed on the command line to the "Visual Studio Build" build step as a property:
/p:OutDir="$(Build.StagingDirectory)"
So that can be accessed by doing
<Exec Command="xcopy.exe Databases "$(OutDir)\Databases" /i /e /y /d" />

TFS 2012 build error The "CreateWorkspaceTask" task was not given a value for the required parameter "BuildAgentUri"

We upgraded to TFS 2012 and changed our legacy build templates to remove all strong name references to Microsoft.TeamFoundation namespaces from the Activity element. We are now getting the following error when building:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets (801): The "CreateWorkspaceTask" task was not given a value for the required parameter "BuildAgentUri".
Has anyone else encountered this error?
I just resolved this issue earlier today....
Navigate and open:-
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets
Find the section resembling the following:-
CreateWorkspaceTask
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
BuildDirectory="$(BuildDirectory)"
SourcesDirectory="$(SolutionRoot)"
Name="$(WorkspaceName)"
Comment="$(CreateWorkspaceTaskComment)"
Replace it with:-
<!-- Create the workspace for this build -->
<CreateWorkspaceTask
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
BuildDirectory="$(BuildDirectory)"
SourcesDirectory="$(SolutionRoot)"
Name="$(WorkspaceName)"
Comment="$(CreateWorkspaceTaskComment)"
Condition=" '$(ProjectFileVersion)' != '4'">
<Output TaskParameter="Name" PropertyName="WorkspaceName" />
<Output TaskParameter="Owner" PropertyName="WorkspaceOwner" />
</CreateWorkspaceTask>
<CreateWorkspaceTask
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
BuildDirectory="$(BuildDirectory)"
BuildAgentUri="$(BuildAgentUri)"
SourcesDirectory="$(SolutionRoot)"
Name="$(WorkspaceName)"
Comment="$(CreateWorkspaceTaskComment)"
Condition=" '$(ProjectFileVersion)' == '4'">
<Output TaskParameter="Name" PropertyName="WorkspaceName" />
<Output TaskParameter="Owner" PropertyName="WorkspaceOwner" />
</CreateWorkspaceTask>
Please pay special attention to the casing of the text as this is an XML document...
Please let me know if this helps...
Cheers!
...
Chev
We ran into this same issue on one of our build machines. The build machine was working fine one day and stopped the next. The only change was finishing the installation of Service Pack 1 for Visual Studio 2010.
We figured that possibly MSBuild got rolled to a previous version.
So we looked at this file on another build machine and that section looked exactly like the snippet Chev provided.
So we went into "progams and features" on the build machine and did a Repair on the TFS 2012 installation. That updated the Microsoft.TeamFoundation.Build.targets file to look just like the snippet provided by Chev.
Now the builds run correctly again.

CruiseControl.net ndk-build on Windows 64bit without Cygwin

Latest Android NDK (version 8) allows to call ndk-build without additional cygwin installed.
My question is: can I plug this into CruiseControl.Net for periodical native build?
I assume that most likely I would need to use Ant as a build method and then add it to ccnet server config.
So the questions are:
How to call ndk-build.cmd from an Ant command
How to configure build.xml file?
I tried several approaches, but all of those failed. Could you give me some clues if it is possible at all?
I ran into the same problem (the CreateProcess failures, etc) when trying to invoke "ndk-build.cmd" directly from build.xml, using CC.net on Windows. I figured out how to get this to work, and so I felt compelled to share my solution.
First, create a 1-line Windows command file as follows (I named it "ndkwrapper.cmd"):
sh ndkwrap.sh %1 %2 %3
Next, create a simple bash shell script as follows (named "ndkwrap.sh"):
#!/usr/bin/sh
# Wrapper around ndk-build script for Windows
#
NDK_PROJECT_PATH=/cygdrive/c/workspace/agnc_android
export NDK_PROJECT_PATH
/cygdrive/c/Android/android-ndk-r8b/ndk-build $1 $2 $3
Of course, your exact paths (for your workspace and NDK directories) may be different, but note, in particular, that "/cygdrive/c" refers to "C:".
One very important step here, after you create the script above, is to convert the line endings from Windows to UNIX. You can do this with a utility called "dos2unix.exe" which is freely available. I don't remember where I got it, but it was part of some open source package of GNU/Linux tools ported to Windows. (Google on "UNIX file utilities for Windows".) If you don't convert the line endings, then sh or bash will have trouble reading the script, and you'll get all kinds of erros about "\r" ...
So, to invoke the equivalent of "ndk-build.cmd clean", for example, you'd type "ndkwrapper.cmd clean" to delete your intermediate and output NDK-related build files, in preparation for a full NDK build.
In your build.xml file for CC.net on Windows, you can invoke the NDK makefile as follows:
<tasks>
<exec>
<executable>cmd.exe</executable>
<baseDirectory>C:\Android</baseDirectory>
<buildArgs>/C ndkwrapper.cmd clean</buildArgs>
</exec>
Hope this helps!
Ben
i observed problems with running ndk-build as an CCNET task as well.
It took me a while, but at the end i noticed, that you have to provide HOST_OS and HOST_ARCH as ndk-build parameters to let it run.
<exec>
<executable>cmd</executable>
<buildArgs>/C ndk-build HOST_OS=windows HOST_ARCH=x86 -B NDK_PROJECT_PATH=[PROJECT] APP_BUILD_SCRIPT=[ANDROIDMKFILE] NDK_APPLICATION_MK=[APPLICATIONMKFILE] NDK_LOG=1</buildArgs>
<buildTimeoutSeconds>120</buildTimeoutSeconds>
</exec>
hope it helps anyone to save time.
Ok I got some progress, I am able to build the jni code via ant or nant but in both cases plugging it to the cc.net server config gives me strane error:
but now CC.net gives me strange errors:
<builderror>
<type>NAnt.Core.BuildException</type>
<message><![CDATA[External Program Failed: G:\\android-ndk-r8b\\ndk-build.cmd (return code was 2)]]></message>
<location>
<filename>G:/MYPath/project.build</filename>
<linenumber>7</linenumber>
<columnnumber>4</columnnumber>
</location>
<stacktrace><![CDATA[ at NAnt.Core.Tasks.ExternalProgramBase.ExecuteTask()
at NAnt.Core.Tasks.ExecTask.ExecuteTask()
at NAnt.Core.Task.Execute()
at NAnt.Core.Target.Execute()
at NAnt.Core.Project.Execute(String targetName, Boolean forceDependencies)
at NAnt.Core.Project.Execute()
at NAnt.Core.Project.Run()]]></stacktrace>
</builderror>
</failure>
<duration>296.40000000000003</duration>
</buildresults>Buildfile: file:///G:/MYPath/project.build
Target framework: Microsoft .NET Framework 4.0
Target(s) specified: build
clean:
[echo] Starting Android ndk CLEAN ...
[exec] Android NDK: Unable to determine HOST_OS from uname -s:
[exec] Android NDK: Please define HOST_OS in your environment.
[exec] process_begin: CreateProcess(NULL, uname -s, ...) failed.
[exec] G:/android-ndk-r8b/build/core/init.mk:131: *** Android NDK: Aborting. . Stop.
BUILD FAILED - 0 non-fatal error(s), 2 warning(s)
My project in cc.net config:
<project>
<name>MY_PROJECT_NAME</name>
<workingDirectory>PATH_TO_MY_PROJECT</workingDirectory>
<tasks>
<nant>
<executable>G:\nant-0.92\bin\Nant.exe</executable>
<baseDirectory>PATH_TO_MY_PROJECT</baseDirectory>
<buildFile>MYPROJECTNAME.build</buildFile>
<buildArgs>build</buildArgs>
<buildTimeoutSeconds>1200</buildTimeoutSeconds>
</nant>
</tasks>
</project>
And my NAnt build file:
<project name="my name" default="build" basedir=".">
<description>My project Build Files.</description>
<target name="clean" description="remove all generated files">
<echo message="Starting Android ndk CLEAN ..."/>
<exec program="G:\\android-ndk-r8b\\ndk-build.cmd" failonerror="true"
basedir="MY PROJECT PATH">
<arg value="clean" />
</exec>
<echo message="Android ndk CLEAN done."/>
</target>
<target name="build" description="remove all generated files" depends="clean">
<echo message="Starting Android ndk BUILD ..."/>
<exec program="G:/android-ndk-r8b/ndk-build.cmd" failonerror="true" />
<echo message="Android ndk BUILD done."/>
</target>
</project>
As I said I can run a Nant.exe for my project and it cleans and build correctly.
It looks like the cc.net tries to run the other ndk-build commend which is used for linux and is missing some commands as uname.
Do you have any idea what cI could be doing wrong ?
The original question is asking about ant builds. This answer is related to a problem in CC.NET and ant and gradle builds are going to be affected in the same way.
We are using gradle and with some custom gradle tasks it is possible to compile the native code of your project as well by calling ndk-build.cmd (from a path that has no spaces in it).
After the gradle file is prepared properly shell initiated gradle builds will work but cc.net initiated builds will fail.
Our CC.NET task is defined as follows:
<exec executable=".\gradlew.bat">
<baseDirectory>$(projSrcDir)</baseDirectory>
<buildArgs>clean assemblePlayRelease assembleProRelease</buildArgs>
<buildTimeoutSeconds>900</buildTimeoutSeconds>
</exec>
The problem is related to a CC.NET bug that causes the shell variable names to be in lower case. Windows shell scripts do not care about the case of shell variable names but because the NDK fires up make variable case becomes an issue. The init.mk make file that is part of the build process relies on shell variable names to identify the host OS type. In particular the shell variable OS. Normally the OS value is defined like this:
OS=Windows_NT
But when the variable is passed to gradle from CC.NET it gets transformed into this:
os=Windows_NT
This causes the detection mechanism in init.mk to fail and tries to execute the unix detection sequence and looks for the Unix uname utility that is not present on Windows resulting in:
Android NDK: Unable to determine HOST_OS from uname -s:
Android NDK: Please define HOST_OS in your environment.
make.exe: Entering directory `D:/CC.NET/svncheckout/pes/src/project/src/main/jni'
make.exe: Leaving directory `D:/CC.NET/svncheckout/pes/src/project/src/main/jni'
And ultimately:
process_begin: CreateProcess(NULL, uname -s, ...) failed.
c:/ndk/build/core/init.mk:160: *** Android NDK: Aborting. . Stop.
FAILURE: Build failed with an exception.
The workaround is less then ideal but it gets the job done. The idea is to edit the ndk-build.cmd and change the case of the passed variables only when we are building from CC.NET.
Simply insert this code after the #echo off line in ndk-build.cmd:
IF DEFINED ccnetproject (
ECHO Applying Environment variable hack for CC.NET.
SET OS2=%os%
SET OS=
REM SET PATH=%path%
SET TEMP2=%temp%
SET TEMP=
)
IF DEFINED ccnetproject (
SET OS=%OS2%
SET OS2=
SET TEMP=%TEMP2%
SET TEMP2=
)
This script first makes temporary copies of values in the lower case OS and TEMP variables. Next it undefines them by clearing their values. An finally the reverse is done.
Two steps are needed because just saying
SET OS=%os%
doesn't do much since scripts are case insensitive. It first locates the OS variable, finds a lower case version and assigns its own value back to itself.
This was tested on CC.NET v1.6.7981.1, gradle v1.1.0 and Android NDK v10 (64bit).

passing option to ant in cruisecontrol

I have following code in config.xml file:
<schedule interval = "300">
<ant anthome="/usr/share/ant"
antworkingdir="${GitDir}"
uselogger="true"
usedebug="true"/>
</schedule>
And when I execute build through it, I am just getting output, like I've been typing just ant in command line.
I need to be able to execute following command from Cruisecontrol:
ant debug
If this is making any difference, I need to be able to build android application.
How this can be done?
Thank you on advance.
You're already using the right attributes in your config.xml to start your ant scripts with loglevel debug
...
usedebug="true"
...
is equivalent to ant -debug ...
see http://cruisecontrol.sourceforge.net/main/configxml.html#ant for details.

Resources