Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Unified Diff: third_party/polymer/v1_0/gendeps.js

Issue 1695663004: Adding GYP V2 targets for all Polymer code (with a script!). Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding JSDoc. Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/polymer/v1_0/components-chromium/paper-tooltip/compiled_resources2.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/polymer/v1_0/gendeps.js
diff --git a/third_party/polymer/v1_0/gendeps.js b/third_party/polymer/v1_0/gendeps.js
new file mode 100644
index 0000000000000000000000000000000000000000..fcbd21a5a5c892164ad02006260d01846ed1b98c
--- /dev/null
+++ b/third_party/polymer/v1_0/gendeps.js
@@ -0,0 +1,91 @@
+var fs = require('fs');
+var path = require('path');
+var glob = require('glob').sync;
+
+var chromiumHeader =
+ '# Copyright 2016 The Chromium Authors. All rights reserved.\n' +
+ '# Use of this source code is governed by a BSD-style license that can be\n' +
+ '# found in the LICENSE file.\n';
+var ignoreFiles = new Set(['index']);
+
+/**
+ * Generates a compiled_resources2.gyp file for all elements defined under the
+ * given folder.
+ * @param {string} folder
+ */
+function processFolder(folder) {
+ var htmlFiles = glob(folder + '/**/*.html').filter(function(file) {
+ return !ignoreFiles.has(path.basename(file, '.html'));
+ });
+ var targets = htmlFiles.map(function(file) {
+ return createTarget(file, detectDependencies(file));
+ });
+ var compiledResourcesContents = chromiumHeader +
+ JSON.stringify({targets: targets}, undefined, 2).replace(/"/g, '\'');
+ fs.writeFileSync(
+ path.join(folder, 'compiled_resources2.gyp'),
+ compiledResourcesContents);
+}
+
+/**
+ * Detects the dependencies of the given HTML file.
+ * @param {string} file
+ * @return {!Array<string>}
+ */
+function detectDependencies(file) {
+ var fileContents = fs.readFileSync(file, {encoding: 'utf8'});
+ var regexp = /^<link rel="import" href="(.*)"/;
+ var lines = fileContents.split('\n');
+ var dependencies = [];
+ lines.forEach(function(line) {
+ var results = regexp.exec(line);
+ if (results && results[1].indexOf('/polymer.html') == -1) {
+ dependencies.push(results[1]);
+ }
+ });
+ return dependencies;
+}
+
+/**
+ * Converts a file name to a GYP target name.
+ * @param {string} file
+ * @return {string}
+ */
+function fileToTarget(file) {
+ return path.basename(file, '.html') + '-extracted';
+}
+
+
+/**
+ * Creates a GYP target for the given file.
+ * @param {string} file
+ * @param {!Array<string>} fileDependencies
+ * @return {{target_name: string, dependencies: !Array<string>, includes: string}}
+ */
+function createTarget(file, fileDependencies) {
+ var gypDependencies = fileDependencies.map(function(dep) {
+ var parts = dep.split(path.sep);
+ if (parts.length == 1) {
+ return fileToTarget(parts[0]);
+ }
+ return path.join(parts[0], parts[1], 'compiled_resources2.gyp:') +
+ fileToTarget(parts[parts.length -1]);
+ });
+ var obj = {
+ target_name: fileToTarget(file),
+ };
+ if (gypDependencies.length > 0) {
+ obj.dependencies = gypDependencies;
+ }
+ obj.includes = ['../../../../closure_compiler/compile_js2.gypi'];
+ return obj;
+}
+
+var ignoreFolders = new Set(['polymer', 'polymer-externs']);
+var srcDir = path.resolve(path.join(__dirname, 'components-chromium'));
+
+fs.readdirSync(srcDir).filter(function(folder) {
+ return !ignoreFolders.has(folder);
+}).map(function(folder) {
+ return path.join(srcDir, folder);
+}).forEach(processFolder);
« no previous file with comments | « third_party/polymer/v1_0/components-chromium/paper-tooltip/compiled_resources2.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698