Bug 1524967 - Check if BinAST auto-generated source is update in build.sh. r=Yoric
authorTooru Fujisawa <arai_a@mac.com>
Sun, 24 Feb 2019 09:42:26 +0000
changeset 518647 5ddf9d49a6b3
parent 518646 1549e3c7bc51
child 518648 4c9346b3f7e3
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersYoric
bugs1524967
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1524967 - Check if BinAST auto-generated source is update in build.sh. r=Yoric Differential Revision: https://phabricator.services.mozilla.com/D20228
js/src/frontend/binsource/build.sh
js/src/frontend/binsource/src/main.rs
--- a/js/src/frontend/binsource/build.sh
+++ b/js/src/frontend/binsource/build.sh
@@ -1,17 +1,39 @@
 #!/bin/sh
 
 cargo run -- \
       ../BinSource.webidl_ \
       ../BinSource.yaml \
-      --out-class ../BinASTParser.h    \
-      --out-impl ../BinASTParser.cpp   \
-      --out-enum ../BinASTEnum.h    \
-      --out-token ../BinToken.h
+      --out-class ../BinASTParser-tmp.h    \
+      --out-impl ../BinASTParser-tmp.cpp   \
+      --out-enum ../BinASTEnum-tmp.h    \
+      --out-token ../BinToken-tmp.h
 
 MACH=../../../../mach
 
 ${MACH} clang-format --path \
-        ../BinASTParser.h \
-        ../BinASTParser.cpp \
-        ../BinASTEnum.h \
-        ../BinToken.h
+        ../BinASTParser-tmp.h \
+        ../BinASTParser-tmp.cpp \
+        ../BinASTEnum-tmp.h \
+        ../BinToken-tmp.h
+
+# Usage: update SRC DST
+#
+# If SRC file and DST file have different content, move SRC file to DST file.
+# If not, remove SRC file.
+update() {
+  SRC=$1
+  DST=$2
+
+  if diff -q ${SRC} ${DST} > /dev/null; then
+      echo "SKIPPED: ${DST} was not modified"
+      rm ${SRC}
+  else
+      echo "UPDATED: ${DST} was modified"
+      mv ${SRC} ${DST}
+  fi
+}
+
+update ../BinASTParser-tmp.h ../BinASTParser.h
+update ../BinASTParser-tmp.cpp ../BinASTParser.cpp
+update ../BinASTEnum-tmp.h ../BinASTEnum.h
+update ../BinToken-tmp.h ../BinToken.h
--- a/js/src/frontend/binsource/src/main.rs
+++ b/js/src/frontend/binsource/src/main.rs
@@ -13,17 +13,16 @@ use binjs_meta::util:: { Reindentable, T
 
 mod refgraph;
 
 use refgraph::{ ReferenceGraph };
 
 use std::collections::{ HashMap, HashSet };
 use std::fs::*;
 use std::io::{ Read, Write };
-use std::path::Path;
 use std::rc::Rc;
 
 use clap::{ App, Arg };
 
 use itertools::Itertools;
 
 /// Rules for generating the code for parsing a single field
 /// of a node.
@@ -2114,44 +2113,23 @@ fn main() {
     assert_eq!(yaml.len(), 1);
 
     let global_rules = GlobalRules::new(&new_syntax, &yaml[0]);
     let mut exporter = CPPExporter::new(new_syntax, global_rules);
 
     exporter.generate_reference_graph();
     exporter.trace(Rc::new(TOPLEVEL_INTERFACE.to_string()));
 
-    let get_file_content = |path: &str| {
-        if !Path::new(path).is_file() {
-            return None;
-        }
-
-        let mut f = File::open(path)
-            .expect("File not found");
-        let mut contents = String::new();
-        f.read_to_string(&mut contents)
-            .expect("Failed to read file");
-        Some(contents)
-    };
     let write_to = |description, arg, data: &String| {
         let dest_path = matches.value_of(arg)
             .unwrap();
         print!("...exporting {description}: {path} ... ",
             description = description,
             path = dest_path);
 
-        if let Some(old_data) = get_file_content(dest_path) {
-            if old_data == *data {
-                // To avoid unnecessary rebuild, do not touch the file if the
-                // content is not updated.
-                println!("skip");
-                return;
-            }
-        };
-
         let mut dest = File::create(&dest_path)
             .unwrap_or_else(|e| panic!("Could not create {description} at {path}: {error}",
                             description = description,
                             path = dest_path,
                             error = e));
         dest.write_all(data.as_bytes())
             .unwrap_or_else(|e| panic!("Could not write {description} at {path}: {error}",
                             description = description,