[Scons-users] Substitution of Literal() broken when using Python 3

Bill Deegan bill at baddogconsulting.com
Sun May 20 13:07:11 EDT 2018


Could you submit such as a pull request on github?

Thanks,
Bill
SCons Project co-manager.

On Sun, May 20, 2018 at 11:54 AM, Philipp Maierhöfer <maiphi.public at gmx.net>
wrote:

> Hi all,
>
> note: this problem has been discussed on the mailing lists before, see
> https://pairlist2.pair.net/pipermail/scons-dev/2017-June/004297.html, but
> as of today it hasn't been fixed in the master branch and I didn't find a
> corresponding issue in the bug tracker. In the following I propose a fix.
>
> To reproduce the problem, create a SConstruct with the content
> """
> Command('PHONY', '', 'echo $_RPATH', RPATH=Literal('\$$ORIGIN'))
> """
> and run it with SCons with Python 3 (I tested with 3.6.5). This leads to
> the error
> scons: *** [PHONY] TypeError `unhashable type: 'Literal'' trying to
> evaluate `${_concat(RPATHPREFIX, RPATH, RPATHSUFFIX, __env__)}'.
>
> Note that with Python 2.7 it works fine.
>
> A solution that works for me is to add a __hash__ method to the class
> SCons.Subst.Literal:
> """
> diff --git a/src/engine/SCons/Subst.py b/src/engine/SCons/Subst.py
> index 68d247f8..b0abf613 100644
> --- a/src/engine/SCons/Subst.py
> +++ b/src/engine/SCons/Subst.py
> @@ -78,6 +78,9 @@ class Literal(object):
>      def is_literal(self):
>          return 1
>
> +    def __hash__(self):
> +        return hash(self.lstr)
> +
>      def __eq__(self, other):
>          if not isinstance(other, Literal):
>              return False
> """
>
> I don't know why the Literal needs to be hashable in Python 3 but not in
> Python 2. And I cannot decide if the above patch is a viable solution or if
> the problem should be addressed somewhere else.
>
> A workaroud on the user side (in your SConstruct) may look like this:
> """
> import SCons
> class HashableLiteral(SCons.Subst.Literal):
>     def __hash__(self):
>         return hash(self.lstr)
> """
> Then use HashableLiteral instead of Literal.
>
> Cheers,
> Philipp
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20180520/42abeca2/attachment.html>


More information about the Scons-users mailing list