Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7711077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:17:07+00:00 2026-06-01T01:17:07+00:00

How can I get the Variables.save to save all variables, and not just the

  • 0

How can I get the Variables.save to save all variables, and not just the one specified by the user. I want to make sure that future runs of scons use exactly the same setup.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T01:17:08+00:00Added an answer on June 1, 2026 at 1:17 am

    Sadly there is no way to do this using core SCons functions. The decision on whether to save a variable value or not is hard-wired into Save, and only values that are not the defaults can be saved.

    However, you can save all variables by abusing the not-well-documented “converter” function. It ain’t pretty, but does the job.

    When you call Variables.Save(), it calls each variable’s converter function and checks the result to see if it is the same as the default (input) value. If you return something that is not the input value when called from Save then all values are stored in the cache file. Elsewhere you need the converter to return the input value as-is, or it would use incorrect variable values.

    def save_all(value, env=None):
        import traceback
        # if called in Save method, return non-default
        for line in traceback.format_stack():
            lines = line.splitlines()
            if lines[0].endswith('Save'):
                return value + 'save'
        # return correct value otherwise
        return value
    
    import SCons
    var = Variables("config.py", ARGUMENTS)
    
    # AddVariables accepts tuples of:
    # Variable key, description, default-value, validator, converter
    var.AddVariables(
        ('CC', 'The C Compiler', 'cc', None, save_all),
        ('CFLAGS', 'Flags to pass to compiler', '-Wall', None, save_all))
    
    env = Environment(tools=[], variables=var)
    var.Save('config.py', env)
    
    print 'CC', env['CC']
    print 'CFLAGS', env['CFLAGS']
    

    Here the function save_all is the hack. It uses the stack trace to check if it is called from within Save. If it is, then it returns a tampered value, otherwise it returns the input value unchanged. You can check the result of this example in the cache file “config.py”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I get a list of all the defined variables in
I want to save the name of all the $_GET variables in a url,
How can I get Environnment variables and if something is missing, set the value?
I've played around quite a bit now, and can't seem to get variables to
I can't figure out how to get the SCOPE_IDENTITY() back to my variables from
I'm trying to access a member structs variables, but I can't seem to get
Given this variable in tcsh: set i = ~/foo/bar.c how can I get just
I just can't seem to figure this one out... As far as I know,
I can not seem to figure out what I'm missing could you all give
I have an app that allows the user to take and save a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.