less --global-var seems not working - less

I'm using less in a JEE project. Compiling less files is via an ant script.
I want to generate multiple versions of bootstrap (and some others less files) with a different color scheme.
So, my script have some :
<antcall target="lessfile">
<param name="file.name.less" value="bootstrap.less" />
<param name="file.name.css" value="bootstrap-orange.css" />
<param name="brand-primary" value="#F44336" />
</antcall>
At the end of the script, I launch compilation via the line:
<arg line="-x ${file.name.less} ${dir.css}/${file.name.css} --global-var='my-background=${brand-primary}'" />
This command line itself poses no worries. The problem is to retrieve the value of 'my-background'.
In the bootstrap file, I do a simple test:
.test {
color : #my-background;
}
And the compilation fails, stating that he does not know the #my-background variable ("variable # my-background is undefined"), as if the argument specifying the global variable was ignored.
Can you explain to me how I can get my global variable value?
Thank you in advance for your answer.
(PS : i have lessc 1.4.2 )

Related

Does file(GENERATE) resolve variables?

I am trying to generate a file, but it fails to resolve variables. Since file(generate) runs during the generate step, are there limitations to what variables it can resolve? (e.g. only cache variables?)
My variables don't get resolved despite them being defined.
message("Registered composites: ${COURAGE_COMPOSITES}")
file(GENERATE OUTPUT ${OUTPUT_PATH}/output.xml INPUT ${INPUT_PATH}/output.xml.in)
output.xml.in
<imports>
$<$<NOT:$<STREQUAL:"${COURAGE_COMPOSITES}","">>:<import iuts="yes"$<ANGLE-R>$<JOIN:${COURAGE_COMPOSITES},</import$<ANGLE-R><import iuts="yes"$<ANGLE-R>></import$<ANGLE-R>>
</imports>
output.xml
<imports>
<import iuts="yes">${COURAGE_COMPOSITES}</import>
</imports>
Actually, file(GENERATE) doesn't expand variables at all.
Documentation for that command tells nothing about variable's expansion
Generate an output file for each build configuration supported by the current CMake Generator. Evaluate generator expressions from the input content to produce the output content.
If you want to expand variables, you could firstly expands them with command configure_file into intermediate file, and then expand generator expressions in that file using file(GENERATE):
# output.xml.in -> output.xml.im
configure_file(${INPUT_PATH}/output.xml.in ${OUTPUT_PATH}/output.xml.im)
# output.xml.im -> output.xml
file(GENERATE OUTPUT ${OUTPUT_PATH}/output.xml INPUT ${OUTPUT_PATH}/output.xml.im)
Alternatively, if your input file is small, you could embed it into the CMakeLists.txt as a string, and use CONTENT parameter for file(GENERATE):
file(GENERATE OUTPUT ${OUTPUT_PATH}/output.xml CONTENT
[=[
<imports>
$<$<NOT:$<STREQUAL:"${COURAGE_COMPOSITES}","">>:<import iuts="yes"$<ANGLE-R>$<JOIN:${COURAGE_COMPOSITES},</import$<ANGLE-R><import iuts="yes"$<ANGLE-R>></import$<ANGLE-R>>
</imports>
]=]
)
In that case the variable substitution will be performed by CMake itself before it passes the string to the command.

Can MSBuild ItemGroup's be chunked?

I've got an ItemGroup that includes source files from my project:
<ItemGroup>
<SourceFiles Include=".\**\*.h;.\**\*.cpp"/>
</ItemGroup>
There are a few hundred source files. I want to pass them to a command line tool in an Exec task.
If I call the command line tool individually for each file:
<Exec Command="tool.exe %(SourceFiles.FullPath)" WorkingDirectory="."/>
Then, it runs very slowly.
If I call the command line tool and pass all of the files in one go:
<Exec Command="tool.exe #(SourceFiles -> '"%(FullPath)"', ' ')" WorkingDirectory="."/>
Then, I get an error if there are too many files (I'm guessing the command line length exceeds some maximum).
Is there a way I can chunk the items so that the tool can be called a number of times, each time passing up to a maximum number of source file names to the tool?
I'm not aware of any mechanism to do that with well known item metadata. What you could do is load all those paths into their own item group and write a custom task that calls the exec task. Writing a custom task is pretty simple, it can be done inline:
http://msdn.microsoft.com/en-us/library/vstudio/dd722601(v=vs.100).aspx

How to split a string and use it inside a for loop in ant script?

I am having a list of machine ips in a ant property.
<property name="machines" ip="10.10.10.1;10.10.10.2;10.10.10.3"/>
I have to copy one file to all the machines(all the machines are windows machines). So I want to split this string and to use it inside a for loop. Inside that forloop i will execute the copy command.
<exec executable="cmd.exe">
<pre>
</pre>
<arg line="/C COPY /Y sample.txt \\${machine_ip}\Shared_folder\sample.txt"/>
<pre>
</pre>
</exec>
Now how to split and use it inside for loop?
Easiest way is to use the ant-contrib features
<for list="10.10.10.1;10.10.10.2" delimiter=";" param = "val">
<sequential>
<echo message = "val = #{val}"/>
</sequential>
</for>
If you can't use ant-contrib, an alternative would be to write your own custom Ant task to split the string and execute your command for each token.
Alternatively, since you are executing a Windows-specific command anyway, you could do the split/loop logic in a batch script and exec that, passing the whole properties string.

How to redirect input for customaction execommand

I'm trying to setup a custom action to initialize my SQLite database using the sqlite3.exe command line tool. In a command prompt I type the following: c:\sqlite3.exe database.db < sqlscript.sql
My Wix custom action falls apart in the ExeCommand attribute because I cannot seem to escape out the <.
<CustomAction Id="InitializeDatabase" FileKey="SQLiteEXE" ExeCommand="database.db < sqlscript.sql" Execute.../>
I've tried "&lt" as well.
I know I could just install an empty initiailzed database but I'm curious how to redirect inputs.
Thanks.
So, what exactly is happening when you say it falls apart? Does it compile?
Just so that we're on the same page, are you ending you XML entity with the semi-colon. You probably are, but it didn't come through in your code sample. Are you using:
<
If that doesn't work, you could try putting the command into a property and using CDATA tags, such as:
<Property Id="MyCommand">
<![CDATA[
database.db < sqlscript.sql
]]>
</Property>
and using that in the ExeCommand attribute:
ExeCommand="[MyCommand]"
That might work.
If you really have to call an EXE, I reccomend using the WiX QuietExec Custom Action pattern. Worse case you could install a .BAT file then use the cmd /c foo.bat command to call it. Then you wouldn't have to escape the <.
Otherwise I would search for an alternative to the EXE. I try to stick with data driven custom actions that run in process ( say C++ or C#/DTF ).
Quiet Execution Custom Action

Error using MSBuild tokens in PropertyGroup

I am trying to setup some properties that I use multiple times in my MSBuild script. I have the following property section:
<PropertyGroup>
<BuildDependsOn>$(BuildDependsOn); MyAfterBuild </BuildDependsOn>
<SubstitutionsFilePath>$(ProjectDir)app.config.substitutions.xml </SubstitutionsFilePath>
<AppConfig>$(TargetPath).config</AppConfig>
<HostConfig>$(TargetDir)$(TargetName).vshost.exe.config</HostConfig>
</PropertyGroup>
When I run this I get the following error:
The expression "#(TargetPath).config" cannot be used in this context. Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists.
I don't understand this error, as the use of the $(BuildDependsOn) and $(ProjectDir) work fine. And I know the $(TargetXXX) values generate properly as when I put them directly into the Tasks section below, they work fine.
The reason for this problem is that TargetDir is defined as an item list, not a property; presumably to cater to the scenario where your outputs are distributed amongst several output directories?
I came up against this same problem and managed to work around it by using the $(OutDir) property instead of $(TargetDir).
(The OutDir property is defined in Microsoft.Common.Targets (lines 100-102) as a normalised version of the OutputPath defined in your project file.)
First try running your build with the /v:diag option, which will output a lot more information and give you a clue as to what part of the build is failing.
A clue might be in the Microsoft.Common.targets file (located in %SystemRoot%\Microsoft.NET\Framework\v2.0.50727) in the PrepareForBuild target:
<!--
These CreateProperty calls are required because TargetDir and TargetPath are defined
to contain an item list. We want that item list to be expanded so that it can be used
as a regular property value and not as an item-list-with-transform.
-->
<CreateProperty Value="$(TargetDir)">
<Output TaskParameter="Value" PropertyName="TargetDir" />
</CreateProperty>
<CreateProperty Value="$(TargetPath)">
<Output TaskParameter="Value" PropertyName="TargetPath" />
</CreateProperty>
To me this looks like a bug, you can report it at https://connect.microsoft.com/feedback/Search.aspx?SiteID=210.