Commit 415a39dd authored by apavlov@chromium.org's avatar apavlov@chromium.org

DevTools: Refactor build script to copy module files in debug_devtools mode

Currently, all module files are copied by the 'copies' GYP actions.
This patch makes build_applications.py copy the app HTML and directories
into the output directory.

R=dgozman, pfeldman@chromium.org

Review URL: https://codereview.chromium.org/646413002

git-svn-id: svn://svn.chromium.org/blink/trunk@183664 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 97fc1238
...@@ -12,9 +12,14 @@ gypi_values = exec_script( ...@@ -12,9 +12,14 @@ gypi_values = exec_script(
# Some of the files in the .gypi use GYP variable expansions, go through and # Some of the files in the .gypi use GYP variable expansions, go through and
# fix them. # fix them.
devtools_core_base_non_generated_files =
gypi_values.devtools_core_base_non_generated_files - [
"<@(devtools_standalone_files)",
] + gypi_values.devtools_standalone_files
devtools_core_base_files = gypi_values.devtools_core_base_files - [ devtools_core_base_files = gypi_values.devtools_core_base_files - [
"<@(devtools_standalone_files)", "<@(devtools_core_base_non_generated_files)",
] + gypi_values.devtools_standalone_files ] + devtools_core_base_non_generated_files
devtools_core_files = devtools_core_files =
devtools_core_base_files + devtools_core_base_files +
...@@ -77,8 +82,6 @@ visibility = [ "//third_party/WebKit/*" ] ...@@ -77,8 +82,6 @@ visibility = [ "//third_party/WebKit/*" ]
group("devtools_frontend_resources") { group("devtools_frontend_resources") {
deps = [ deps = [
":devtools_html",
":toolbox_html",
":copy_inspector_images", ":copy_inspector_images",
":copy_standalone_css", ":copy_standalone_css",
":devtools_extension_api", ":devtools_extension_api",
...@@ -167,35 +170,6 @@ action("generate_devtools_grd") { ...@@ -167,35 +170,6 @@ action("generate_devtools_grd") {
] ]
} }
template("generate_app_html") {
assert(defined(invoker.app_name), target_name)
app_name = invoker.app_name
action(target_name) {
script = "scripts/generate_devtools_html.py"
inputs = [ "front_end/" + app_name + ".html"]
outputs = [ resources_out_dir + app_name + ".html" ]
args = rebase_path(inputs, root_build_dir) +
rebase_path(outputs, root_build_dir)
if (debug_devtools) {
args += [ "1" ]
} else {
args += [ "0" ]
}
}
}
generate_app_html("devtools_html") {
app_name = "devtools"
}
generate_app_html("toolbox_html") {
app_name = "toolbox"
}
action("devtools_extension_api") { action("devtools_extension_api") {
script = "scripts/generate_devtools_extension_api.py" script = "scripts/generate_devtools_extension_api.py"
...@@ -229,62 +203,62 @@ action("frontend_protocol_sources") { ...@@ -229,62 +203,62 @@ action("frontend_protocol_sources") {
] ]
} }
group("build_applications") { action("build_applications") {
if (!debug_devtools) { script = "scripts/build_applications.py"
# Release: concatenate application code. This overwrites helper_scripts = [
# application-specific scripts (devtools.js), and thus should be guarded. "scripts/modular_build.py",
action("build_applications_release") { "scripts/concatenate_application_code.py",
script = "scripts/build_applications.py" ]
helper_scripts = [
"scripts/modular_build.py", inputs = helper_scripts + all_devtools_files + generated_scripts
"scripts/concatenate_application_code.py",
] outputs = [
resources_out_dir + "devtools.js",
inputs = helper_scripts + all_devtools_files + generated_scripts resources_out_dir + "devtools.html",
resources_out_dir + "toolbox.js",
outputs = [ resources_out_dir + "toolbox.html",
resources_out_dir + "devtools.js", ]
resources_out_dir + "toolbox.js",
resources_out_dir + "audits_module.js", if (debug_devtools) {
resources_out_dir + "console_module.js", deps = [ ":copy_debug_non_modules" ]
resources_out_dir + "devices_module.js",
resources_out_dir + "documentation_module.js", debug_mode = "1"
resources_out_dir + "elements_module.js",
resources_out_dir + "extensions_module.js",
resources_out_dir + "heap_snapshot_worker_module.js",
resources_out_dir + "layers_module.js",
resources_out_dir + "network_module.js",
resources_out_dir + "profiler_module.js",
resources_out_dir + "promises_module.js",
resources_out_dir + "resources_module.js",
resources_out_dir + "script_formatter_worker_module.js",
resources_out_dir + "settings_module.js",
resources_out_dir + "source_frame_module.js",
resources_out_dir + "sources_module.js",
resources_out_dir + "temp_storage_shared_worker_module.js",
resources_out_dir + "timeline_module.js",
]
args = [
"devtools", "toolbox",
"--input_path", rebase_path("front_end", root_build_dir),
"--output_path", rebase_path(resources_out_dir, root_build_dir),
"--debug", "0"
]
deps = [
":supported_css_properties",
":frontend_protocol_sources",
]
}
deps = [
":build_applications_release"
]
} else { } else {
outputs += [
resources_out_dir + "audits_module.js",
resources_out_dir + "console_module.js",
resources_out_dir + "devices_module.js",
resources_out_dir + "documentation_module.js",
resources_out_dir + "elements_module.js",
resources_out_dir + "extensions_module.js",
resources_out_dir + "heap_snapshot_worker_module.js",
resources_out_dir + "layers_module.js",
resources_out_dir + "network_module.js",
resources_out_dir + "profiler_module.js",
resources_out_dir + "promises_module.js",
resources_out_dir + "resources_module.js",
resources_out_dir + "script_formatter_worker_module.js",
resources_out_dir + "settings_module.js",
resources_out_dir + "source_frame_module.js",
resources_out_dir + "sources_module.js",
resources_out_dir + "temp_storage_shared_worker_module.js",
resources_out_dir + "timeline_module.js",
]
deps = [ deps = [
":copy_debug_modules" ":supported_css_properties",
":frontend_protocol_sources",
] ]
debug_mode = "0"
} }
args = [
"devtools", "toolbox",
"--input_path", rebase_path("front_end", root_build_dir),
"--output_path", rebase_path(resources_out_dir, root_build_dir),
"--debug", debug_mode
]
} }
copy("copy_codemirror_css") { copy("copy_codemirror_css") {
...@@ -300,233 +274,29 @@ copy("copy_standalone_css") { ...@@ -300,233 +274,29 @@ copy("copy_standalone_css") {
} }
if (debug_devtools) { if (debug_devtools) {
# Debug: copy front-end into resources_out_dir as-is. # Debug: copy non-module directories and core into resources_out_dir as-is.
group("copy_debug_modules") { group("copy_debug_non_modules") {
deps = [
":copy_audits_module",
":copy_bindings_module",
":copy_common_module",
":copy_components_module",
":copy_console_module",
":copy_devices_module",
":copy_documentation_module",
":copy_elements_module",
":copy_extensions_module",
":copy_heap_snapshot_worker_module",
":copy_host_module",
":copy_layers_module",
":copy_main_module",
":copy_network_module",
":copy_profiler_module",
":copy_promises_module",
":copy_resources_module",
":copy_screencast_module",
":copy_script_formatter_worker_module",
":copy_sdk_module",
":copy_settings_module",
":copy_source_frame_module",
":copy_sources_module",
":copy_temp_storage_shared_worker_module",
":copy_timeline_module",
":copy_toolbox_module",
":copy_toolbox_bootstrap_module",
":copy_ui_module",
":copy_workspace_module",
]
copy("copy_runtime_core") {
sources = devtools_core_base_files -
gypi_values.devtools_standalone_files
outputs = [ resources_out_dir + "/{{source_file_part}}" ]
}
deps += [ ":copy_runtime_core" ]
}
# Copies module contents into resources_out_dir in debug_devtools=1 builds.
# module_name: (String) The JS module name to process.
# imported_files: (List of strings) The list of files the input depends on.
template("copy_debug_module") {
assert(defined(invoker.module_name), target_name)
assert(defined(invoker.imported_files), target_name)
imported_files = invoker.imported_files
module_name = invoker.module_name
module_json = "front_end/" + module_name + "/module.json"
copy(target_name) {
sources = [ module_json ] + imported_files
outputs = [ resources_out_dir + module_name + "/{{source_file_part}}" ]
}
}
copy_debug_module("copy_audits_module") {
module_name = "audits"
imported_files = gypi_values.devtools_audits_js_files
}
copy_debug_module("copy_bindings_module") {
module_name = "bindings"
imported_files = gypi_values.devtools_bindings_js_files
}
copy_debug_module("copy_common_module") {
module_name = "common"
imported_files = gypi_values.devtools_common_js_files
}
copy_debug_module("copy_components_module") {
module_name = "components"
imported_files = gypi_values.devtools_components_js_files
}
copy_debug_module("copy_console_module") {
module_name = "console"
imported_files = gypi_values.devtools_console_js_files
}
copy_debug_module("copy_devices_module") {
module_name = "devices"
imported_files = gypi_values.devtools_devices_js_files
}
copy_debug_module("copy_documentation_module") {
module_name = "documentation"
imported_files = gypi_values.devtools_documentation_js_files
}
copy_debug_module("copy_elements_module") {
module_name = "elements"
imported_files = gypi_values.devtools_elements_js_files
}
copy_debug_module("copy_extensions_module") {
module_name = "extensions"
imported_files = devtools_extensions_js_files
}
copy_debug_module("copy_heap_snapshot_worker_module") {
module_name = "heap_snapshot_worker"
imported_files = gypi_values.devtools_heap_snapshot_worker_js_files
}
copy_debug_module("copy_host_module") {
module_name = "host"
imported_files = gypi_values.devtools_host_js_files
}
copy_debug_module("copy_layers_module") {
module_name = "layers"
imported_files = gypi_values.devtools_layers_js_files
}
copy_debug_module("copy_main_module") {
module_name = "main"
imported_files = gypi_values.devtools_main_js_files
}
copy_debug_module("copy_network_module") {
module_name = "network"
imported_files = gypi_values.devtools_network_js_files
}
copy_debug_module("copy_profiler_module") {
module_name = "profiler"
imported_files = gypi_values.devtools_profiler_js_files
}
copy_debug_module("copy_promises_module") {
module_name = "promises"
imported_files = gypi_values.devtools_promises_js_files
}
copy_debug_module("copy_resources_module") {
module_name = "resources"
imported_files = gypi_values.devtools_resources_js_files
}
copy_debug_module("copy_screencast_module") {
module_name = "screencast"
imported_files = gypi_values.devtools_screencast_js_files
}
group("copy_script_formatter_worker_module") {
copy_debug_module("copy_script_formatter_worker_module_base") {
module_name = "script_formatter_worker"
imported_files = gypi_values.devtools_uglify_files +
gypi_values.devtools_script_formatter_worker_js_files
}
copy("copy_uglify_js_files") {
sources = gypi_values.devtools_uglify_files
outputs = [ resources_out_dir + "UglifyJS/{{source_file_part}}" ]
}
deps = [ deps = [
":copy_script_formatter_worker_module_base", ":copy_runtime_core",
":copy_uglify_js_files" ":copy_uglify_js_files",
]
}
copy_debug_module("copy_sdk_module") {
module_name = "sdk"
imported_files = gypi_values.devtools_sdk_js_files
}
copy_debug_module("copy_settings_module") {
module_name = "settings"
imported_files = gypi_values.devtools_settings_js_files
}
group("copy_source_frame_module") {
copy_debug_module("copy_source_frame_module_base") {
module_name = "source_frame"
imported_files = gypi_values.devtools_source_frame_js_files
}
copy("copy_codemirror_js_files") {
sources = gypi_values.devtools_cm_js_files
outputs = [ resources_out_dir + "cm/{{source_file_part}}" ]
}
deps = [
":copy_source_frame_module_base",
":copy_codemirror_js_files", ":copy_codemirror_js_files",
] ]
} }
copy_debug_module("copy_sources_module") { copy("copy_runtime_core") {
module_name = "sources" sources = devtools_core_base_non_generated_files -
imported_files = gypi_values.devtools_sources_js_files gypi_values.devtools_standalone_files
} outputs = [ resources_out_dir + "/{{source_file_part}}" ]
copy_debug_module("copy_temp_storage_shared_worker_module") {
module_name = "temp_storage_shared_worker"
imported_files = gypi_values.devtools_temp_storage_shared_worker_js_files
}
copy_debug_module("copy_timeline_module") {
module_name = "timeline"
imported_files = gypi_values.devtools_timeline_js_files
}
copy_debug_module("copy_toolbox_module") {
module_name = "toolbox"
imported_files = gypi_values.devtools_toolbox_js_files
}
copy_debug_module("copy_toolbox_bootstrap_module") {
module_name = "toolbox_bootstrap"
imported_files = gypi_values.devtools_toolbox_bootstrap_js_files
} }
copy_debug_module("copy_ui_module") { copy("copy_uglify_js_files") {
module_name = "ui" sources = gypi_values.devtools_uglify_files
imported_files = gypi_values.devtools_ui_js_files outputs = [ resources_out_dir + "UglifyJS/{{source_file_part}}" ]
} }
copy_debug_module("copy_workspace_module") { copy("copy_codemirror_js_files") {
module_name = "workspace" sources = gypi_values.devtools_cm_js_files
imported_files = gypi_values.devtools_workspace_js_files outputs = [ resources_out_dir + "cm/{{source_file_part}}" ]
} }
} }
...@@ -540,7 +310,7 @@ if (!debug_devtools) { ...@@ -540,7 +310,7 @@ if (!debug_devtools) {
script = "scripts/concatenate_css_files.py" script = "scripts/concatenate_css_files.py"
input_stylesheet = "front_end/" + app_name + ".css" input_stylesheet = "front_end/" + app_name + ".css"
inputs = [ input_stylesheet ] + devtools_core_base_files inputs = [ input_stylesheet ] + devtools_core_base_non_generated_files
outputs = [ resources_out_dir + app_name + ".css" ] outputs = [ resources_out_dir + app_name + ".css" ]
......
...@@ -37,8 +37,6 @@ ...@@ -37,8 +37,6 @@
'target_name': 'devtools_frontend_resources', 'target_name': 'devtools_frontend_resources',
'type': 'none', 'type': 'none',
'dependencies': [ 'dependencies': [
'devtools_html',
'toolbox_html',
'supported_css_properties', 'supported_css_properties',
'frontend_protocol_sources', 'frontend_protocol_sources',
'build_applications', 'build_applications',
...@@ -61,38 +59,6 @@ ...@@ -61,38 +59,6 @@
}, },
], ],
}, },
{
'target_name': 'devtools_html',
'type': 'none',
'sources': ['front_end/devtools.html'],
'actions': [{
'action_name': 'devtools_html',
'script_name': 'scripts/generate_devtools_html.py',
'input_page': 'front_end/devtools.html',
'inputs': [
'<@(_script_name)',
'<@(_input_page)',
],
'outputs': ['<(PRODUCT_DIR)/resources/inspector/devtools.html'],
'action': ['python', '<@(_script_name)', '<@(_input_page)', '<@(_outputs)', '<@(debug_devtools)'],
}],
},
{
'target_name': 'toolbox_html',
'type': 'none',
'sources': ['front_end/toolbox.html'],
'actions': [{
'action_name': 'toolbox_html',
'script_name': 'scripts/generate_devtools_html.py',
'input_page': 'front_end/toolbox.html',
'inputs': [
'<@(_script_name)',
'<@(_input_page)',
],
'outputs': ['<(PRODUCT_DIR)/resources/inspector/toolbox.html'],
'action': ['python', '<@(_script_name)', '<@(_input_page)', '<@(_outputs)', '<@(debug_devtools)'],
}],
},
{ {
'target_name': 'devtools_extension_api', 'target_name': 'devtools_extension_api',
'type': 'none', 'type': 'none',
...@@ -111,8 +77,6 @@ ...@@ -111,8 +77,6 @@
'target_name': 'generate_devtools_grd', 'target_name': 'generate_devtools_grd',
'type': 'none', 'type': 'none',
'dependencies': [ 'dependencies': [
'devtools_html',
'toolbox_html',
'devtools_extension_api', 'devtools_extension_api',
'devtools_frontend_resources', 'devtools_frontend_resources',
], ],
...@@ -261,32 +225,33 @@ ...@@ -261,32 +225,33 @@
{ {
'target_name': 'build_applications', 'target_name': 'build_applications',
'type': 'none', 'type': 'none',
'conditions': [ 'dependencies': [
['debug_devtools==0', { # Release 'supported_css_properties',
'dependencies': [ 'frontend_protocol_sources',
'devtools_html', ],
'toolbox_html', 'output_path': '<(PRODUCT_DIR)/resources/inspector/',
'supported_css_properties', 'actions': [{
'frontend_protocol_sources', 'action_name': 'build_applications',
], 'script_name': 'scripts/build_applications.py',
'actions': [{ 'helper_scripts': [
'action_name': 'build_applications', 'scripts/modular_build.py',
'script_name': 'scripts/build_applications.py', 'scripts/concatenate_application_code.py',
'helper_scripts': [ ],
'scripts/modular_build.py', 'inputs': [
'scripts/concatenate_application_code.py', '<@(_script_name)',
], '<@(_helper_scripts)',
'inputs': [ '<@(all_devtools_files)',
'<@(_script_name)', '<(_output_path)/InspectorBackendCommands.js',
'<@(_helper_scripts)', '<(_output_path)/SupportedCSSProperties.js',
'<@(all_devtools_files)', ],
'<(PRODUCT_DIR)/resources/inspector/InspectorBackendCommands.js', 'action': ['python', '<@(_script_name)', 'devtools', 'toolbox', '--input_path', 'front_end', '--output_path', '<@(_output_path)', '--debug', '<@(debug_devtools)'],
'<(PRODUCT_DIR)/resources/inspector/SupportedCSSProperties.js', 'conditions': [
], ['debug_devtools==0', { # Release
'output_path': '<(PRODUCT_DIR)/resources/inspector/',
'outputs': [ 'outputs': [
'<(_output_path)/devtools.js', '<(_output_path)/devtools.js',
'<(_output_path)/devtools.html',
'<(_output_path)/toolbox.js', '<(_output_path)/toolbox.js',
'<(_output_path)/toolbox.html',
'<(_output_path)/audits_module.js', '<(_output_path)/audits_module.js',
'<(_output_path)/console_module.js', '<(_output_path)/console_module.js',
'<(_output_path)/devices_module.js', '<(_output_path)/devices_module.js',
...@@ -306,236 +271,40 @@ ...@@ -306,236 +271,40 @@
'<(_output_path)/temp_storage_shared_worker_module.js', '<(_output_path)/temp_storage_shared_worker_module.js',
'<(_output_path)/timeline_module.js', '<(_output_path)/timeline_module.js',
], ],
'action': ['python', '<@(_script_name)', 'devtools', 'toolbox', '--input_path', 'front_end', '--output_path', '<@(_output_path)', '--debug', '<@(debug_devtools)'], },
{ # Debug
'outputs': [
'<(_output_path)/devtools.html',
'<(_output_path)/toolbox.html',
]
}] }]
]
}],
'conditions': [
['debug_devtools==0', { # Release
}, },
{ # Debug { # Debug
# Copy Runtime.js and all modules of all applications here. # Copy runtime core and non-module directories here.
'app_target': '<(PRODUCT_DIR)/resources/inspector',
'copies': [ 'copies': [
{ {
'destination': '<(_app_target)', 'destination': '<(_output_path)',
'files': [
'<@(devtools_core_base_files)',
],
},
{
'destination': '<(_app_target)/common',
'files': [
'<@(devtools_common_js_files)',
'front_end/common/module.json',
],
},
{
'destination': '<(_app_target)/components',
'files': [
'<@(devtools_components_js_files)',
'front_end/components/module.json',
],
},
{
'destination': '<(_app_target)/sdk',
'files': [
'<@(devtools_sdk_js_files)',
'front_end/sdk/module.json',
],
},
{
'destination': '<(_app_target)/workspace',
'files': [
'<@(devtools_workspace_js_files)',
'front_end/workspace/module.json',
],
},
{
'destination': '<(_app_target)/bindings',
'files': [
'<@(devtools_bindings_js_files)',
'front_end/bindings/module.json',
],
},
{
'destination': '<(_app_target)/ui',
'files': [
'<@(devtools_ui_js_files)',
'front_end/ui/module.json',
],
},
{
'destination': '<(_app_target)/host',
'files': [
'<@(devtools_host_js_files)',
'front_end/host/module.json',
],
},
{
'destination': '<(_app_target)/screencast',
'files': [
'<@(devtools_screencast_js_files)',
'front_end/screencast/module.json',
],
},
{
'destination': '<(_app_target)/toolbox',
'files': [ 'files': [
'<@(devtools_toolbox_js_files)', '<@(devtools_core_base_non_generated_files)',
'front_end/toolbox/module.json',
], ],
}, },
{ {
'destination': '<(_app_target)/toolbox_bootstrap', 'destination': '<(_output_path)/UglifyJS',
'files': [
'<@(devtools_toolbox_bootstrap_js_files)',
'front_end/toolbox_bootstrap/module.json',
],
},
{
'destination': '<(_app_target)/main',
'files': [
'<@(devtools_main_js_files)',
'front_end/main/module.json',
],
},
{
'destination': '<(_app_target)/audits',
'files': [
'<@(devtools_audits_js_files)',
'front_end/audits/module.json',
],
},
{
'destination': '<(_app_target)/console',
'files': [
'<@(devtools_console_js_files)',
'front_end/console/module.json',
],
},
{
'destination': '<(_app_target)/devices',
'files': [
'<@(devtools_devices_js_files)',
'front_end/devices/module.json',
],
},
{
'destination': '<(_app_target)/documentation',
'files': [
'<@(devtools_documentation_js_files)',
'front_end/documentation/module.json',
],
},
{
'destination': '<(_app_target)/elements',
'files': [
'<@(devtools_elements_js_files)',
'front_end/elements/module.json',
],
},
{
'destination': '<(_app_target)/extensions',
'files': [
'<@(devtools_extensions_js_files)',
'front_end/extensions/module.json',
],
},
{
'destination': '<(_app_target)/heap_snapshot_worker',
'files': [
'<@(devtools_heap_snapshot_worker_js_files)',
'front_end/heap_snapshot_worker/module.json',
],
},
{
'destination': '<(_app_target)/layers',
'files': [
'<@(devtools_layers_js_files)',
'front_end/layers/module.json',
],
},
{
'destination': '<(_app_target)/network',
'files': [
'<@(devtools_network_js_files)',
'front_end/network/module.json',
],
},
{
'destination': '<(_app_target)/profiler',
'files': [
'<@(devtools_profiler_js_files)',
'front_end/profiler/module.json',
],
},
{
'destination': '<(_app_target)/promises',
'files': [
'<@(devtools_promises_js_files)',
'front_end/promises/module.json',
],
},
{
'destination': '<(_app_target)/resources',
'files': [
'<@(devtools_resources_js_files)',
'front_end/resources/module.json',
],
},
{
'destination': '<(_app_target)/script_formatter_worker',
'files': [
# FIXME: This will excessively copy files from common/ and cm/ folders into worker folder, which is fine for the debug mode.
'<@(devtools_script_formatter_worker_js_files)',
'front_end/script_formatter_worker/module.json',
],
},
{
'destination': '<(_app_target)/UglifyJS',
'files': [ 'files': [
'<@(devtools_uglify_files)', '<@(devtools_uglify_files)',
], ],
}, },
{ {
'destination': '<(_app_target)/settings', 'destination': '<(_output_path)/cm',
'files': [
'<@(devtools_settings_js_files)',
'front_end/settings/module.json',
],
},
{
'destination': '<(_app_target)/source_frame',
'files': [
'<@(devtools_source_frame_js_files)',
'front_end/source_frame/module.json',
],
},
{
'destination': '<(_app_target)/cm',
'files': [ 'files': [
'<@(devtools_cm_js_files)', '<@(devtools_cm_js_files)',
'<@(devtools_cm_css_files)', '<@(devtools_cm_css_files)',
], ],
}, },
{
'destination': '<(_app_target)/sources',
'files': [
'<@(devtools_sources_js_files)',
'front_end/sources/module.json',
],
},
{
'destination': '<(_app_target)/temp_storage_shared_worker',
'files': [
'<@(devtools_temp_storage_shared_worker_js_files)',
'front_end/temp_storage_shared_worker/module.json',
],
},
{
'destination': '<(_app_target)/timeline',
'files': [
'<@(devtools_timeline_js_files)',
'front_end/timeline/module.json',
],
}
] ]
}] }]
] ]
...@@ -563,9 +332,6 @@ ...@@ -563,9 +332,6 @@
{ {
'target_name': 'concatenated_devtools_css', 'target_name': 'concatenated_devtools_css',
'type': 'none', 'type': 'none',
'dependencies': [
'devtools_html',
],
'actions': [{ 'actions': [{
'action_name': 'concatenate_devtools_css', 'action_name': 'concatenate_devtools_css',
'script_name': 'scripts/concatenate_css_files.py', 'script_name': 'scripts/concatenate_css_files.py',
...@@ -583,9 +349,6 @@ ...@@ -583,9 +349,6 @@
{ {
'target_name': 'concatenated_toolbox_css', 'target_name': 'concatenated_toolbox_css',
'type': 'none', 'type': 'none',
'dependencies': [
'toolbox_html',
],
'actions': [{ 'actions': [{
'action_name': 'concatenate_toolbox_css', 'action_name': 'concatenate_toolbox_css',
'script_name': 'scripts/concatenate_css_files.py', 'script_name': 'scripts/concatenate_css_files.py',
......
...@@ -50,9 +50,12 @@ ...@@ -50,9 +50,12 @@
], ],
'devtools_core_base_files': [ 'devtools_core_base_files': [
'front_end/devtools.js', 'front_end/devtools.js',
'front_end/toolbox.js',
'<@(devtools_core_base_non_generated_files)',
],
'devtools_core_base_non_generated_files': [
'front_end/devtools.json', 'front_end/devtools.json',
'front_end/devtools.css', 'front_end/devtools.css',
'front_end/toolbox.js',
'front_end/toolbox.json', 'front_end/toolbox.json',
'front_end/toolbox.css', 'front_end/toolbox.css',
'front_end/Runtime.js', 'front_end/Runtime.js',
......
...@@ -5,18 +5,25 @@ ...@@ -5,18 +5,25 @@
# found in the LICENSE file. # found in the LICENSE file.
""" """
Concatenates autostart modules, application modules' module.json descriptors, Release:
and the application loader into a single script. - Concatenates autostart modules, application modules' module.json descriptors,
Also concatenates all workers' dependencies into individual worker loader scripts. and the application loader into a single script.
- Concatenates all workers' dependencies into individual worker loader scripts.
- Builds app.html referencing the application script.
Debug:
- Copies the module directories into their destinations.
- Copies app.html as-is.
""" """
from cStringIO import StringIO from cStringIO import StringIO
from os import path from os import path
from os.path import join
from modular_build import read_file, write_file, bail_error from modular_build import read_file, write_file, bail_error
import copy import copy
import modular_build import modular_build
import os import os
import re import re
import shutil
import sys import sys
try: try:
...@@ -24,8 +31,8 @@ try: ...@@ -24,8 +31,8 @@ try:
except ImportError: except ImportError:
import json import json
rjsmin_path = os.path.abspath(os.path.join( rjsmin_path = path.abspath(join(
os.path.dirname(__file__), path.dirname(__file__),
"..", "..",
"..", "..",
"build", "build",
...@@ -34,103 +41,190 @@ sys.path.append(rjsmin_path) ...@@ -34,103 +41,190 @@ sys.path.append(rjsmin_path)
import rjsmin import rjsmin
def minify_if_needed(javascript, minify): def minify_js(javascript):
return rjsmin.jsmin(javascript) if minify else javascript return rjsmin.jsmin(javascript)
def concatenated_module_filename(module_name, output_dir): def concatenated_module_filename(module_name, output_dir):
return path.join(output_dir, module_name + '_module.js') return join(output_dir, module_name + '_module.js')
def concatenate_autostart_modules(descriptors, application_dir, output_dir, output): def hardlink_or_copy_dir(src, dest):
non_autostart = set() if path.exists(dest):
sorted_module_names = descriptors.sorted_modules() shutil.rmtree(dest)
for name in sorted_module_names: for src_dir, dirs, files in os.walk(src):
desc = descriptors.modules[name] subpath = path.relpath(src_dir, src)
name = desc['name'] dest_dir = path.normpath(join(dest, subpath))
type = descriptors.application[name].get('type') os.mkdir(dest_dir)
if type == 'autostart': for name in files:
deps = set(desc.get('dependencies', [])) src_name = join(src_dir, name)
non_autostart_deps = deps & non_autostart dest_name = join(dest_dir, name)
if len(non_autostart_deps): if hasattr(os, 'link'):
bail_error('Non-autostart dependencies specified for the autostarted module "%s": %s' % (name, non_autostart_deps)) os.link(src_name, dest_name)
output.write('\n/* Module %s */\n' % name) else:
modular_build.concatenate_scripts(desc.get('scripts'), path.join(application_dir, name), output_dir, output) shutil.copy(src_name, dest_name)
elif type != 'worker':
non_autostart.add(name)
class AppBuilder:
def __init__(self, application_name, descriptors, application_dir, output_dir):
def concatenate_application_script(application_name, descriptors, application_dir, output_dir, minify): self.application_name = application_name
application_loader_name = application_name + '.js' self.descriptors = descriptors
output = StringIO() self.application_dir = application_dir
runtime_contents = read_file(path.join(application_dir, 'Runtime.js')) self.output_dir = output_dir
runtime_contents = re.sub('var allDescriptors = \[\];', 'var allDescriptors = %s;' % release_module_descriptors(descriptors.modules).replace("\\", "\\\\"), runtime_contents, 1)
output.write('/* Runtime.js */\n') def app_file(self, extension):
output.write(runtime_contents) return self.application_name + '.' + extension
output.write('\n/* Autostart modules */\n')
concatenate_autostart_modules(descriptors, application_dir, output_dir, output)
output.write('/* Application descriptor %s */\n' % (application_name + '.json')) # Outputs:
output.write('applicationDescriptor = ') # <app_name>.html
output.write(descriptors.application_json) # <app_name>.js
output.write(';\n/* Application loader */\n') # <module_name>_module.js
output.write(read_file(path.join(application_dir, application_loader_name))) class ReleaseBuilder(AppBuilder):
def __init__(self, application_name, descriptors, application_dir, output_dir):
write_file(path.join(output_dir, application_loader_name), minify_if_needed(output.getvalue(), minify)) AppBuilder.__init__(self, application_name, descriptors, application_dir, output_dir)
output.close()
def build_app(self):
self._build_html()
def concatenate_dynamic_module(module_name, descriptors, application_dir, output_dir, minify): self._build_app_script()
scripts = descriptors.modules[module_name].get('scripts') for module in filter(lambda desc: not desc.get('type'), self.descriptors.application.values()):
if not scripts: self._concatenate_dynamic_module(module['name'])
return for module in filter(lambda desc: desc.get('type') == 'worker', self.descriptors.application.values()):
module_dir = path.join(application_dir, module_name) self._concatenate_worker(module['name'])
output = StringIO()
modular_build.concatenate_scripts(scripts, module_dir, output_dir, output) def _build_html(self):
output_file_path = concatenated_module_filename(module_name, output_dir) html_name = self.app_file('html')
write_file(output_file_path, minify_if_needed(output.getvalue(), minify)) output = StringIO()
output.close() with open(join(self.application_dir, html_name), 'r') as app_input_html:
for line in app_input_html:
if '<script ' in line or '<link ' in line:
def concatenate_worker(module_name, descriptors, application_dir, output_dir, minify): continue
descriptor = descriptors.modules[module_name] if '</head>' in line:
scripts = descriptor.get('scripts') output.write(self._generate_include_tag("%s.css" % self.application_name))
if not scripts: output.write(self._generate_include_tag("%s.js" % self.application_name))
return output.write(line)
worker_dir = path.join(application_dir, module_name)
output_file_path = concatenated_module_filename(module_name, output_dir) write_file(join(self.output_dir, html_name), output.getvalue())
output.close()
output = StringIO()
output.write('/* Worker %s */\n' % module_name) def _build_app_script(self):
dependencies = descriptors.sorted_dependencies_closure(module_name) script_name = self.app_file('js')
dep_descriptors = [] output = StringIO()
for dep_name in dependencies: self._concatenate_application_script(output)
dep_descriptor = descriptors.modules[dep_name] write_file(join(self.output_dir, script_name), minify_js(output.getvalue()))
dep_descriptors.append(dep_descriptor) output.close()
scripts = dep_descriptor.get('scripts')
if scripts: def _generate_include_tag(self, resource_path):
output.write('\n/* Module %s */\n' % dep_name) if (resource_path.endswith('.js')):
modular_build.concatenate_scripts(scripts, path.join(application_dir, dep_name), output_dir, output) return ' <script type="text/javascript" src="%s"></script>\n' % resource_path
elif (resource_path.endswith('.css')):
write_file(output_file_path, minify_if_needed(output.getvalue(), minify)) return ' <link rel="stylesheet" type="text/css" href="%s">\n' % resource_path
output.close() else:
assert resource_path
def release_module_descriptors(module_descriptors): def _release_module_descriptors(self):
result = [] module_descriptors = self.descriptors.modules
for name in module_descriptors: result = []
module = copy.copy(module_descriptors[name]) for name in module_descriptors:
# Clear scripts, as they are not used at runtime module = copy.copy(module_descriptors[name])
# (only the fact of their presence is important). # Clear scripts, as they are not used at runtime
if module.get('scripts'): # (only the fact of their presence is important).
module['scripts'] = [] if module.get('scripts'):
result.append(module) module['scripts'] = []
return json.dumps(result) result.append(module)
return json.dumps(result)
def build_application(application_name, loader, application_dir, output_dir, minify): def _concatenate_autostart_modules(self, output):
non_autostart = set()
sorted_module_names = self.descriptors.sorted_modules()
for name in sorted_module_names:
desc = self.descriptors.modules[name]
name = desc['name']
type = self.descriptors.application[name].get('type')
if type == 'autostart':
deps = set(desc.get('dependencies', []))
non_autostart_deps = deps & non_autostart
if len(non_autostart_deps):
bail_error('Non-autostart dependencies specified for the autostarted module "%s": %s' % (name, non_autostart_deps))
output.write('\n/* Module %s */\n' % name)
modular_build.concatenate_scripts(desc.get('scripts'), join(self.application_dir, name), self.output_dir, output)
elif type != 'worker':
non_autostart.add(name)
def _concatenate_application_script(self, output):
application_loader_name = self.app_file('js')
runtime_contents = read_file(join(self.application_dir, 'Runtime.js'))
runtime_contents = re.sub('var allDescriptors = \[\];', 'var allDescriptors = %s;' % self._release_module_descriptors().replace("\\", "\\\\"), runtime_contents, 1)
output.write('/* Runtime.js */\n')
output.write(runtime_contents)
output.write('\n/* Autostart modules */\n')
self._concatenate_autostart_modules(output)
output.write('/* Application descriptor %s */\n' % self.app_file('json'))
output.write('applicationDescriptor = ')
output.write(self.descriptors.application_json)
output.write('\n/* Application loader */\n')
output.write(read_file(join(self.application_dir, application_loader_name)))
def _concatenate_dynamic_module(self, module_name):
module = self.descriptors.modules[module_name]
scripts = module.get('scripts')
if not scripts:
return
module_dir = join(self.application_dir, module_name)
output = StringIO()
modular_build.concatenate_scripts(scripts, module_dir, self.output_dir, output)
output_file_path = concatenated_module_filename(module_name, self.output_dir)
write_file(output_file_path, minify_js(output.getvalue()))
output.close()
def _concatenate_worker(self, module_name):
descriptor = self.descriptors.modules[module_name]
scripts = descriptor.get('scripts')
if not scripts:
return
output = StringIO()
output.write('/* Worker %s */\n' % module_name)
dep_descriptors = []
for dep_name in self.descriptors.sorted_dependencies_closure(module_name):
dep_descriptor = self.descriptors.modules[dep_name]
dep_descriptors.append(dep_descriptor)
scripts = dep_descriptor.get('scripts')
if scripts:
output.write('\n/* Module %s */\n' % dep_name)
modular_build.concatenate_scripts(scripts, join(self.application_dir, dep_name), self.output_dir, output)
output_file_path = concatenated_module_filename(module_name, self.output_dir)
write_file(output_file_path, minify_js(output.getvalue()))
output.close()
# Outputs:
# <app_name>.html as-is
# <app_name>.js as-is
# <module_name>/<all_files>
class DebugBuilder(AppBuilder):
def __init__(self, application_name, descriptors, application_dir, output_dir):
AppBuilder.__init__(self, application_name, descriptors, application_dir, output_dir)
def build_app(self):
self._build_html()
shutil.copy(join(self.application_dir, self.app_file('js')), self.output_dir)
for module_name in self.descriptors.modules:
module = self.descriptors.modules[module_name]
input_module_dir = join(self.application_dir, module_name)
output_module_dir = join(self.output_dir, module_name)
hardlink_or_copy_dir(input_module_dir, output_module_dir)
def _build_html(self):
html_name = self.app_file('html')
shutil.copy(join(self.application_dir, html_name), join(self.output_dir, html_name))
def build_application(application_name, loader, application_dir, output_dir, release_mode):
descriptors = loader.load_application(application_name + '.json') descriptors = loader.load_application(application_name + '.json')
concatenate_application_script(application_name, descriptors, application_dir, output_dir, minify) if release_mode:
for module in filter(lambda desc: not desc.get('type'), descriptors.application.values()): builder = ReleaseBuilder(application_name, descriptors, application_dir, output_dir)
concatenate_dynamic_module(module['name'], descriptors, application_dir, output_dir, minify) else:
for module in filter(lambda desc: desc.get('type') == 'worker', descriptors.application.values()): builder = DebugBuilder(application_name, descriptors, application_dir, output_dir)
concatenate_worker(module['name'], descriptors, application_dir, output_dir, minify) builder.build_app()
#!/usr/bin/env python
#
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from os import path
import os
import sys
def generate_include_tag(resource_path):
if (resource_path.endswith('.js')):
return ' <script type="text/javascript" src="%s"></script>\n' % resource_path
elif (resource_path.endswith('.css')):
return ' <link rel="stylesheet" type="text/css" href="%s">\n' % resource_path
else:
assert resource_path
def write_app_input_html(app_input_file, app_output_file, application_name, debug):
for line in app_input_file:
if not debug:
if '<script ' in line or '<link ' in line:
continue
if '</head>' in line:
app_output_file.write(generate_include_tag("%s.css" % application_name))
app_output_file.write(generate_include_tag("%s.js" % application_name))
app_output_file.write(line)
def main(argv):
if len(argv) < 4:
print('usage: %s app_input_html generated_app_html debug' % argv[0])
return 1
# The first argument is ignored. We put 'web.gyp' in the inputs list
# for this script, so every time the list of script gets changed, our html
# file is rebuilt.
app_input_html_name = argv[1]
app_output_html_name = argv[2]
debug = argv[3] != '0'
application_name = path.splitext(path.basename(app_input_html_name))[0]
with open(app_input_html_name, 'r') as app_input_html:
with open(app_output_html_name, 'w') as app_output_html:
write_app_input_html(app_input_html, app_output_html, application_name, debug)
if __name__ == '__main__':
sys.exit(main(sys.argv))
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