Skip to content

Commit 7692c11

Browse files
Update the Dart package creation script to copy source files instead of creating symlinks to the source tree (#165242)
The use of symlinks and the use of a directory as a GN output path may cause unnecessary rebuilds when Ninja checks file modification times to determine whether build outputs are up to date. Also remove various other unused featues that were copied from the original version of the script in the Mojo project.
1 parent efd9f14 commit 7692c11

File tree

3 files changed

+4
-126
lines changed

3 files changed

+4
-126
lines changed

engine/src/flutter/build/dart/tools/dart_pkg.py

Lines changed: 3 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,11 @@
1414
import subprocess
1515
import sys
1616

17-
USE_LINKS = sys.platform != 'win32'
18-
19-
DART_ANALYZE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'dart_analyze.py')
20-
2117

2218
def dart_filter(path):
2319
if os.path.isdir(path):
2420
return True
2521
_, ext = os.path.splitext(path)
26-
# .dart includes '.mojom.dart'
2722
return ext == '.dart'
2823

2924

@@ -41,21 +36,6 @@ def has_pubspec_yaml(paths):
4136
return False
4237

4338

44-
def link(from_root, to_root):
45-
ensure_dir_exists(os.path.dirname(to_root))
46-
try:
47-
os.unlink(to_root)
48-
except OSError as err:
49-
if err.errno == errno.ENOENT:
50-
pass
51-
52-
try:
53-
os.symlink(from_root, to_root)
54-
except OSError as err:
55-
if err.errno == errno.EEXIST:
56-
pass
57-
58-
5939
def copy(from_root, to_root, filter_func=None):
6040
if not os.path.exists(from_root):
6141
return
@@ -84,18 +64,6 @@ def copy(from_root, to_root, filter_func=None):
8464
dirs[:] = list(filter(wrapped_filter, dirs))
8565

8666

87-
def copy_or_link(from_root, to_root, filter_func=None):
88-
if USE_LINKS:
89-
link(from_root, to_root)
90-
else:
91-
copy(from_root, to_root, filter_func)
92-
93-
94-
def link_if_possible(from_root, to_root):
95-
if USE_LINKS:
96-
link(from_root, to_root)
97-
98-
9967
def remove_if_exists(path):
10068
try:
10169
os.remove(path)
@@ -118,47 +86,6 @@ def list_files(from_root, filter_func=None):
11886
return file_list
11987

12088

121-
def remove_broken_symlink(path):
122-
if not USE_LINKS:
123-
return
124-
try:
125-
link_path = os.readlink(path)
126-
except OSError as err:
127-
# Path was not a symlink.
128-
if err.errno == errno.EINVAL:
129-
pass
130-
else:
131-
if not os.path.exists(link_path):
132-
remove_if_exists(path)
133-
134-
135-
def remove_broken_symlinks(root_dir):
136-
if not USE_LINKS:
137-
return
138-
for current_dir, _, child_files in os.walk(root_dir):
139-
for filename in child_files:
140-
path = os.path.join(current_dir, filename)
141-
remove_broken_symlink(path)
142-
143-
144-
def analyze_entrypoints(dart_sdk, package_root, entrypoints):
145-
cmd = ['python', DART_ANALYZE]
146-
cmd.append('--dart-sdk')
147-
cmd.append(dart_sdk)
148-
cmd.append('--entrypoints')
149-
cmd.extend(entrypoints)
150-
cmd.append('--package-root')
151-
cmd.append(package_root)
152-
cmd.append('--no-hints')
153-
try:
154-
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
155-
except subprocess.CalledProcessError as err:
156-
print('Failed analyzing %s' % entrypoints)
157-
print(err.output)
158-
return err.returncode
159-
return 0
160-
161-
16289
def main():
16390
parser = argparse.ArgumentParser(description='Generate a dart-pkg')
16491
parser.add_argument(
@@ -177,23 +104,10 @@ def main():
177104
help='Directory where dart_pkg should go',
178105
required=True
179106
)
180-
parser.add_argument(
181-
'--package-root', metavar='package_root', help='packages/ directory', required=True
182-
)
183107
parser.add_argument('--stamp-file', metavar='stamp_file', help='timestamp file', required=True)
184-
parser.add_argument(
185-
'--entries-file', metavar='entries_file', help='script entries file', required=True
186-
)
187108
parser.add_argument(
188109
'--package-sources', metavar='package_sources', help='Package sources', nargs='+'
189110
)
190-
parser.add_argument(
191-
'--package-entrypoints',
192-
metavar='package_entrypoints',
193-
help='Package entry points for analyzer',
194-
nargs='*',
195-
default=[]
196-
)
197111
parser.add_argument(
198112
'--sdk-ext-directories',
199113
metavar='sdk_ext_directories',
@@ -249,14 +163,7 @@ def main():
249163
for source in args.package_sources:
250164
relative_source = os.path.relpath(source, common_source_prefix)
251165
target = os.path.join(target_dir, relative_source)
252-
copy_or_link(source, target)
253-
254-
entrypoint_targets = []
255-
for source in args.package_entrypoints:
256-
relative_source = os.path.relpath(source, common_source_prefix)
257-
target = os.path.join(target_dir, relative_source)
258-
copy_or_link(source, target)
259-
entrypoint_targets.append(target)
166+
copy(source, target)
260167

261168
# Copy sdk-ext sources into pkg directory
262169
sdk_ext_dir = os.path.join(target_dir, 'sdk_ext')
@@ -266,30 +173,13 @@ def main():
266173
for source in sdk_ext_sources:
267174
relative_source = os.path.relpath(source, common_prefix)
268175
target = os.path.join(sdk_ext_dir, relative_source)
269-
copy_or_link(source, target)
176+
copy(source, target)
270177

271178
common_source_prefix = os.path.dirname(os.path.commonprefix(args.sdk_ext_files))
272179
for source in args.sdk_ext_files:
273180
relative_source = os.path.relpath(source, common_source_prefix)
274181
target = os.path.join(sdk_ext_dir, relative_source)
275-
copy_or_link(source, target)
276-
277-
# Symlink packages/
278-
package_path = os.path.join(args.package_root, args.package_name)
279-
copy_or_link(lib_path, package_path)
280-
281-
# Link dart-pkg/$package/packages to dart-pkg/packages
282-
link_if_possible(args.package_root, target_packages_dir)
283-
284-
# Remove any broken symlinks in target_dir and package root.
285-
remove_broken_symlinks(target_dir)
286-
remove_broken_symlinks(args.package_root)
287-
288-
# If any entrypoints are defined, write them to disk so that the analyzer
289-
# test can find them.
290-
with open(args.entries_file, 'w') as file:
291-
for entrypoint in entrypoint_targets:
292-
file.write(entrypoint + '\n')
182+
copy(source, target)
293183

294184
# Write stamp file.
295185
with open(args.stamp_file, 'w'):

engine/src/flutter/sky/dist/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ if (is_android) {
1111
source = "$root_gen_dir/dart-pkg/sky_engine"
1212
dest = "$root_build_dir/dist/packages/sky_engine"
1313

14-
inputs = [ source ]
1514
outputs = [ dest ]
1615

1716
args = [

engine/src/flutter/sky/packages/sky_engine/BUILD.gn

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,7 @@ generated_file("_embedder_yaml") {
293293
action("sky_engine") {
294294
package_name = "sky_engine"
295295
pkg_directory = rebase_path("$root_gen_dir/dart-pkg")
296-
package_root = rebase_path("$root_gen_dir/dart-pkg/packages")
297296
stamp_file = "$root_gen_dir/dart-pkg/${package_name}.stamp"
298-
entries_file = "$root_gen_dir/dart-pkg/${package_name}.entries"
299297

300298
sources = [
301299
"LICENSE",
@@ -322,12 +320,7 @@ action("sky_engine") {
322320
"$service_isolate_dir/vmservice_server.dart",
323321
]
324322

325-
outputs = [
326-
"$root_gen_dir/dart-pkg/${package_name}",
327-
"$root_gen_dir/dart-pkg/${package_name}/pubspec.yaml",
328-
"$root_gen_dir/dart-pkg/packages/${package_name}",
329-
stamp_file,
330-
]
323+
outputs = [ stamp_file ]
331324

332325
script = rebase_path("//flutter/build/dart/tools/dart_pkg.py", ".", "//")
333326

@@ -340,12 +333,8 @@ action("sky_engine") {
340333
rebase_path(dart_sdk_root),
341334
"--pkg-directory",
342335
pkg_directory,
343-
"--package-root",
344-
package_root,
345336
"--stamp-file",
346337
rebase_path(stamp_file),
347-
"--entries-file",
348-
rebase_path(entries_file),
349338
"--package-sources",
350339
] + rebase_path(sources) + [ "--sdk-ext-directories" ] +
351340
rebase_path(sdk_ext_directory) + [ "--sdk-ext-files" ] +

0 commit comments

Comments
 (0)