QMake: test functions do not work as expected - qt

In QtCreator 4.2.0 I try to use one *.pro file for building binaries for multiple hardware configurations.
In Build & Run => Build Settings => Build Enviroment I define the enviroment variable TARGET like as follows:
Build Settings A: Variable TARGET has Value bbb
Build Settings B: Variable TARGET has Value desktop
In the pro-file I use the following test functions:
equals($$TARGET,"bbb")
{
message("setting include paths for bbb"))
message($$TARGET)
}
equals($$TARGET,"laptop")
{
message("setting include paths for laptop.")
message($$TARGET)
}
contains($$TARGET,"*bbb*")
{
message("setting include paths for bbb"))
message($$TARGET)
}
contains($$TARGET,"*laptop*")
{
message("setting include paths for laptop.")
message($$TARGET)
}
And I get this output when running qmake:
Project MESSAGE: setting include paths for bbb
Project MESSAGE: bbb
Project MESSAGE: setting include paths for laptop.
Project MESSAGE: bbb
Project MESSAGE: setting include paths for bbb
Project MESSAGE: bbb
Project MESSAGE: setting include paths for laptop.
Project MESSAGE: bbb
Project MESSAGE: setting include paths for bbb
This makes no sense to me an I can't figure what I'm doing wrong here. Why are the parts after testing fro laptop executed?
By the way, I solved my problem by using Scopes. This works perfect for me:
CONFIG += $$(TARGET_HW)
desktop {
message("setting include paths for laptop.")
}
cetec {
message("setting include paths for cetec."))
}
But I'm still interested in the correct way of using test functions.

I provide the correct syntax for the first test, as an example:
equals(TARGET,"bbb") {
message("setting include paths for bbb"))
message($$TARGET)
}
Please notice:
The curly brace is on the same line of the test.
The variable tested has no dollar signs, just the variable name

The opening brace must written on the same line as the condition (https://doc.qt.io/qt-5/qmake-language.html#scope-syntax).

There are so many issues in your question, that there is place for another answer, adding to the previous correct ones:
as #daru says, you need to open the brace in the same line as the test function.
as #p-a-o-l-o says, contains and equals syntax require variable names as first arguments, without $$.
TARGET is an internal variable, that contains the base name of the project file by default. It becomes the name of the executable or library you are building.
You may use an environment variable named TARGET, but then you should assign it to a qmake variable name with another name.
sample code:
TGT=$$(TARGET)
equals(TGT,"bbb") {
message("$$TGT equals bbb"))
message(TGT=$$TGT)
}
equals(TGT,"laptop") {
message("$$TGT equals laptop")
message(TGT=$$TGT)
}
contains(TGT,"bbb") {
message("$$TGT contains bbb"))
message(TGT=$$TGT)
}
contains(TGT,"top") {
message("$$TGT contains top")
message(TGT=$$TGT)
}

Related

File Should Exist is not recognizing filepath

I'm using the File Should Exist keyword to check for an existing file in a List.
This is the high-level format:
Variables:
#{Files} /Desktop/Other/scooby.txt
... /Desktop/DummyFiles/daffy.txt
... %{CURDIR}/mickey.txt
Test Case:
Given File Should Exist ${Files[0]}
[...]
Output:
Setup failed:
Path '/Desktop/Other/scooby.txt' does not exist.
I'm not sure why this happens. The file name and filepath are correct. I also tried a bunch of different combinations (I copied the file over to the subdirectory this script is running from but that also doesn't work). I tried making the filepath a scalar variable instead of a List/array. Adding ".." in front of the file path doesn't work either. I've looked into "Glob pattern" but I don't think that's the issue either.
Always use absolute paths if in doubt. For example - /Desktop/Other/scooby.txt Does not point to any "meaningful" path even on windows because its lacking the the drive. On windows, using C:/Users/$yourlocalusername/Desktop/Other/scooby.txt might be working (replace $yourlocalusername with correct value)
Relying on relative paths (like in your example, 2 first ones are relative even thought you start with /, because in windows you still have a drive at the start) - you will need to ensure that working directory is set to a specific directory before you run your suite. Now, if you run your suite via IDE, current working directory might not be what you expect it to be so before you are familiar with how relative & absolute paths work - prefer to use absolute paths. See https://www.computerhope.com/issues/ch001708.htm - maybe that will clear out your issue.
You can either use ${CURDIR} or do not start the relative path with '/'.
I guess when starting with '/' , RF does not take this as relative path input and try to map the address from root directory i.e. C:
In below example, I have demonstrated both the approach, and it works fine for me.
*** Settings ***
Library OperatingSystem
Documentation Demonstrating File Exist keywords
*** Variables ***
#{Files} Data/VariableData/ConditionalFlows.robot
... Data/VariableData/testdata.robot
#{Files2} ${CURDIR}/Data/VariableData/ConditionalFlows.robot
... ${CURDIR}/Data/VariableData/testdata.robot
*** Test Cases ***
TS002-Check For File Existence
[Documentation] File exists
${File} File Should Exist ${Files}[0]
${File} File Should Exist ${Files2}[0]

How to add a logic to .pro file based on configuration?

In my application (qmake based) I have 2 configuration, let's say CONF1 and CONF2.
Each configuration defines "Additional arguments" at Project/Build settings/Build step tab:
DEFINES+=CONF1
and
DEFINES+=CONF2
So in C++ code I can add some specified logic for specified build configuration:
#if defined CONF1
logo->setPixmap(QPixmap("conf1.png"));
#else
logo->setPixmap(QPixmap("conf2.png"));
#endif
Also I need to define icon for the application executable.
So in .pro file I've added:
win32 {
RC_ICONS = logo.ico
}
But the problem that I need different icons for different configuration.
I've tried:
contains(DEFINES, CONF1) {
RC_ICONS = conf1.ico
}
else {
RC_ICONS = conf2.ico
}
but that doesn't work. It looks that contains works only for variables defined inside .pro file only.
So my question - how can I add different settings (icons in my case) for different configuration?
As far as I'm aware qmake can't evaluate variables set in the DEFINES list, but only qmake variables.
However, you can use a qmake variable to perform both tasks at the same time. Just assign the "conf" value to your variable, evaluate that variable to add it to the DEFINES list and then test its value using qmake functions (e.g. equals).
As an example:
Add the following to your additional qmake arguments (including quotes):
"MYCONF = CONF1"
Then use these directives in your .pro file:
DEFINES += $${MYCONF}
equals(MYCONF, "CONF1") {
RC_ICONS = conf1.ico
} else {
RC_ICONS = conf2.ico
}

scss-lint.yml is not working

I got small problem with scss-lint, I am trying to run in a simple file and after changes in the scss-lint.yml , still not loading my config.
scss file: _headlines.scss
// Headlines
%headline-primary {
#include rem-size(60px);
color: palette(grey, light);
font-weight: $font-weight--book;
line-height: $line-height-base;
margin-top: 0;
}
scss-lint.yml
# Default application configuration that all configurations inherit from.
scss_files: "scss/**/*.scss"
plugin_directories: ['.scss-linters']
# List of gem names to load custom linters from (make sure they are already
# installed)
plugin_gems: []
# Default severity of all linters.
severity: warning
linters:
ColorKeyword:
enabled: false
ColorVariable:
enabled: false
command line used:
scss-lint scss/_headlines.scss
file sctrucute:
scss/_headlines.scss:5:1 [W] TrailingWhitespace: Line contains trailing whitespace
scss/_headlines.scss:5:18 [W] ColorKeyword: Color `grey` should be written in hexadecimal form as `#808080`
scss/_headlines.scss:5:18 [W] ColorVariable: Color literals like `grey` should only be used in variable declarations; they should be referred to via variable everywhere else.
scss/_headlines.scss:9:1 [W] FinalNewline: Files should end with a trailing newline
ColorKeyword is defined as false in my scss-lint.yml but still runing someone know what is happen?
In the scss-lint documentation, the following is specified:
Configuration
scss-lint loads configuration in the following order of precedence:
Configuration file specified via the --config flag
Configuration from .scss-lint.yml in the current working directory, if it exists
Configuration from .scss-lint.yml in the user's home directory, if it exists
All configurations extend the default configuration.
There is no .scss-lint.yml in your current working directory, scss-lint-test. Therefore, it will be using the default configuration.
To solve this, either move your YML file into scss-lint-test, or run scss-lint from the scss folder.

premake5 precompiled headers not working

(this is using Premake5 alpha binary available for download on website)
I'm trying to port my existing VS solution over to using premake5.
It uses MS style precompiled headers(stdafx.h/stdafx.cpp).
When I specify this is my test project:
pchheader "stdafx.h"
pchsource "stdafx.cpp"
It does set the project to using precompiled headers, but it is not setting stdafx.cpp to generate precompiled headers(/Yc). Instead all the files in the project are trying to use(/Yu) and nobody is generating the PCH. So it does not build..
I'm guessing this does works somehow, what black magic am I missing here?
Here is my entire premake5 file for reference
-- premake5.lua
solution "Cloud"
configurations { "Debug", "Release", "Final" }
platforms { "Win32_AVX2", "Win64_AVX2"}
location "premake"
flags{"MultiProcessorCompile", "ExtraWarnings", "FatalCompileWarnings", "FatalLinkWarnings", "FloatFast"}
startproject "Cloud"
vectorextensions "AVX2"
filter { "platforms:Win32" }
system "Windows"
architecture "x32"
filter { "platforms:Win64" }
system "Windows"
architecture "x64"
filter "configurations:Debug"
defines { "DEBUG" }
flags { "Symbols" }
filter "configurations:Release"
defines { "NDEBUG" }
flags{"Symbols"}
optimize "Speed"
filter "configurations:Final"
defines { "NDEBUG" }
flags{"LinkTimeOptimization"}
optimize "Speed"
group "app"
--primary executable
project "Cloud"
location "../src_test/cloud"
kind "ConsoleApp"
language "C++"
targetdir "..//%{cfg.buildcfg}"
pchheader "stdafx.h"
pchsource "stdafx.cpp"
vpaths{
{["src/pch/*"] = "../src_test/cloud/stdafx.*"},
{["src/*"] = "../src_test/cloud/**.cpp"},
{["module/*"] = "../src_test/cloud/Module*.h"},
{["core/*"] = "../src_test/cloud/Core*.h"},
{["headers*"] = "../src_test/cloud/*.h"},
--{["src_c/*"] = "../src_test/cloud/**.c"}
}
files { "../src_test/cloud/*.h", "../src_test/cloud/*.c", "../src_test/cloud/*.cpp", "../src_test/cloud/*.hpp" }
One related question: how do I disable precompiled header usage on specific files within a project? Some of my files will not build if the PCH is included, so I have manually disabled them in the existing solution/projects.
Thanks!
It's probably because pchsource requires a file path (like files) Since your stdafx.cpp is not in the same directory as your script, Premake does not find it. Try using pchsource "../src_test/cloud/stdafxcpp" instead, it should fix the problem.
Also I see that you don't add "../src_test/cloud/" as an include directory, so that means that your pch header will be included using relative path, right ? If so, you'll need to update pchheader to reflect that. Due to the way Visual Studio works, you need to set pchheader as it appears in your cpp files. E.g. if in your cpp files you have #include "../src_test/cloud/stdafx.h" you need to use this in Premake: pchheader "../src_test/cloud/stdafx.h".
And finally, to deactivate precompiled headers on certain files, you can use filters:
-- deactivate precompiled headers for C files
filter "files:**.c"
flags { "NoPCH" }
I am changing a script from premake 4 to premake 5 and I had some troubles to deactivate pch on a specific file with :
filter "files:myfile.cpp"
flags { "NoPCH" }
It was disabling pch on the whole project and not on a specific file.
But it was because pchsource and pchheader were defined after the filtering.
When we flag a file with no PCH, pchsource and pchheader have to be defined first.

Does sbt have something like gradle's processResources task with ReplaceTokens support?

We are moving into Scala/SBT from a Java/Gradle stack. Our gradle builds were leveraging a task called processResources and some Ant filter thing named ReplaceTokens to dynamically replace tokens in a checked-in .properties file without actually changing the .properties file (just changing the output). The gradle task looks like:
processResources {
def whoami = System.getProperty( 'user.name' );
def hostname = InetAddress.getLocalHost().getHostName()
def buildTimestamp = new Date().format('yyyy-MM-dd HH:mm:ss z')
filter ReplaceTokens, tokens: [
"buildsig.version" : project.version,
"buildsig.classifier" : project.classifier,
"buildsig.timestamp" : buildTimestamp,
"buildsig.user" : whoami,
"buildsig.system" : hostname,
"buildsig.tag" : buildTag
]
}
This task locates all the template files in the src/main/resources directory, performs the requisite substitutions and outputs the results at build/resources/main. In other words it transforms src/main/resources/buildsig.properties from...
buildsig.version=#buildsig.version#
buildsig.classifier=#buildsig.classifier#
buildsig.timestamp=#buildsig.timestamp#
buildsig.user=#buildsig.user#
buildsig.system=#buildsig.system#
buildsig.tag=#buildsig.tag#
...to build/resources/main/buildsig.properties...
buildsig.version=1.6.5
buildsig.classifier=RELEASE
buildsig.timestamp=2013-05-06 09:46:52 PDT
buildsig.user=jenkins
buildsig.system=bobk-mbp.local
buildsig.tag=dev
Which, ultimately, finds its way into the WAR file at WEB-INF/classes/buildsig.properties. This works like a champ to record build specific information in a Properties file which gets loaded from the classpath at runtime.
What do I do in SBT to get something like this done? I'm new to Scala / SBT so please forgive me if this seems a stupid question. At the end of the day what I need is a means of pulling some information from the environment on which I build and placing that information into a properties file that is classpath loadable at runtime. Any insights you can give to help me get this done are greatly appreciated.
The sbt-buildinfo is a good option. The README shows an example of how to define custom mappings and mappings that should run on each compile. In addition to the straightforward addition of normal settings like version shown there, you want a section like this:
buildInfoKeys ++= Seq[BuildInfoKey](
"hostname" -> java.net.InetAddress.getLocalHost().getHostName(),
"whoami" -> System.getProperty("user.name"),
BuildInfoKey.action("buildTimestamp") {
java.text.DateFormat.getDateTimeInstance.format(new java.util.Date())
}
)
Would the following be what you're looking for:
sbt-editsource: An SBT plugin for editing files
sbt-editsource is a text substitution plugin for SBT 0.11.x and
greater. In a way, it’s a poor man’s sed(1), for SBT. It provides the
ability to apply line-by-line substitutions to a source text file,
producing an edited output file. It supports two kinds of edits:
Variable substitution, where ${var} is replaced by a value. sed-like
regular expression substitution.
This is from Community Plugins.

Resources