dawn-cmake/generator/remove_files.py
Corentin Wallez ff2dc652f5 Revert "remove_files.py: Print warnings on removals"
This reverts commit d51b47ac676244cccb156bbd29d0e53231068330.

Reason for revert: crbug.com/1335550

Original change's description:
> remove_files.py: Print warnings on removals
>
> This will make it easier to debug build issues happening because if this
> script in the future.
>
> Bug: chromium:1314527
> Change-Id: I5bbb4082ac816f98860e621917bc35b26ba7cb29
> Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87700
> Auto-Submit: Corentin Wallez <cwallez@chromium.org>
> Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
> Commit-Queue: Dan Sinclair <dsinclair@chromium.org>

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: chromium:1314527
Change-Id: I47e352f57becaa064b6c8ceb022dcbed9bd212d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93441
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
2022-06-14 00:04:55 +00:00

92 lines
2.9 KiB
Python

#!/usr/bin/env python3
# Copyright 2019 The Dawn Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse, glob, os, sys
def check_in_subdirectory(path, directory):
return path.startswith(directory) and not '/' in path[len(directory):]
def check_is_allowed(path, allowed_dirs):
return any(
check_in_subdirectory(path, directory) for directory in allowed_dirs)
def get_all_files_in_dir(find_directory):
result = []
for (directory, _, files) in os.walk(find_directory):
result += [os.path.join(directory, filename) for filename in files]
return result
def run():
# Parse command line arguments
parser = argparse.ArgumentParser(
description="Removes stale autogenerated files from gen/ directories.")
parser.add_argument(
'--root-dir',
type=str,
help='The root directory, all other paths in files are relative to it.'
)
parser.add_argument(
'--allowed-output-dirs-file',
type=str,
help='The file containing a list of allowed directories')
parser.add_argument(
'--stale-dirs-file',
type=str,
help=
'The file containing a list of directories to check for stale files')
parser.add_argument('--stamp',
type=str,
help='A stamp written once this script completes')
args = parser.parse_args()
root_dir = args.root_dir
stamp_file = args.stamp
# Load the list of allowed and stale directories
with open(args.allowed_output_dirs_file) as f:
allowed_dirs = set(
[os.path.join(root_dir, line.strip()) for line in f.readlines()])
for directory in allowed_dirs:
if not directory.endswith('/'):
print('Allowed directory entry "{}" doesn\'t end with /'.format(
directory))
return 1
with open(args.stale_dirs_file) as f:
stale_dirs = set([line.strip() for line in f.readlines()])
# Remove all files in stale dirs that aren't in the allowed dirs.
for stale_dir in stale_dirs:
stale_dir = os.path.join(root_dir, stale_dir)
for candidate in get_all_files_in_dir(stale_dir):
if not check_is_allowed(candidate, allowed_dirs):
os.remove(candidate)
# Finished! Write the stamp file so ninja knows to not run this again.
with open(stamp_file, "w") as f:
f.write("")
return 0
if __name__ == "__main__":
sys.exit(run())