Discussion:
[Scons-users] Environment clones linked?
Daniel Moody
2018-05-25 03:33:58 UTC
Permalink
I am trying to clone an environment and then make changes to the clone so
that it is different than the original.

But somehow changing the clone also changes my original env? Is that
expected behavior?

Below is an example SConstruct which reproduces the issue (SCons 3.01
installed from pip on windows 10):

env1 = Environment()
env2 = env1.Clone()

print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)

print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)

Which produces this output:

C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.

Can someone shed some light on if this is a bug or how do I uniquely modify
the SHLINKCOM?
Bill Deegan
2018-05-25 03:54:34 UTC
Permalink
So you're reaching into an Action defined in a builder.
That's pretty far inside the Environment to a level that there's not a deep
copy of it.

This when using mslink right?

shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK
$SHLINKFLAGS $_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB
$_SHLINK_SOURCES", "$SHLINKCOMSTR")}', '$SHLINKCOMSTR')

regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")

embedManifestDllCheckAction = SCons.Action.Action(embedManifestDllCheck, None)

compositeShLinkAction = shlibLinkAction + regServerCheck +
embedManifestDllCheckAction

env['SHLINKCOM'] = compositeShLinkAction


In this case I'd expect the Clone copy/deep copying logic would yield what
you are seeing.
If you did this:

env2['SHLINKCOM'] = SCons.Action.Action("echo link command env2",None) +
env2['SHLINKCOM'].list[1] + env2['SHLINKCOM'].list[2]

Then it shouldn't modify env1..
-Bill
Post by Daniel Moody
I am trying to clone an environment and then make changes to the clone so
that it is different than the original.
But somehow changing the clone also changes my original env? Is that
expected behavior?
Below is an example SConstruct which reproduces the issue (SCons 3.01
env1 = Environment()
env2 = env1.Clone()
print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)
print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)
C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
Can someone shed some light on if this is a bug or how do I uniquely
modify the SHLINKCOM?
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Daniel Moody
2018-05-25 04:23:03 UTC
Permalink
Thanks that worked!

I didn't understand how deep Clone went. Originally I tried to modify the
Action command directly because I didn't want to mess with the other
actions for the SHLINKCOM.
Post by Bill Deegan
So you're reaching into an Action defined in a builder.
That's pretty far inside the Environment to a level that there's not a
deep copy of it.
This when using mslink right?
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}', '$SHLINKCOMSTR')
regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
embedManifestDllCheckAction = SCons.Action.Action(embedManifestDllCheck, None)
compositeShLinkAction = shlibLinkAction + regServerCheck + embedManifestDllCheckAction
env['SHLINKCOM'] = compositeShLinkAction
In this case I'd expect the Clone copy/deep copying logic would yield what
you are seeing.
env2['SHLINKCOM'] = SCons.Action.Action("echo link command env2",None) +
env2['SHLINKCOM'].list[1] + env2['SHLINKCOM'].list[2]
Then it shouldn't modify env1..
-Bill
Post by Daniel Moody
I am trying to clone an environment and then make changes to the clone so
that it is different than the original.
But somehow changing the clone also changes my original env? Is that
expected behavior?
Below is an example SConstruct which reproduces the issue (SCons 3.01
env1 = Environment()
env2 = env1.Clone()
print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)
print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)
C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
Can someone shed some light on if this is a bug or how do I uniquely
modify the SHLINKCOM?
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Jonathon Reinhart
2018-05-25 14:25:41 UTC
Permalink
We've fought this exact issue before as well: Modifications to Actions
or ActionLists affect all environments.

The key, as Bill explained, is to leverage the indirection that the
environments provide via the *COM variables. In our case, we actually
append to the action lists in the environments.


Jonathon
Post by Daniel Moody
Thanks that worked!
I didn't understand how deep Clone went. Originally I tried to modify the
Action command directly because I didn't want to mess with the other actions
for the SHLINKCOM.
Post by Bill Deegan
So you're reaching into an Action defined in a builder.
That's pretty far inside the Environment to a level that there's not a
deep copy of it.
This when using mslink right?
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS
$_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES",
"$SHLINKCOMSTR")}', '$SHLINKCOMSTR')
regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
embedManifestDllCheckAction = SCons.Action.Action(embedManifestDllCheck, None)
compositeShLinkAction = shlibLinkAction + regServerCheck +
embedManifestDllCheckAction
env['SHLINKCOM'] = compositeShLinkAction
In this case I'd expect the Clone copy/deep copying logic would yield what
you are seeing.
env2['SHLINKCOM'] = SCons.Action.Action("echo link command env2",None) +
env2['SHLINKCOM'].list[1] + env2['SHLINKCOM'].list[2]
Then it shouldn't modify env1..
-Bill
Post by Daniel Moody
I am trying to clone an environment and then make changes to the clone so
that it is different than the original.
But somehow changing the clone also changes my original env? Is that
expected behavior?
Below is an example SConstruct which reproduces the issue (SCons 3.01
env1 = Environment()
env2 = env1.Clone()
print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)
print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)
C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
Can someone shed some light on if this is a bug or how do I uniquely
modify the SHLINKCOM?
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Bill Deegan
2018-05-25 15:01:26 UTC
Permalink
Any thoughts on how better to document this?
More verbiage under Clone()

You're already in the deep end of the pool when you're doing this kind of
SCons code though..

On Fri, May 25, 2018 at 9:25 AM, Jonathon Reinhart <
Post by Jonathon Reinhart
We've fought this exact issue before as well: Modifications to Actions
or ActionLists affect all environments.
The key, as Bill explained, is to leverage the indirection that the
environments provide via the *COM variables. In our case, we actually
append to the action lists in the environments.
Jonathon
Post by Daniel Moody
Thanks that worked!
I didn't understand how deep Clone went. Originally I tried to modify the
Action command directly because I didn't want to mess with the other
actions
Post by Daniel Moody
for the SHLINKCOM.
Post by Bill Deegan
So you're reaching into an Action defined in a builder.
That's pretty far inside the Environment to a level that there's not a
deep copy of it.
This when using mslink right?
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS
$_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES",
"$SHLINKCOMSTR")}', '$SHLINKCOMSTR')
regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
embedManifestDllCheckAction = SCons.Action.Action(
embedManifestDllCheck,
Post by Daniel Moody
Post by Bill Deegan
None)
compositeShLinkAction = shlibLinkAction + regServerCheck +
embedManifestDllCheckAction
env['SHLINKCOM'] = compositeShLinkAction
In this case I'd expect the Clone copy/deep copying logic would yield
what
Post by Daniel Moody
Post by Bill Deegan
you are seeing.
env2['SHLINKCOM'] = SCons.Action.Action("echo link command env2",None) +
env2['SHLINKCOM'].list[1] + env2['SHLINKCOM'].list[2]
Then it shouldn't modify env1..
-Bill
Post by Daniel Moody
I am trying to clone an environment and then make changes to the clone
so
Post by Daniel Moody
Post by Bill Deegan
Post by Daniel Moody
that it is different than the original.
But somehow changing the clone also changes my original env? Is that
expected behavior?
Below is an example SConstruct which reproduces the issue (SCons 3.01
env1 = Environment()
env2 = env1.Clone()
print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)
print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)
C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
Can someone shed some light on if this is a bug or how do I uniquely
modify the SHLINKCOM?
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Jonathon Reinhart
2018-05-25 18:28:25 UTC
Permalink
Yes a friendly warning might be helpful, pointing out that Clone() is
not a totally deep-clone, and that specifically Action objects remain
linked.

You might also consider going on to say that the correct way to
manipulate the way Actions work on a per-environment basis is to
manipulate the *COM variables which the Actions reference.
Post by Bill Deegan
Any thoughts on how better to document this?
More verbiage under Clone()
You're already in the deep end of the pool when you're doing this kind of
SCons code though..
On Fri, May 25, 2018 at 9:25 AM, Jonathon Reinhart
Post by Jonathon Reinhart
We've fought this exact issue before as well: Modifications to Actions
or ActionLists affect all environments.
The key, as Bill explained, is to leverage the indirection that the
environments provide via the *COM variables. In our case, we actually
append to the action lists in the environments.
Jonathon
Post by Daniel Moody
Thanks that worked!
I didn't understand how deep Clone went. Originally I tried to modify the
Action command directly because I didn't want to mess with the other actions
for the SHLINKCOM.
On Thu, May 24, 2018 at 11:54 PM, Bill Deegan
Post by Bill Deegan
So you're reaching into an Action defined in a builder.
That's pretty far inside the Environment to a level that there's not a
deep copy of it.
This when using mslink right?
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK $SHLINKFLAGS
$_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES",
"$SHLINKCOMSTR")}', '$SHLINKCOMSTR')
regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
embedManifestDllCheckAction =
SCons.Action.Action(embedManifestDllCheck,
None)
compositeShLinkAction = shlibLinkAction + regServerCheck +
embedManifestDllCheckAction
env['SHLINKCOM'] = compositeShLinkAction
In this case I'd expect the Clone copy/deep copying logic would yield what
you are seeing.
env2['SHLINKCOM'] = SCons.Action.Action("echo link command env2",None) +
env2['SHLINKCOM'].list[1] + env2['SHLINKCOM'].list[2]
Then it shouldn't modify env1..
-Bill
Post by Daniel Moody
I am trying to clone an environment and then make changes to the clone so
that it is different than the original.
But somehow changing the clone also changes my original env? Is that
expected behavior?
Below is an example SConstruct which reproduces the issue (SCons 3.01
env1 = Environment()
env2 = env1.Clone()
print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)
print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)
C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
Can someone shed some light on if this is a bug or how do I uniquely
modify the SHLINKCOM?
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Bill Deegan
2018-05-25 18:35:33 UTC
Permalink
Pull request? ;)

On Fri, May 25, 2018 at 1:28 PM, Jonathon Reinhart <
Post by Jonathon Reinhart
Yes a friendly warning might be helpful, pointing out that Clone() is
not a totally deep-clone, and that specifically Action objects remain
linked.
You might also consider going on to say that the correct way to
manipulate the way Actions work on a per-environment basis is to
manipulate the *COM variables which the Actions reference.
Post by Bill Deegan
Any thoughts on how better to document this?
More verbiage under Clone()
You're already in the deep end of the pool when you're doing this kind of
SCons code though..
On Fri, May 25, 2018 at 9:25 AM, Jonathon Reinhart
Post by Jonathon Reinhart
We've fought this exact issue before as well: Modifications to Actions
or ActionLists affect all environments.
The key, as Bill explained, is to leverage the indirection that the
environments provide via the *COM variables. In our case, we actually
append to the action lists in the environments.
Jonathon
Post by Daniel Moody
Thanks that worked!
I didn't understand how deep Clone went. Originally I tried to modify the
Action command directly because I didn't want to mess with the other actions
for the SHLINKCOM.
On Thu, May 24, 2018 at 11:54 PM, Bill Deegan
Post by Bill Deegan
So you're reaching into an Action defined in a builder.
That's pretty far inside the Environment to a level that there's not
a
Post by Bill Deegan
Post by Jonathon Reinhart
Post by Daniel Moody
Post by Bill Deegan
deep copy of it.
This when using mslink right?
shlibLinkAction = SCons.Action.Action('${TEMPFILE("$SHLINK
$SHLINKFLAGS
Post by Bill Deegan
Post by Jonathon Reinhart
Post by Daniel Moody
Post by Bill Deegan
$_SHLINK_TARGETS $_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES",
"$SHLINKCOMSTR")}', '$SHLINKCOMSTR')
regServerAction = SCons.Action.Action("$REGSVRCOM", "$REGSVRCOMSTR")
embedManifestDllCheckAction =
SCons.Action.Action(embedManifestDllCheck,
None)
compositeShLinkAction = shlibLinkAction + regServerCheck +
embedManifestDllCheckAction
env['SHLINKCOM'] = compositeShLinkAction
In this case I'd expect the Clone copy/deep copying logic would yield what
you are seeing.
env2['SHLINKCOM'] = SCons.Action.Action("echo link command
env2",None)
Post by Bill Deegan
Post by Jonathon Reinhart
Post by Daniel Moody
Post by Bill Deegan
+
env2['SHLINKCOM'].list[1] + env2['SHLINKCOM'].list[2]
Then it shouldn't modify env1..
-Bill
Post by Daniel Moody
I am trying to clone an environment and then make changes to the
clone
Post by Bill Deegan
Post by Jonathon Reinhart
Post by Daniel Moody
Post by Bill Deegan
Post by Daniel Moody
so
that it is different than the original.
But somehow changing the clone also changes my original env? Is that
expected behavior?
Below is an example SConstruct which reproduces the issue (SCons
3.01
Post by Bill Deegan
Post by Jonathon Reinhart
Post by Daniel Moody
Post by Bill Deegan
Post by Daniel Moody
env1 = Environment()
env2 = env1.Clone()
print("env2 before = " + env1['SHLINKCOM'].list[0].cmd_list)
env2['SHLINKCOM'].list[0].cmd_list = "echo link command env2"
print("env2 after = " + env1['SHLINKCOM'].list[0].cmd_list)
print("env1 = " + env2['SHLINKCOM'].list[0].cmd_list)
C:\Users\Daniel\workspace>scons -f SConstruct.py
scons: Reading SConscript files ...
env2 before = ${TEMPFILE("$SHLINK $SHLINKFLAGS $_SHLINK_TARGETS
$_LIBDIRFLAGS $_LIBFLAGS $_PDB $_SHLINK_SOURCES", "$SHLINKCOMSTR")}
env2 after = echo link command env2
env1 = echo link command env2
scons: done reading SConscript files.
scons: Building targets ...
scons: `.' is up to date.
scons: done building targets.
Can someone shed some light on if this is a bug or how do I uniquely
modify the SHLINKCOM?
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
_______________________________________________
Scons-users mailing list
https://pairlist4.pair.net/mailman/listinfo/scons-users
Loading...