-1

Is there a runtime variable that can be checked during tree generation if the scons -c flag has been provided?

Additional Context:

Suppose you have a Sconscript that generates a target "TARG" which can be built, and it is convenient when building TARG to also check a couple filesystem things, create a directory, copy in some files.

For annoying unrelated reasons, we don't have the option of adding the SCons "Copy" operation to the TARG build tree, so we want to just add 'def do_prepare_output_directory(): ...`.

Only problem is we don't want to do this in the case of scons -c TARG. What should I do to confirm that we're doing a regular build command and not a clean command?

  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 25 '22 at 23:50
  • I'm not entirely get what are you asking. Do you want `-c` to remove less things? It looks like asking to detect `-c` flag maybe be the XY problem (https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Could you maybe provide the MRE? https://stackoverflow.com/help/minimal-reproducible-example – Piotr Siupa Jul 26 '22 at 06:33
  • Fair criticism @NO_NAME - it may indeed be that this question is a bit themed toward asking about my naive solution as opposed to the problem, but to be fair it seemed worthwhile that the question "how can a scons script programmatically check if a clean operation is being executed" be asked somewhere on StackOverflow I think – shuriken_alley Jul 26 '22 at 17:51
  • @shuriken_alley I'm concerned that for example the operations you want to stop when `-c` is passed will break something unless they are done during an actual build of the program. If this is the case, there are other ways than `-c` to run SCons without performing a build. There is the option `--help`, you can specify only a single file to built in the command line, etc. – Piotr Siupa Jul 26 '22 at 17:59

2 Answers2

1

To know if you're in clean mode, use GetOption("clean")

Mats Wichmann
  • 800
  • 6
  • 6
-1

Sounds like you want this:

env.Clean(target, files or directories)

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

Also why can't you add the mkdir and copy?

Just use AddPostAction() to the builder which creates the target in question.

bdbaddog
  • 3,357
  • 2
  • 22
  • 33
  • This AddPostAction() option seems like a good solution for my particular use case – shuriken_alley Jul 26 '22 at 19:26
  • @bdbaddog Stack Overflow has a strict policy that an answer should attempt to solve the question. You answer was useful for the OP but it still doesn't tell how to detect the flag `-c`. This should be a comment instead. (https://meta.stackoverflow.com/questions/275121/good-answers-but-not-to-the-question-asked) I was even considering flagging it as "not an answer" but I decided a downvote is enough. (Also, you shouldn't ask questions in the answer. This is also what comments are for.) – Piotr Siupa Jul 28 '22 at 12:40