diff options
author | Mats Wichmann <mats@linux.com> | 2018-08-19 15:21:13 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2020-05-01 14:31:57 (GMT) |
commit | b890f5fcdfc79795533cae7b7cd1bf05cb82c527 (patch) | |
tree | 0d540e996d5a73d674442612737addf8ae9ea123 /src/engine/SCons | |
parent | db16f4557b7c816cba466f2e009930017e4aac72 (diff) | |
download | SCons-b890f5fcdfc79795533cae7b7cd1bf05cb82c527.zip SCons-b890f5fcdfc79795533cae7b7cd1bf05cb82c527.tar.gz SCons-b890f5fcdfc79795533cae7b7cd1bf05cb82c527.tar.bz2 |
Use uuid lib for Visual Studio guids
In the Visual Studio area, use uuid (Python standard library)
to generate GUID identifiers instead of specifically using md5.
Simplifies things as uuid lib can provide already formatted strings
of the form that we need.
This is split off from PR #3447 by request.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'src/engine/SCons')
-rw-r--r-- | src/engine/SCons/CacheDir.py | 1 | ||||
-rw-r--r-- | src/engine/SCons/Tool/msvs.py | 41 | ||||
-rw-r--r-- | src/engine/SCons/Tool/packaging/msi.py | 8 | ||||
-rw-r--r-- | src/engine/SCons/Util.py | 2 |
4 files changed, 33 insertions, 19 deletions
diff --git a/src/engine/SCons/CacheDir.py b/src/engine/SCons/CacheDir.py index 117f6b0..9982555 100644 --- a/src/engine/SCons/CacheDir.py +++ b/src/engine/SCons/CacheDir.py @@ -27,7 +27,6 @@ __doc__ = """ CacheDir support """ -import hashlib import json import os import stat diff --git a/src/engine/SCons/Tool/msvs.py b/src/engine/SCons/Tool/msvs.py index e5c9bd0..1fda9e1 100644 --- a/src/engine/SCons/Tool/msvs.py +++ b/src/engine/SCons/Tool/msvs.py @@ -34,7 +34,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import SCons.compat import base64 -import hashlib +import uuid import ntpath import os import pickle @@ -77,6 +77,21 @@ def processIncludes(includes, env, target, source): return [env.Dir(i).abspath for i in SCons.PathList.PathList(includes).subst_path(env, target, source)] +# Work-in-progress +# individual elements each get a globally unique identifier. +# however, there also are some "well known" guids that either +# represent something, or are used as a namespace to base +# generating guids that should be "in" the namespace +#NAMESPACE_PROJECT = uuid.UUID("{D9BD5916-F055-4D77-8C69-9448E02BF433}") +#NAMESPACE_SLN_GROUP = uuid.UUID("{2D0C29E0-512F-47BE-9AC4-F4CAE74AE16E}") +#NAMESPACE_INTERNAL = uuid.UUID("{BAA4019E-6D67-4EF1-B3CB-AE6CD82E4060}") + +# Kinds of projects, as used in solution files +#PROJECT_KIND_C = "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}" +#PROJECT_KIND_PCL = "{786C830F-07A1-408B-BD7F-6EE04809D6DB}" +#NAMESPACE_PRJ_FOLDER = "{66A26720-8FB5-11D2-AA7E-00C04F688DDE}" +#NAMESPACE_SLN_FOLDER = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}" +#NAMESPACE_TEST = "{3AC096D0-A1C2-E12C-1390-A8335801FDAB}" def processFlags(flags, env): """ @@ -91,21 +106,23 @@ def processFlags(flags, env): external_makefile_guid = '{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}' +def _generateGUID(slnfile, name, namespace=external_makefile_guid): + """Generates a GUID for the sln file to use. + + The uuid5 function is used to combine an existing namespace uuid - + the one VS uses for C projects (external_makedile_guid) - + and a combination of the solution file name (slnfile) and the + project name (name). We just need uniqueness/repeatability. + + Returns (str) "displayable" GUID, already wrapped in braces + """ -def _generateGUID(slnfile, name): - """This generates a dummy GUID for the sln file to use. It is - based on the MD5 signatures of the sln filename plus the name of - the project. It basically just needs to be unique, and not - change with each invocation.""" - m = hashlib.md5() # Normalize the slnfile path to a Windows path (\ separators) so # the generated file has a consistent GUID even if we generate # it on a non-Windows platform. - m.update(bytearray(ntpath.normpath(str(slnfile)) + str(name),'utf-8')) - solution = m.hexdigest().upper() - # convert most of the signature to GUID form (discard the rest) - solution = "{" + solution[:8] + "-" + solution[8:12] + "-" + solution[12:16] + "-" + solution[16:20] + "-" + solution[20:32] + "}" - return solution + slnfile = ntpath.normpath(str(slnfile)) + solution = uuid.uuid5(uuid.UUID(namespace), "%s-%s" %(slnfile, name)) + return '{' + str(solution).upper() + '}' version_re = re.compile(r'(\d+\.\d+)(.*)') diff --git a/src/engine/SCons/Tool/packaging/msi.py b/src/engine/SCons/Tool/packaging/msi.py index 9f28b72..defb5c6 100644 --- a/src/engine/SCons/Tool/packaging/msi.py +++ b/src/engine/SCons/Tool/packaging/msi.py @@ -161,7 +161,7 @@ def generate_guids(root): To handle this requirement, the uuid is generated with an md5 hashing the whole subtree of a xml node. """ - from hashlib import md5 + import uuid # specify which tags need a guid and in which attribute this should be stored. needs_id = { 'Product' : 'Id', @@ -175,10 +175,8 @@ def generate_guids(root): node_list = root.getElementsByTagName(key) attribute = value for node in node_list: - hash = md5(node.toxml()).hexdigest() - hash_str = '%s-%s-%s-%s-%s' % ( hash[:8], hash[8:12], hash[12:16], hash[16:20], hash[20:] ) - node.attributes[attribute] = hash_str - + hash = uuid.uuid5(uuid.NAMESPACE_URL, node.toxml()) + node.attributes[attribute] = str(hash) def string_wxsfile(target, source, env): diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 588d02f..07cdad9 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -1538,7 +1538,6 @@ def silent_intern(x): return x - # From Dinu C. Gherman, # Python Cookbook, second edition, recipe 6.17, p. 277. # Also: @@ -1569,6 +1568,7 @@ class Null(object): def __delattr__(self, name): return self + class NullSeq(Null): def __len__(self): return 0 |