gn2bp: Remove unuded code
Test: ./gen_android_bp --desc gn.json --output Android.bp \
'//third_party/zlib:zlib'
Change-Id: Icd3891c605e6b519b4eb7ca9a14563c825c5750d
diff --git a/tools/gn2bp/gn_utils.py b/tools/gn2bp/gn_utils.py
index 6163ea0..9cada7b 100644
--- a/tools/gn2bp/gn_utils.py
+++ b/tools/gn2bp/gn_utils.py
@@ -39,114 +39,12 @@
}
-def _check_command_output(cmd, cwd):
- try:
- output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=cwd)
- except subprocess.CalledProcessError as e:
- print(
- 'Command "{}" failed in {}:'.format(' '.join(cmd), cwd),
- file=sys.stderr)
- print(e.output.decode(), file=sys.stderr)
- sys.exit(1)
- else:
- return output.decode()
-
-
def repo_root():
"""Returns an absolute path to the repository root."""
return os.path.join(
os.path.realpath(os.path.dirname(__file__)), os.path.pardir)
-def _tool_path(name, system_buildtools=False):
- # Pass-through to use name if the caller requests to use the system
- # toolchain.
- if system_buildtools:
- return [name]
- wrapper = os.path.abspath(
- os.path.join(repo_root(), 'tools', 'run_buildtools_binary.py'))
- return ['python3', wrapper, name]
-
-
-def prepare_out_directory(gn_args,
- name,
- root=repo_root(),
- system_buildtools=False):
- """Creates the JSON build description by running GN.
-
- Returns (path, desc) where |path| is the location of the output directory
- and |desc| is the JSON build description.
- """
- out = os.path.join(root, 'out', name)
- try:
- os.makedirs(out)
- except OSError as e:
- if e.errno != errno.EEXIST:
- raise
- _check_command_output(
- _tool_path('gn', system_buildtools) +
- ['gen', out, '--args=%s' % gn_args],
- cwd=repo_root())
- return out
-
-
-def load_build_description(out, system_buildtools=False):
- """Creates the JSON build description by running GN."""
- desc = _check_command_output(
- _tool_path('gn', system_buildtools) +
- ['desc', out, '--format=json', '--all-toolchains', '//*'],
- cwd=repo_root())
- return json.loads(desc)
-
-
-def create_build_description(gn_args, root=repo_root()):
- """Prepares a GN out directory and loads the build description from it.
-
- The temporary out directory is automatically deleted.
- """
- out = prepare_out_directory(gn_args, 'tmp.gn_utils', root=root)
- try:
- return load_build_description(out)
- finally:
- shutil.rmtree(out)
-
-
-def build_targets(out, targets, quiet=False, system_buildtools=False):
- """Runs ninja to build a list of GN targets in the given out directory.
-
- Compiling these targets is required so that we can include any generated
- source files in the amalgamated result.
- """
- targets = [t.replace('//', '') for t in targets]
- with open(os.devnull, 'w') as devnull:
- stdout = devnull if quiet else None
- cmd = _tool_path('ninja', system_buildtools) + targets
- subprocess.check_call(cmd, cwd=os.path.abspath(out), stdout=stdout)
-
-
-def compute_source_dependencies(out, system_buildtools=False):
- """For each source file, computes a set of headers it depends on."""
- ninja_deps = _check_command_output(
- _tool_path('ninja', system_buildtools) + ['-t', 'deps'], cwd=out)
- deps = {}
- current_source = None
- for line in ninja_deps.split('\n'):
- filename = os.path.relpath(os.path.join(out, line.strip()), repo_root())
- if not line or line[0] != ' ':
- current_source = None
- continue
- elif not current_source:
- # We're assuming the source file is always listed before the
- # headers.
- assert os.path.splitext(line)[1] in ['.c', '.cc', '.cpp', '.S']
- current_source = filename
- deps[current_source] = []
- else:
- assert current_source
- deps[current_source].append(filename)
- return deps
-
-
def label_to_path(label):
"""Turn a GN output label (e.g., //some_dir/file.cc) into a path."""
assert label.startswith('//')
@@ -172,41 +70,6 @@
return name
-def gen_buildflags(gn_args, target_file):
- """Generates the perfetto_build_flags.h for the given config.
-
- target_file: the path, relative to the repo root, where the generated
- buildflag header will be copied into.
- """
- tmp_out = prepare_out_directory(gn_args, 'tmp.gen_buildflags')
- build_targets(tmp_out, [BUILDFLAGS_TARGET], quiet=True)
- src = os.path.join(tmp_out, 'gen', 'build_config', 'perfetto_build_flags.h')
- shutil.copy(src, os.path.join(repo_root(), target_file))
- shutil.rmtree(tmp_out)
-
-
-def check_or_commit_generated_files(tmp_files, check):
- """Checks that gen files are unchanged or renames them to the final location
-
- Takes in input a list of 'xxx.swp' files that have been written.
- If check == False, it renames xxx.swp -> xxx.
- If check == True, it just checks that the contents of 'xxx.swp' == 'xxx'.
- Returns 0 if no diff was detected, 1 otherwise (to be used as exit code).
- """
- res = 0
- for tmp_file in tmp_files:
- assert (tmp_file.endswith('.swp'))
- target_file = os.path.relpath(tmp_file[:-4])
- if check:
- if not filecmp.cmp(tmp_file, target_file):
- sys.stderr.write('%s needs to be regenerated\n' % target_file)
- res = 1
- os.unlink(tmp_file)
- else:
- os.rename(tmp_file, target_file)
- return res
-
-
class GnParser(object):
"""A parser with some cleverness for GN json desc files
diff --git a/tools/gn2bp/run_buildtools_binary.py b/tools/gn2bp/run_buildtools_binary.py
deleted file mode 100755
index 7a6fe81..0000000
--- a/tools/gn2bp/run_buildtools_binary.py
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (C) 2022 The Android Open Source Project
-#
-# 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.
-""" A wrapper to run gn, ninja and other buildtools/ for all platforms. """
-
-from __future__ import print_function
-
-import os
-import subprocess
-import sys
-
-from platform import system, machine
-
-ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
-
-
-def run_buildtools_binary(args):
- if len(args) < 1:
- print('Usage %s command [args]\n' % sys.argv[0])
- return 1
-
- sys_name = system().lower()
- os_dir = None
- ext = ''
- if sys_name == 'windows':
- os_dir = 'win'
- ext = '.exe'
- elif sys_name == 'darwin':
- os_dir = 'mac'
- elif sys_name == 'linux':
- os_dir = 'linux64'
- else:
- print('OS not supported: %s\n' % sys_name)
- return 1
-
- cmd = args[0]
- args = args[1:]
- exe_path = os.path.join(ROOT_DIR, 'buildtools', os_dir, cmd) + ext
- if sys_name == 'windows':
- # execl() behaves oddly on Windows: the spawned process doesn't seem to
- # receive CTRL+C. Use subprocess instead.
- return subprocess.call([exe_path] + args)
- else:
- os.execl(exe_path, os.path.basename(exe_path), *args)
-
-
-if __name__ == '__main__':
- sys.exit(run_buildtools_binary(sys.argv[1:]))