From ccfafee0239068d5c98017ae5e14ccef29c835c4 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Tue, 13 Dec 2016 10:01:28 -0800 Subject: [PATCH] Make list_files.py and list_dart_files.py return absolute paths for GN This makes doing an SDK build in the Fuchsia tree easier. The previous attempt at this change failed in gyp builds targeting xcode. They failed because input lists for actions of the same target (e.g. the actions for dartanalyzer) are merged and de-duped when the lists contain relative paths, but merged and *not* de-duped when the lists contain absolute paths. gyp rejects xcode files that it generated itself when they contain duplicate entries. This CL works around that bug, by using absolute paths in the GN build and keeping relative paths in the gyp build. R=rmacnak@google.com Review-Url: https://codereview.chromium.org/2567213002 . --- BUILD.gn | 8 ++++---- create_sdk.gyp | 8 ++++---- pkg/BUILD.gn | 1 - pkg/pkg_files.gyp | 11 +++++++---- runtime/vm/BUILD.gn | 13 ++++++++----- runtime/vm/vm.gypi | 3 ++- tools/list_dart_files.py | 22 +++++++++++++++++----- tools/list_files.py | 20 ++++++++++++++++---- utils/compiler/compiler.gyp | 8 ++++++-- utils/create_timestamp.gni | 13 ++----------- utils/dartanalyzer/BUILD.gn | 6 +++--- utils/dartanalyzer/dartanalyzer.gyp | 18 ++++++++++++------ utils/dartdevc/BUILD.gn | 3 ++- utils/dartdevc/dartdevc.gyp | 3 ++- utils/dartdoc/BUILD.gn | 3 ++- utils/dartdoc/dartdoc.gyp | 5 +++-- utils/dartfmt/BUILD.gn | 3 ++- utils/dartfmt/dartfmt.gyp | 3 ++- 18 files changed, 94 insertions(+), 57 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index a027a2e6150..7d1f7fd8764 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -70,12 +70,13 @@ action("create_sdk") { ] sdk_lib_files = exec_script("tools/list_dart_files.py", - [ rebase_path("sdk/lib") ], + [ "absolute", rebase_path("sdk/lib") ], "list lines") preamble_files = exec_script("tools/list_files.py", [ + "absolute", "", rebase_path("sdk/lib/_internal/js_runtime/lib/preambles"), ], @@ -83,14 +84,13 @@ action("create_sdk") { sdk_bin_files = exec_script("tools/list_files.py", [ + "absolute", "", rebase_path("sdk/bin"), ], "list lines") - inputs = rebase_path(sdk_lib_files, "", "sdk/lib") + - rebase_path(preamble_files, "", "sdk/lib") + - rebase_path(sdk_bin_files, "", "sdk/bin") + + inputs = sdk_lib_files + preamble_files + sdk_bin_files + [ "sdk/lib/dart_client.platform", "sdk/lib/dart_server.platform", diff --git a/create_sdk.gyp b/create_sdk.gyp index b1b9361ddda..9e41ef91ee6 100644 --- a/create_sdk.gyp +++ b/create_sdk.gyp @@ -23,15 +23,15 @@ 'inputs': [ # Xcode can only handle a certain amount of files in one list # (also depending on the length of the path from where you run). - ' + python tools/list_dart_files.py {absolute, relative} """ import os @@ -15,11 +19,16 @@ import sys def main(argv): - directory = argv[1] + mode = argv[1] + if mode not in ['absolute', 'relative']: + raise Exception("First argument must be 'absolute' or 'relative'") + directory = argv[2] + if mode in 'absolute' and not os.path.isabs(directory): + directory = os.path.realpath(directory) pattern = None - if len(argv) > 2: - pattern = re.compile(argv[2]) + if len(argv) > 3: + pattern = re.compile(argv[3]) for root, directories, files in os.walk(directory): # We only care about actual source files, not generated code or tests. @@ -34,7 +43,10 @@ def main(argv): for filename in files: if filename.endswith('.dart') and not filename.endswith('_test.dart'): - fullname = os.path.relpath(os.path.join(root, filename)) + if mode in 'absolute': + fullname = os.path.join(directory, root, filename) + else: + fullname = os.path.relpath(os.path.join(root, filename)) fullname = fullname.replace(os.sep, '/') print fullname diff --git a/tools/list_files.py b/tools/list_files.py index ad277e853f0..b63d6ab0e32 100755 --- a/tools/list_files.py +++ b/tools/list_files.py @@ -5,8 +5,12 @@ """Tool for listing files whose name match a pattern. +If the first argument is 'relative', the script produces paths relative to the +current working directory. If the first argument is 'absolute', the script +produces absolute paths. + Usage: - python tools/list_files.py PATTERN DIRECTORY... + python tools/list_files.py {absolute, relative} PATTERN DIRECTORY... """ import os @@ -15,13 +19,21 @@ import sys def main(argv): - pattern = re.compile(argv[1]) - for directory in argv[2:]: + mode = argv[1] + if mode not in ['absolute', 'relative']: + raise Exception("First argument must be 'absolute' or 'relative'") + pattern = re.compile(argv[2]) + for directory in argv[3:]: + if mode in 'absolute' and not os.path.isabs(directory): + directory = os.path.realpath(directory) for root, directories, files in os.walk(directory): if '.git' in directories: directories.remove('.git') for filename in files: - fullname = os.path.relpath(os.path.join(root, filename)) + if mode in 'absolute': + fullname = os.path.join(directory, root, filename) + else: + fullname = os.path.relpath(os.path.join(root, filename)) fullname = fullname.replace(os.sep, '/') if re.search(pattern, fullname): print fullname diff --git a/utils/compiler/compiler.gyp b/utils/compiler/compiler.gyp index 63c4daeb36d..272dd0aa137 100644 --- a/utils/compiler/compiler.gyp +++ b/utils/compiler/compiler.gyp @@ -20,7 +20,10 @@ 'inputs': [ '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)dart<(EXECUTABLE_SUFFIX)', '../../sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart', - '