MSBuild ignoring CLToolExe property in project file - visual-c++

I'm trying to compile Python 2.7 with clang on Windows. I thought a solution to doing this would be to specify the properties CLToolPath and CLToolExe. However, when I set these properties in the project files, msbuild seems to just ignore them and continue using the Microsoft compiler.
The weird thing is that when I specify those properties on the command line, msbuild does actually pick them up. (But due to other aspects of the way Python 2.7 is set up, the build doesn't actually succeed that way, so it doesn't solve the problem. It just proves these are the right properties.)
This is the relevant section of a project file
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<Link>
<SubSystem>Console</SubSystem>
</Link>
<ClCompile>
<CLToolPath>C:\llvm\build\Release\bin</CLToolPath>
<CLToolExe>clang-cl.exe</CLToolExe>
</ClCompile>
</ItemDefinitionGroup>
And this is the command line I'm using
msbuild /t:clean,build /p:Configuration=Release /p:TrackFileAccess=false /p:Platform="x64" /fileLogger pcbuild.sln
Any idea what could be causing the properties to be ignored?

You're putting it to a wrong place. Find relevant PropertyGroup tag and add <CLToolExe> and <CLToolExe> to it as follows:
<PropertyGroup>
<CLToolExe>clang-cl.exe</CLToolExe>
<CLToolPath>C:\llvm\build\Release\bin</CLToolPath>
</PropertyGroup>

Related

CMake autogenerated files missing includes CMAKE_C_INCLUDE_PATH and CMAKE_CXX_INCLUDE_PATH

I have a complex build I'm trying to sort out on a new build server. Using CMake for creating the makefiles. Old version of CMake on a different server was 2.8.5. New version is 2.8.12.2. For some reason, the autogenerated CMakeDirectoryInformation.cmake files are missing the CMAKE_C_INCLUDE_PATH and CMAKE_CXX_INCLUDE_PATH, which specify the absolute location of the include headers available to that particular directory. Without that information, the source code in that directory that references headers via a local path (such as foo.h versus ../../../asdf/foo.h) won't compile. Any ideas why these are missing? As far as I can tell this is supposed to be autogenerated by CMake.
I found a useful command that got me further into my build:
SET(CMAKE_INCLUDE_DIRECTORIES_BEFORE ON)
But that didn't actually solve my problem. The real issue was that in one of my CMakeLists.txt files I had:
include_directories(
$[XXXX_INCLUDE_DIR}
)
The '[' bracket was causing the build to fail because that include directory was not being used. However, on the old build server, it had no issue with this square bracket.

Scons missing builtin Builder for "Jar"

I'm using an (admittedly aged) version of Scons (2.0.1; upgrading possible but might be difficult), and I'm having trouble with the "Jar" builder. Specifically, it isn't available, and I don't know why. The "JavaClassFile" builder is available and works correctly, but it can't build my jar, failing with this error:
scons: Reading SConscript files ...
AttributeError: 'SConsEnvironment' object has no attribute 'Jar':
File "/home/fred/comms/SConstruct", line 183:
envWithJava.Jar(target='util/myproject.jar', source=['util/myproject.class', 'util/jasypt.jar', 'util/bcprov-ext-jdk15on-152.jar', 'util/Manifest.txt'])
The relevant SConstruct excerpt:
env.Jar(target='util/myproject.jar', source=['util/myproject.class', 'util/jasypt.jar', 'util/bcprov-ext-jdk15on-152.jar', 'util/Manifest.txt'])
"BUILDERS:" from env.Dump() does not list "Jar", but has numerous others, and builds C, C++, Flex and other sources fine.
I'm mainly looking for a way to debug what's happening inside of Scons to make it skip the builder. The jar command is in the same dir as javac, and that builder works, so it doesn't seem path related. The Python files that have the Jar references are present in the lib used by Scons.
Any ideas?
My guess is that you either have no "jar" executable installed (can you call it on the command line?), or it's located in a path that hasn't been properly propagated to your Environment. See also #1 of the "most asked FAQs" at http://scons.org/wiki/FrequentlyAskedQuestions and the very java-specific bug report at http://scons.tigris.org/issues/show_bug.cgi?id=2730 .

How to make debug build of specific module under AOSP tree?

I built eng flavor of AOSP tree and installed on a device. I like to step through code of a module (say libinput.so). I want to build this module with "-O0 -g" passed as part of CFLAGS. BUT I don't want to change the Android.mk file of this module.
Lets say this module is at aosppath/frameworks/base/service/input.
I cd to this folder after sourcing build/envsetup.sh.
I tried "mm -B LOCAL_STRIP_MODULE=false". When I was stepping through eclipse gdb, I see the execution order going zig zag.
Then I tried "mm -B LOCAL_STRIP_MODULE=false LOCAL_CFLAGS="-O0 -g""
Now gdb was able to step through fine. But this doesn't seem to work in other projects. I have a module that uses skia and opengl. The build is failing when I pass LOCAL_CFLAGS on command line.
What is the suggested way to make debug flavor of specific .so or exe under AOSP tree?
Thanks
So since the main reason you don't want to make changes to Android.mk is so you don't have to check it in, an alternative here is to use the .repo/local_manifests folder to change a module that is owned by android to be owned by you.
Here is a sample my_manifest.xml file which can do this for you:
<manifest>
<remote name="origin"
fetch="ssh://git#github.com/YourRepoHere/" />
<remove-project name="platform/frameworks/base"/>
<project path="frameworks/base" remote="origin" name="frameworks-base" revision="your-branch-name"/>
</manifest>
This will remove frameworks/base from the android manifest tree, and replace it with your own manifest tree (which you need to fork into your own repository).
After that, you can then use a conditional inside of your Android.mk file like so:
ifeq ($(TARGET_BUILD_VARIANT),userdebug)
CONDITIONAL_CHANGES_HERE
endif
Again, I realize that you didn't want to modify the Android.mk file but since you also asked for the suggested way of making a module that is conditional on the build variant, I am going to include this answer anyway in case nothing better comes your way. This is really the suggested way of doing what you want to do, as your project will now be maintained by the repo tool.

Building a solution to multiple architectures into the same folder in TFS 2012

We have a solution that we would like built against two architectures (x86 and x64) and put in the same folder on build. The solution has four projects, three of which we are outputting as AnyCPU, since they are called by the fourth project and thus will take on whatever bitness it is running under.
I have already gone into the csproj file and changed it like so:
<Choose>
<When Condition=" '$(Platform)'=='x64' ">
<PropertyGroup>
<AssemblyName>TaskLoaderHost64</AssemblyName>
</PropertyGroup>
</When>
<When Condition=" '$(Platform)'=='x86' ">
<PropertyGroup>
<AssemblyName>TaskLoaderHost32</AssemblyName>
</PropertyGroup>
</When>
</Choose>
Additionally I set the OutputPath for all cominations of Platform and Configuration to \bin\Debug or \bin\Release (removing the architecture portion). When building in Visual Studio, I set Architecture to x86, build taskloaderhost project, set to x64, build, and in the bin\debug folder I have one copy each of the three AnyCPU project outputs and one each of x86 and x64 TaskLoaderHost outputs. This is exactly what I want. Everything in the same folder.
Moving this to TFS, I created a Build Definition that builds the TaskLoaderHost project in both x86 and x64 flavors. And instead of the above, I get the following at the drop location root.
\
\logs
\x64
\x64\Debug
\x86
\x86\Debug
Where did the extra directories come from? Specifying OutDir in MSBuildArguments does nothing, and TFS seems to ignore the OutputPath property (but it does read the Assembly Name property) from the csproj file.
Anyone know a way to force it to put output from two different architectures in the same directory?
Interesting Fact
If you do not specify OutputPath in the project file, TFS complains about the fact that it is undefined, and refuses to output it. If you do specify it, TFS does not use that value in the Drop location filesystem structure.
I found the following article on MSDN that describes how this can be done, and I have it working on my TFS Build Server. It is written against TFS 2010, but works well enough for 2012 as well.
Control Where the Build System Places Your Binaries
Essentially what you do is edit the BuildTemplate and Project definitions (csproj/vbproj/etc) that are being built.
In the Build Template, edit the Run MSBuild found at this location:
Process > Sequence > Run On Agent > Try Compile Test and Associate Changesets and Work Items> Sequence > Compile, Test, and Associate Changesets and Work Items > Try Compile and Test > Compile and Test > For Each Configuration in BuildSettings.PlatformConfigurations > Compile and Test for configuration > If BuildSettings.HasProjectsToBuild > For Each Project in BuildSettings.ProjectsToBuild > Try to Compile the Project > Compile the Project > Run MSBuild for Project.
Remove the value in the OutDir property, and put the following into the CommandLineArguments property: String.Format("/p:SkipInvalidConfigurations=true;TeamBuildOutDir=""{0}"" {1}",
BinariesDirectory, MSBuildArguments)
Finally place the following after the other conditional property groups in your Project file:
<PropertyGroup Condition="$(TeamBuildOutDir) != '' ">
<OutputPath>$(TeamBuildOutDir)\$(SolutionName)\$(MSBuildProjectName)\$(Configuration)</OutputPath>
</PropertyGroup>
I changed the OutputPath on mine a little. Since I am building a single project which has the other projects as dependencies, I only had to put the above PropertyGroup in a single project file.

How do I fix MSB3073 error in my post-build event?

I'm working on a project that requires that DLLs generated by building my solution to be copied from the bin folder to another folder, both of which are on my machine, in my C drive. I've written a batch file that uses xcopy to accomplish this, which you can see here:
xcopy /s /y /q "C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.dll" "C:\inetpub\wwwroot\AppServer\bin\"
xcopy /s /y /q "C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.pdb" "C:\inetpub\wwwroot\AppServer\bin\"
Now, I've tried numerous iterations of this file, which is located at:
C:\Users\scogan\Desktop\CopyFiles.bat
so my post-build event command line looks like this:
call C:\Users\scogan\Desktop\CopyFiles.bat
I've run this batch file on its own with two text files in folders on my desktop, and it works fine. I've also run it as it is with the files I need to copy on its own, and that works fine, too. However, when I try to run this as a post-build event, I get this output:
1> Organizr -> C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Client\bin\Debug\Organizr.exe
1> File not found - Organizr.Services.dll
1> 0 File(s) copied
1> 0 File(s) copied
1> File not found - Organizr.Services.pdb
1>c:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(4291,5): error MSB3073: The command "call C:\Users\scogan\Desktop\CopyFiles.bat" exited with code 4.
I've done some research, and found that error code 4 means that "Initialization error occurred. There is not enough memory or disk space, or you entered an invalid drive name or invalid syntax on the command line."
I've also looked up what MSB3073 is, and haven't really found much that can help me there. So, my question is what am I doing wrong? Are the absolute paths messing it up? Any help here is appreciated.
Playing around with different project properties, I found that the project build order was the problem. The project that generated the files I wanted to copy was built second, but the project that was running the batch file as a post-build event was built first, so I simply attached the build event to the second project instead, and it works just fine. Thanks for your help, everyone, though.
Prefer the MsBuild "Copy" task in an AfterBuild target over a post-build event.
Append this Target into your project file and remove the PostBuildEvent.
<Target Name="AfterBuild">
<Copy SourceFiles="C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.*"
DestinationFolder="C:\inetpub\wwwroot\AppServer\bin\"
OverwriteReadOnlyFiles="true"
SkipUnchangedFiles="false" />
</Target>
For what it's worth, the problem in my case was caused by using '/' as the directory separator in a copy command. Must use backslashes.
In my case, the dll I was creating by building the project was still in use in the background. I killed the application and then xcopy worked fine as expected.
The specified error is related to the post built event. Somehow VS tool is not able to copy the files to the destination folder. There can be many reasons for it. To check the exact error cause go to Tools > Option> Project and Solution > Built and run, and change "MsBuild project build output verbosity" to "Diagnostic". It will give you enough information to detect the actual problem.
This is too late but posting my experience for people looking at it later:-
In MS VS 2010 I had the same issue. It got resolved by putting quotes to post build copy command args which contained spaces!
In Project Properties --> Configuration Properties --> Build Events --> Post-Build Event --> Command Line change:
copy $(ProjectDir)a\b\c $(OutputPath)
to
copy "$(ProjectDir)a\b\c" "$(OutputPath)"
If the problem still persists even after putting the after build in the correct project try using "copy" instead of xcopy. This worked for me.
The Post-Build Event (under Build Events, in the properties dialog) of an imported project, had an environment variable which was not defined.
Navigated to Control Panel\All Control Panel Items\System\Advanced system settings to add the appropriate environment variable, and doing no more than restarting VS2017 resolved the error.
Also, following on from #Seans and other answers regarding multiple project races/contentions, create a temp folder in the output folder like so,
and select the project producing the preferred output:
and build (no rebuild/clean) is a speedy solution.
Following thing you should do before to run copy command if you facing some issue with copy command
open solution as a administrator and build the solution.
if you have problem like "0 File(s) copied" check you source and destination path. might you are using wrong path. it would be better if you run the same command in "command prompt" to check whether it is working fine or not.
I solved it by doing the following:
In Visual studio I went in Project -> Project Dependencies
I selected the XXX.Test solution and told it that it also depends on the XXX solution to make the post-build events in the XXX.Test solution not generate this error (exit with code 4).
I've found the issue happens when you have multiple projects building in parallel and one or more of the projects are attempting to copy the same files, creating race conditions that will result in occasional errors. So how to solve it?
There's a lot of options, as above just changing things around could solve the issue for some people. More robust solutions would be...
Restrict the files being copied i.e. instead of xcopy $(TargetDir)*.*"... instead do xcopy "$(TargetDir)$(TargetName).*"...
Catch the error and retry i.e:
:loop
xcopy /Y /R /S /J /Q "$(TargetDir)$(TargetName).*" "somewhere"
if ErrorLevel 1 goto loop
Use robocopy instead of xcopy
You probably won't want to do this as it will increase your build times, but you could reduce the maximum number of parallel project builds to 1 ...
I had the same problem for my Test project. I found out why my post build event wasn't working and that's because I was copying files before running the $(ProjectName).exe command and some of these files were required for Test project itself. Hence, by just moving $(ProjectName).exe as the first command fix the issue.
I faced this issue recently and surprisingly only i was having this problem and none of my team members were facing this issue when building the project code.
On debugging i found that my code directory had spacing issue , It was D:\GIT Workspace\abc\xyz.
As a quick fix i changed it to D:\GITWS\abc\xyz and it solved the problem.
I was getting this error after downloading some source code from Github. Specifically the rust oxide development framework. My problem is that the Steam.ps1 script file, that's used to update some of the dlls from Steam was blocked by the OS. I had to open the files properties an UNBLOCK it. I had not realized this was done to ps1 files as well as exes.
In my case a setting mismatch between Project's Configuration Properties->General->Output Directory setting and Linker->General->Output Directory.
There was a warning about it during linking.
I was facing a similar issue where it said it cannot copy a DLL from my build location to destination. The issue was my project path contained spaces, removing them the error was gone.

Resources