0

In my C++ project I have a (large) number of .foo files that get transformed into .bar files using a custom build step that runs foo2bar on the .foo file.

The resultant .bar output file is not further used in any build steps. It is however used when running the c++ project(s) executable output.

The problem here is that the .foo files handle their own internal nested #include-like handling of dependant files. And this messes up the custom build step. It's not just .foo => .bar It's .foo + (a ton of includes derived from the .foo contents) => .bar

I basically want the custom build step to ALWAYS run the build command, and let the foo2bar compiler figure out if the output .bar is up to date or not. How to do that ?

tried:

  1. the "simple" solution seems to be to list ALL the include dependencies in the custom build step. This is pretty much a no-go, managing and maintaining this manually is not feasible.
  2. setting the output to neverExists.bleh This works, it always triggers a build. But then you get an error at the end that the output was never created. 2b) you can solve that by setting the Custom Build Step flag 'Verify Dependencies and outputs exist' to NO... But when building the solution on Azure build agents, it can't detect build errors and the builds are erroneously passing when they shouldn't. The return value of foo2bar.exe (i.e. errorlevel) is ignored (local build seems to handle this ok). Any error messages are ignored (local build catches these from the console output).

How do you make a vc++ project run a "custom compiler that has its own include dependency handling" on project source files ? It doesn't have to be a custom build step per se.

8
  • For approach #1 are you able to use a recursive wildcard match, i.e. **\*.foo? Commented Jun 26 at 19:59
  • Could i confirm with you that what do you mean ` want the custom build step to ALWAYS run the build command`? And did you use DevOps pipeline to build the project that went wrong? Please share some screenshots of reproducing the issue to help us better understand this scenario. Commented Jun 27 at 9:07
  • Not sure what you mean by wildcard match... and how to do that in VS2022 build step. But no... the includes have an assortment of different extensions, and come from multiple include folders not below the project root.
    – oreubens
    Commented Jun 27 at 12:13
  • confirming what i want... I want to ALWAYS have MsBuild call the foo2bar compiler on the .foo file, so that foo2bar can figure out if the output is up to date or needs rebuilding. With outfile.bar defined as output, as soon as .bar is there and more recent than the .foo, MSBuild assumes it's up to date and skips the actual build command. Even if some of the include files are more recent and require a recompile of foo to bar.
    – oreubens
    Commented Jun 27 at 12:16
  • Since you ask "How do you...", here's my story. We use a CMake project to generate Visual Studio project; the CMake project is the source of truth, vcproj is just for convenience. In our case, the custom build tool is protoc, Google protobuf compiler. protoc has --dependency_out option that dumps a transitive list of imports to a file. So we have a CMake script that runs protoc in that mode on every source .proto file, extracts the list of dependencies, and adds them as additional inputs for that .proto Commented Jun 28 at 0:06

1 Answer 1

0

If you want to ALWAYS have MsBuild call custom build step, here is a workaround:

Simply specify some non-existent file in Outputs , and the custom build step will always run. It will run even if your project is up-to-date, since the Output file is never found.

For example

<ItemDefinitionGroup>
  <CustomBuildStep>
    <Command>xxxx</Command>
    <Outputs>$(TargetName).missing</Outputs>
    <Inputs>xxxx</Inputs>
  </CustomBuildStep>
</ItemDefinitionGroup>

Hope it can help.

6
  • Yes, see my OP (tried, 2nd). This solution has issues.
    – oreubens
    Commented Jul 11 at 15:26
  • The problem of this method is that it can't detect build errors when building on Azure agents. So what you ultimately want to do is building your solution using a devops pipeline that includes tasks? if yes, what are the tasks? Commented Jul 12 at 6:20
  • I thought this was obvious from the OP. The task is build VS solution. Which are c++ projects, making dlls and exes. Some of the steps needed for making the exes is compiling Foo files into bar files (which are then included as resources)
    – oreubens
    Commented Jul 13 at 15:47
  • OK. If you use the VSBuild task (for example), have you set the msbuildArgs input in the build task, such as /p:WarningLevel? You can also use logFileVerbosity to create a log file to check what happened during build. Commented Jul 15 at 9:39
  • and how does changing warning level change anything about custom build steps ? Setting log verbosity won't help either, I know what the problem is. I need a way to force/override a (re)build regardless of whether msbuild "thinks" the ouput is up to date, while having a correctly set output target.
    – oreubens
    Commented Jul 15 at 12:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.