Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

python - How to put validation logic as dependency on SCONS target

I have a simple, yet non obvious requirement to a build process on SCONS.

I need to enter the following command:

scons release [version]

Expected results

What this should do is:

  1. Activate a target called release.
  2. Capture the parameter passed soon after the release parameter.
  3. As part of the target, execute a function. If the parameter passed after the release targed is valid, call another targed.
  4. If it is not valid, interrupt the workflow and show an error message.

Problem

I have no idea how to set this up

My current hypothesis would be:

  1. Create a custom builder with two actions.
  2. First action should be a python function that somehow would be able to stop the process in case its logic so decides.
  3. Second action should be invoking the default builder, because if the first action decides it is ok to go ahead, the default builder should be executed.
  4. Create a target pointing to this custom builder called release.

What I need to do is kind of create a workflow where some logic is executed as part of a target and decides if another one should or should not be executed.

But I don't know if it is doable the way I am thinking, and I miss some knowledge I don't know where to get:

  1. The "release" target is not an input file. It is instead a trigger to execut a workflow composed of different actions. How do I tell SCONS that "release" parameter is not a file?
  2. How do I capture the next parameter typed soon after the "release" parameter? This is the release number and shall be used by the "release" target to validate stuff. Pseldocode would be:
def releaseTarget(wantedRelease):
  if wantedTarget == "":
    interruptHere()
  1. How do I interrupt the workflow, so as to prevent the next action from being executed?
  2. How do I chain the default action as the next action in the workflow?

I would like some pointers on where I should start looking for this kind of functionality on scons.

question from:https://stackoverflow.com/questions/65859394/how-to-put-validation-logic-as-dependency-on-scons-target

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The SCons way to do this would be to use Variables. That would lead to invoking as:

scons release VERSION=1.2.3

Variables are covered in SCons docs here:

For release you'd use an Alias docs here

If you're going to be doing anything beyond trivial with SCons, it's probably worth a thorough read of the users guide and manpage.

Also, please join us on our discord server for help, or the users mailing list, or the IRC channel details here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...