0

I ask my question in such a specific way because I am afraid that a more generic form could lead to excessively theoretic discussions of how the things should be done best and in the most appropriate way (like a question about pre and post-process actions in SCons).

WPP incorporation actually requires execution of an additional command (commands) before compilation of a file and only even if the build process finds necessity to compile the file without any regard to WPP.

I would remark that this is easily achieved with few lines of definitions in a shared Visual Studio property page file making this work for multiple files in multiple projects, folders, etc. in an absolutely transparent for developers way.

Thus I am wondering whether this can be done in a similarly simple way with SCons? I do not have any deep knowledge of either SCons or MSBuild frameworks; I work with them for simple practical use so I would truly appreciate a practical and useful advise.

Mtm 3.14
  • 29
  • 5
  • Can you add a link to info about Windows WPP software? I have no idea what that is – bdbaddog May 07 '20 at 21:33
  • Answering @bdbaddog: a simple Google search for "WPP Tracing" brings a lot of information, including [this](https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/wpp-software-tracing). But the question is not truly WPP related; it's about putting a command before compile action that can use selected parameters of the compile command and is executed only if the compilation is required (so it's not a builder or anything else self-sufficient). – Mtm 3.14 May 12 '20 at 10:52
  • If you're asking for help it's usually better to provide all of the contextual info so people willing to help don't have to expend a lot of extra time trying to find out what you are asking about. Thus my request. You can edit your question and stick a link to the relevant info there. – bdbaddog May 12 '20 at 18:22
  • You wanted to exclude pre actions it seemed like, but from this description they sound rather appropriate as they are only applied if the target is first concluded to be out of date. – Mats Wichmann May 12 '20 at 18:24
  • A couple of clarifications in an attempt to express myself better. First of all, I am talking about the default SCons coming out of the box. Now, suggest I would like to extend it. If it finds that a source file should _not_ be recompiled (i.e. its object file is up to date), nothing additional is necessary. If it decides to compile a source file, say. I want it to execute a command _before_ the actual compilation, and, as a POC. let the command to simply echo the file's source path and target path. Obviously, the less work to do, the better solution. – Mtm 3.14 May 12 '20 at 18:54

1 Answers1

1

Here's what I'd suggest.

SCons builds command lines from Environment() variables. For example the compile command line for building shared object for c++ is stored in SHCXXCOM (and the variable for what is displayed to user when the command is run defaults to SHCXXCOM, but can be changed by modifying SHCXXCOMSTR).

Back to the problem at hand. Assuming you have a limited number of build steps you want to wrap, you can do something like.

env['SHCXXCOM'] = [ 'MPP PRE COMMAND LINE', env['SHCXXCOM'], 'MPP POST COMMAND LINE']

You'll have to figure out which variables you need to do this with, but take a look at the manpage to figure that out.

https://scons.org/doc/production/HTML/scons-man.html

p.s. I've not tried this, but in theory it should work. Let us know if not.

bdbaddog
  • 3,357
  • 2
  • 22
  • 33
  • Thanks for the suggestion. It looks like it works the way I need and is much simpler than the way I found while waiting for an answer. But appetite comes with eating: I would like to make the pre-compile optional (say, depending on an environment variable). One way is to implement the pre-compile command to do this. A bit ugly. The second way is to put a function as the pre-compile command. Works but SCons expect the function to _execute_ the command. A bit complicated. Is there a way to use a command generator function as the pre-compile command? – Mtm 3.14 May 13 '20 at 10:45
  • No. Command generators aren't run right before the command is executed. If you want to make it optional do you mean globally, or not for all compiles? – bdbaddog May 14 '20 at 14:32
  • To @bdbaddog:I am dealing with a huge legacy project thus any visible behavior alternation is much unwelcome. So optionally means for targets that explicitly want this extension, e.g by adding a special parameter to the builder method call. A function instead of the string command solves this since the optional logic can be put there. Two drawbacks: 1) Dealing with Actions explicitly (create/execute in the function while I would prefer to minimize 'Pythonish' code), and 2) The pre-compile action is always printed to the log even if it does nothing by its inner logic - scary for old users. – Mtm 3.14 May 14 '20 at 16:26
  • @Mtm3.14 - Here's what I'd do. have a second env you use for such and populate the actions in that env with the pre and post command. That way not a lot needs to change. Call it wpp_env. Then you can just swap out the env you use to build whatever with wpp_env. Simple and not to intrusive. – bdbaddog May 15 '20 at 19:08
  • To @bdbaddog: Yes, it sounds like a really decent and fair solution.It can become a bit inconvenient in a case of _few_ optional pre-compile actions although this approach still can be used. Nevertheless, it perfectly match the originally described necessities.Thanks a lot for really helpful ideas. – Mtm 3.14 May 18 '20 at 08:58
  • Glad to be of help! If you believe this answers your question, please mark this response as the solution. Keep in mind that you can mix build steps and environments, but don't build the same target with two different environments as SCons will warn or error depending on how different the Environment()'s are. If you have additional requirements/constraints, please update your question and I'll try to amend my answer if possible. – bdbaddog May 19 '20 at 17:19