Skip to content

Commit 71876cf

Browse files
Simeon Anfinrudcopybara-github
authored andcommitted
Revert "Reland #2 "Android: Refactor write_build_config.py""
This reverts commit 4bc21e8413d1d01f2b1bf474cbb7fa6811b40528. Change-Id: I5523850ad9fb072919d354d2ab9383feeb8852c6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6680571 Reviewed-by: Andrew Grieve <[email protected]> Owners-Override: Andrew Grieve <[email protected]> Commit-Queue: Andrew Grieve <[email protected]> Cr-Commit-Position: refs/heads/main@{#1479597} NOKEYCHECK=True GitOrigin-RevId: 4f141ffbfc24fe79b6f1d8596212818f12c07fb6
1 parent 1c14ac6 commit 71876cf

File tree

10 files changed

+1104
-1141
lines changed

10 files changed

+1104
-1141
lines changed

android/PRESUBMIT.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ def J(*dirs):
9898
J('gyp', 'java_cpp_features_tests.py'),
9999
J('gyp', 'java_cpp_strings_tests.py'),
100100
J('gyp', 'java_google_api_keys_tests.py'),
101+
J('gyp', 'util', 'build_utils_test.py'),
101102
J('gyp', 'util', 'manifest_utils_test.py'),
102103
J('gyp', 'util', 'md5_check_test.py'),
103104
J('gyp', 'util', 'resource_utils_test.py'),

android/gradle/generate_gradle.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ def FromGnTarget(cls, gn_target):
158158
return cls._cached_entries[gn_target]
159159

160160
@classmethod
161-
def FromParamsJsonPath(cls, path):
161+
def FromBuildConfigPath(cls, path):
162162
prefix = 'gen/'
163-
suffix = '.params.json'
163+
suffix = '.build_config.json'
164164
assert path.startswith(prefix) and path.endswith(suffix), path
165165
subdir = path[len(prefix):-len(suffix)]
166166
gn_target = '//%s:%s' % (os.path.split(subdir))
@@ -249,12 +249,9 @@ def AllEntries(self):
249249
This includes the entry itself to make iterating simpler."""
250250
if self._all_entries is None:
251251
logging.debug('Generating entries for %s', self.GnTarget())
252-
deps = [
253-
_ProjectEntry.FromParamsJsonPath(p)
254-
for p in self.Gradle()['dependent_android_projects']
255-
]
256-
deps.extend(
257-
_ProjectEntry.FromParamsJsonPath(p)
252+
deps = [_ProjectEntry.FromBuildConfigPath(p)
253+
for p in self.Gradle()['dependent_android_projects']]
254+
deps.extend(_ProjectEntry.FromBuildConfigPath(p)
258255
for p in self.Gradle()['dependent_java_projects'])
259256
all_entries = set()
260257
for dep in deps:
@@ -372,15 +369,11 @@ def Generate(self, root_entry):
372369
self.processed_res_dirs.update(res_dirs)
373370
variables['res_dirs'] = self._Relativize(root_entry, res_dirs)
374371
if self.split_projects:
375-
deps = [
376-
_ProjectEntry.FromParamsJsonPath(p)
377-
for p in root_entry.Gradle()['dependent_android_projects']
378-
]
372+
deps = [_ProjectEntry.FromBuildConfigPath(p)
373+
for p in root_entry.Gradle()['dependent_android_projects']]
379374
variables['android_project_deps'] = [d.ProjectName() for d in deps]
380-
deps = [
381-
_ProjectEntry.FromParamsJsonPath(p)
382-
for p in root_entry.Gradle()['dependent_java_projects']
383-
]
375+
deps = [_ProjectEntry.FromBuildConfigPath(p)
376+
for p in root_entry.Gradle()['dependent_java_projects']]
384377
variables['java_project_deps'] = [d.ProjectName() for d in deps]
385378
return variables
386379

@@ -732,7 +725,7 @@ def _FindAllProjectEntries(main_entries):
732725
found.add(cur_entry)
733726
sub_config_paths = cur_entry.BuildConfig()['deps_configs']
734727
to_scan.extend(
735-
_ProjectEntry.FromParamsJsonPath(p) for p in sub_config_paths)
728+
_ProjectEntry.FromBuildConfigPath(p) for p in sub_config_paths)
736729
return list(found)
737730

738731

android/gyp/util/build_utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""Contains common helpers for GN action()s."""
66

77
import atexit
8+
import collections
89
import contextlib
910
import fnmatch
1011
import json
@@ -326,6 +327,34 @@ def MatchesGlob(path, filters):
326327
return filters and any(fnmatch.fnmatch(path, f) for f in filters)
327328

328329

330+
def GetSortedTransitiveDependencies(top, deps_func):
331+
"""Gets the list of all transitive dependencies in sorted order.
332+
333+
There should be no cycles in the dependency graph (crashes if cycles exist).
334+
335+
Args:
336+
top: A list of the top level nodes
337+
deps_func: A function that takes a node and returns a list of its direct
338+
dependencies.
339+
Returns:
340+
A list of all transitive dependencies of nodes in top, in order (a node will
341+
appear in the list at a higher index than all of its dependencies).
342+
"""
343+
# Find all deps depth-first, maintaining original order in the case of ties.
344+
deps_map = collections.OrderedDict()
345+
346+
def discover(nodes):
347+
for node in nodes:
348+
if node in deps_map:
349+
continue
350+
deps = deps_func(node)
351+
discover(deps)
352+
deps_map[node] = deps
353+
354+
discover(top)
355+
return list(deps_map)
356+
357+
329358
def InitLogging(enabling_env):
330359
logging.basicConfig(
331360
level=logging.DEBUG if os.environ.get(enabling_env) else logging.WARNING,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2018 The Chromium Authors
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
import collections
7+
import os
8+
import sys
9+
import unittest
10+
11+
sys.path.insert(
12+
0, os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)))
13+
from util import build_utils
14+
15+
_DEPS = collections.OrderedDict()
16+
_DEPS['a'] = []
17+
_DEPS['b'] = []
18+
_DEPS['c'] = ['a']
19+
_DEPS['d'] = ['a']
20+
_DEPS['e'] = ['f']
21+
_DEPS['f'] = ['a', 'd']
22+
_DEPS['g'] = []
23+
_DEPS['h'] = ['d', 'b', 'f']
24+
_DEPS['i'] = ['f']
25+
26+
27+
class BuildUtilsTest(unittest.TestCase):
28+
def testGetSortedTransitiveDependencies_all(self):
29+
TOP = _DEPS.keys()
30+
EXPECTED = ['a', 'b', 'c', 'd', 'f', 'e', 'g', 'h', 'i']
31+
actual = build_utils.GetSortedTransitiveDependencies(TOP, _DEPS.get)
32+
self.assertEqual(EXPECTED, actual)
33+
34+
def testGetSortedTransitiveDependencies_leaves(self):
35+
TOP = ['c', 'e', 'g', 'h', 'i']
36+
EXPECTED = ['a', 'c', 'd', 'f', 'e', 'g', 'b', 'h', 'i']
37+
actual = build_utils.GetSortedTransitiveDependencies(TOP, _DEPS.get)
38+
self.assertEqual(EXPECTED, actual)
39+
40+
def testGetSortedTransitiveDependencies_leavesReverse(self):
41+
TOP = ['i', 'h', 'g', 'e', 'c']
42+
EXPECTED = ['a', 'd', 'f', 'i', 'b', 'h', 'g', 'e', 'c']
43+
actual = build_utils.GetSortedTransitiveDependencies(TOP, _DEPS.get)
44+
self.assertEqual(EXPECTED, actual)
45+
46+
47+
if __name__ == '__main__':
48+
unittest.main()

0 commit comments

Comments
 (0)