Commit 2ce3bfdf authored by Jérémie Boulic's avatar Jérémie Boulic Committed by Chromium LUCI CQ

[Files app]: Add scripts for JS modules conversion

Command:
ui/file_manager/base/tools/modules.sh [1] [2]
[1] build directory (e.g. out/Release)
[2] path of JS file to convert (relative to chromium/src)

What does the script do:
1. Update BUILD.gn to enable conversion of JS file.
2. Add exports.
3. Run closure compiler.
4. Parse closure compiler output to retrieve unknown types/variables/functions.
6. Parse these dependencies to find relevant exported types/variables/functions.
7. When found, update BUILD.gn and JS file.

Made sure that:
The script doesn't add any irrelevant import/export.
No duplicate lines are added.

Steps 3 to 7 are ran until the closure compiler output
'X error(s), Y warning(s), Z% typed' doesn't change. The closure compiler
is ran at least 3 times (except if no imports are found), sometimes more.

Bug: 1133186
Change-Id: I1528c8187bc1476d6add1bcb14a0d4fd1b64a4fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2550328
Commit-Queue: Jeremie Boulic <jboulic@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834181}
parent b8c6670f
This diff is collapsed.
#!/bin/bash
#
# Copyright (c) 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Command usage:
# ui/file_manager/base/tools/modules.sh out/Release ui/file_manager/
# file_manager/foreground/js/list_thumbnail_loader.js
# ui/file_manager/base/tools/modules.sh out/Release ui/file_manager/
# file_manager/common/js/importer_common.js
# ui/file_manager/base/tools/modules.sh out/Release ui/file_manager/
# file_manager/foreground/js/list_thumbnail_loader_unittest.js
# Input: js file to convert.
build_dir=$1;
file_path=$2;
dir=`dirname $file_path`;
compiler_output="$build_dir/gen/ui/file_manager/base/tools/compiler_output.txt";
# Create containing directory of `compiler_output` if doesn't exist.
mkdir -p `dirname $compiler_output`;
# Process files with Python.
ui/file_manager/base/tools/modules.py $file_path 'generate';
# Parse closure compiler output and update files until the message 'X error(s),
# Y warning(s), Z% typed' doesn't change.
prev_output=""
new_output="."
while [[ $prev_output != $new_output ]]; do
prev_output=$new_output;
# Run closure compiler and save output.
ninja -C $build_dir $dir:closure_compile 2>&1 | tee $compiler_output;
# Parse closure compiler output.
ui/file_manager/base/tools/modules.py $file_path 'parse' $compiler_output;
# Get number of errors from modules.txt.
new_output=$(cat $compiler_output | grep 'error(s)' );
done;
# Format files.
git cl format --js;
if [[ $new_output == "" ]]; then
echo "No closure compiler error found"
else
echo "Final state: " $new_output;
fi;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment