summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2019-01-06 14:01:11 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2019-01-06 14:08:19 +0100
commitea11f9cb69c61c74a94a7ce645939d861b99d5c2 (patch)
treedc6288a6ed349828ab16b81032ae83a5ab178a0b
parent15a9fc823a61f9a4c78835ad3ab46a1df5241e84 (diff)
downloadgobject-introspection-ea11f9cb69c61c74a94a7ce645939d861b99d5c2.tar.gz
scanner: rework source root guessing code
commonprefix doesn't work on relative paths and doesn't return directories so so for the g-i build case it returned an empty string resulting in paths relative to the working directory, making the build not reproducible. To somehwat improve this make sure the paths are absolute, use commonpath and if no common dir can be found just fall back to passing all directories so we only write the basenames. I guess we should look into passing --sources-top-dirs in the g-i build.
-rw-r--r--giscanner/scannermain.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index a2d7ea5d..154fe483 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -428,6 +428,7 @@ def create_source_scanner(options, args):
filenames = extract_filelist(options)
else:
filenames = extract_filenames(args)
+ filenames = [os.path.realpath(f) for f in filenames]
if platform.system() == 'Darwin':
options.cpp_undefines.append('__BLOCKS__')
@@ -490,6 +491,26 @@ def write_output(data, options):
_error("while writing output: %s" % (e.strerror, ))
+def get_source_root_dirs(options, filenames):
+ if options.sources_top_dirs:
+ return options.sources_top_dir
+
+ # None passed, we need to guess
+ assert all(os.path.isabs(f) for f in filenames)
+ dirs = sorted(set([os.path.dirname(f) for f in filenames]))
+
+ # We need commonpath (3.5+), otherwise give up
+ if not hasattr(os.path, "commonpath"):
+ return dirs
+
+ common = os.path.commonpath(dirs)
+ # If the only common path is the root directory give up
+ if os.path.dirname(common) == common:
+ return dirs
+
+ return [common]
+
+
def scanner_main(args):
parser = _get_option_parser()
(options, args) = parser.parse_args(args)
@@ -579,9 +600,9 @@ def scanner_main(args):
transformer.namespace.c_includes = options.c_includes
transformer.namespace.exported_packages = exported_packages
- if not options.sources_top_dirs:
- options.sources_top_dirs = [os.path.commonprefix(filenames).rpartition(os.path.sep)[0]]
- writer = Writer(transformer.namespace, options.sources_top_dirs)
+
+ sources_top_dirs = get_source_root_dirs(options, filenames)
+ writer = Writer(transformer.namespace, sources_top_dirs)
data = writer.get_encoded_xml()
write_output(data, options)