hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1405602 - in /hadoop/common/branches/branch-1-win: CHANGES.branch-1-win.txt build.xml src/saveVersion.py src/saveVersion.sh
Date Sun, 04 Nov 2012 18:47:29 GMT
Author: suresh
Date: Sun Nov  4 18:47:29 2012
New Revision: 1405602

URL: http://svn.apache.org/viewvc?rev=1405602&view=rev
Log:
HADOOP-8420. Hadoop Common creating package-info.java must not depend on sh. Contributed by
Bikas Saha.

Added:
    hadoop/common/branches/branch-1-win/src/saveVersion.py
Modified:
    hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
    hadoop/common/branches/branch-1-win/build.xml
    hadoop/common/branches/branch-1-win/src/saveVersion.sh

Modified: hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt?rev=1405602&r1=1405601&r2=1405602&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt (original)
+++ hadoop/common/branches/branch-1-win/CHANGES.branch-1-win.txt Sun Nov  4 18:47:29 2012
@@ -197,3 +197,6 @@ Branch-hadoop-1-win - unreleased
 
     HADOOP-8949. Remove FileUtil.CygPathCommand dead code. (Chris Nauroth via 
     suresh)
+
+    HADOOP-8420. Hadoop Common creating package-info.java must not depend on sh.
+    (Bikas Saha via suresh)

Modified: hadoop/common/branches/branch-1-win/build.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/build.xml?rev=1405602&r1=1405601&r2=1405602&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/build.xml (original)
+++ hadoop/common/branches/branch-1-win/build.xml Sun Nov  4 18:47:29 2012
@@ -443,8 +443,8 @@
       <mapper type="glob" from="*.template" to="*"/>
     </copy>
 
-    <exec executable="sh">
-       <arg line="src/saveVersion.sh ${version} ${build.dir}"/>
+    <exec executable="python">
+       <arg line="src/saveVersion.py ${version} ${build.dir}"/>
     </exec>
 	
    <exec executable="sh">

Added: hadoop/common/branches/branch-1-win/src/saveVersion.py
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/saveVersion.py?rev=1405602&view=auto
==============================================================================
--- hadoop/common/branches/branch-1-win/src/saveVersion.py (added)
+++ hadoop/common/branches/branch-1-win/src/saveVersion.py Sun Nov  4 18:47:29 2012
@@ -0,0 +1,150 @@
+#! /usr/bin/python
+
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+# This file is used to generate the BuildStamp.java class that
+# records the user, url, revision and timestamp.
+
+import os
+import sys
+import re
+import subprocess
+import getpass
+import time
+import socket
+import hashlib
+
+def usage():
+  print >>sys.stderr, "Usage: saveVersion.py <version> <build_directory>"
+  print >>sys.stderr, "Eg:    saveVersion.py  1.1.0  build"
+
+
+# This template is what gets written to build/src/o.a.h/BuildStamp.java
+# It is filled out by (version, revision, user, date, url, srcChecksum)
+
+template_string = \
+'''/*
+ * Generated by src/saveVersion.py
+ */
+@HadoopVersionAnnotation(version="%s", revision="%s",
+                         user="%s", date="%s", url="%s",
+                         srcChecksum="%s")
+package org.apache.hadoop;
+'''
+
+# Convert Windows paths with back-slashes into canonical Unix paths
+# with forward slashes.  Unix paths are unchanged.  Mixed formats
+# just naively have back-slashes converted to forward slashes.
+def canonicalpath(path):
+  return re.sub('\\\\','/',path)
+
+# This is an implementation of md5sum-like functionality in pure python.
+# The path name is output in canonical form to get the same aggregate
+# checksum as Linux.
+def md5sum(fname):
+  block_size = 2**20
+  f = open(os.path.normpath(fname), 'rb')  # open in binary mode to make sure EOLs don't
get munged
+  md5 = hashlib.md5()
+  while True:
+    data = f.read(block_size)
+    if not data:
+      break
+    md5.update(data)
+  f.close()
+  return "%s %s\n" % (md5.hexdigest(), canonicalpath(fname))
+
+# Roughly emulate the Python 2.7 functionality of "subprocess.check_output()"
+# by accepting a CLI vector [cmd, arg1, arg2, ...], and returning its stdout result,
+# but without the "checking".  For use in lower version Python interpreters.
+def subprocessOutput(args):
+  # result = subprocess.check_output(args, shell=True) # requires py2.7
+  process = subprocess.Popen(args, stdout=subprocess.PIPE)
+  result = process.communicate()[0].strip()
+  return result
+
+# Strip surrounding quotes from a string object that carried its quotes with it.
+def stripquotes(s):
+  if (s[0] == '"' and s[-1] == '"') or (s[0] == "'" and s[-1] == "'") :
+    return s[1:-1]
+  elif (s[0] == '\\' and s[-1] == '"') :
+    return s[1:-1]
+  else:
+    return s
+
+
+def main(argv=None):
+  if argv is None:
+    argv = sys.argv[1:3]
+  if (len(argv) != 2) or (argv[0] == "--help") or (argv[0] == "-h"):
+    usage()
+    return -1
+
+  version = argv[0]
+  build_dir = argv[1]
+
+  user = getpass.getuser()
+  date = time.strftime("%a %b %d %H:%M:%S %Z %Y")  # simulate `date`
+
+  if os.path.isdir(".git"):
+    revision = stripquotes(subprocessOutput(['git', 'log', '-1', '--pretty=format:"%H"']))
+    origin = subprocessOutput(['git', 'config', '--get', 'remote.origin.url'])
+    branch = subprocessOutput(['git', 'branch'])
+
+    filter_current_branch = re.compile(r'^\* (.*)$', re.MULTILINE)
+    current_branch = filter_current_branch.search(branch).group(1).strip()
+    url = "%s on branch %s" % (origin, current_branch)
+  else:
+    svn_info = subprocessOutput(['svn', 'info'])
+    filter_last_revision = re.compile(r'^Last Changed Rev: (.*)$', re.MULTILINE)
+    revision = filter_last_revision.search(svn_info).group(1).strip()
+
+    filter_url = re.compile(r'^URL: (.*)$', re.MULTILINE)
+    url = filter_url.search(svn_info).group(1).strip()
+
+  filter_java = re.compile(r'.+\.java$')
+  file_list = []
+  for root, dirs, files in os.walk("src"):
+    for name in files:
+      if filter_java.match(name):
+        file_list.append(canonicalpath(os.path.join(root, name)))
+
+  # Sorting is done on unix-format names, case-folded, in order to get a platform-independent
sort.
+  file_list.sort(key=str.upper)
+  file_count = len(file_list)
+  hash = hashlib.md5()
+  for name in file_list:
+    file_hash_string = md5sum(name)
+    hash.update(file_hash_string)
+
+  srcChecksum = hash.hexdigest()
+
+  target_dir = os.path.join(os.path.normpath(build_dir),
+                            os.path.normpath('src/org/apache/hadoop'))
+  if not os.path.exists(target_dir):
+    os.makedirs(target_dir)
+
+  target_file = os.path.join(target_dir, 'package-info.java')
+  fout = open(target_file, "w")
+  fout.write(template_string % (version, revision, user, date, url, srcChecksum))
+  fout.close()
+
+  print("Checksummed %s src/**.java files" % file_count)
+  return 0
+
+##########################
+if __name__ == "__main__":
+  sys.exit(main())

Modified: hadoop/common/branches/branch-1-win/src/saveVersion.sh
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/saveVersion.sh?rev=1405602&r1=1405601&r2=1405602&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/saveVersion.sh (original)
+++ hadoop/common/branches/branch-1-win/src/saveVersion.sh Sun Nov  4 18:47:29 2012
@@ -20,20 +20,29 @@
 # records the user, url, revision and timestamp.
 unset LANG
 unset LC_CTYPE
+if [[ `which md5sum` != "" ]]; then
+  # linux
+  export MD5SUM="md5sum"
+elif [[ `which md5` != "" ]]; then
+  # mac
+  export MD5SUM="md5 -r"
+fi
+
 version=$1
 build_dir=$2
 user=`whoami`
 date=`date`
 if [ -d .git ]; then
   revision=`git log -1 --pretty=format:"%H"`
-  hostname=`hostname`
+  origin=`git config --get remote.origin.url`
   branch=`git branch | sed -n -e 's/^* //p'`
-  url="git://$hostname/$cwd on branch $branch"
+  url="$origin on branch $branch"
 else
   revision=`svn info | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
   url=`svn info | sed -n -e 's/URL: \(.*\)/\1/p'`
 fi
-srcChecksum=`find src -name '*.java' | LC_ALL=C sort | xargs md5sum | md5sum | cut -d ' '
-f 1`
+srcChecksum=`find src -name '*.java' | LC_ALL=C sort -f | xargs $MD5SUM | $MD5SUM | cut -d
' ' -f 1`
+file_count=`find src -name '*.java' | LC_ALL=C sort -f | wc -l`
 
 mkdir -p $build_dir/src/org/apache/hadoop
 cat << EOF | \
@@ -48,3 +57,5 @@ cat << EOF | \
                          srcChecksum="SRCCHECKSUM")
 package org.apache.hadoop;
 EOF
+
+echo "Checksummed $file_count src/**.java files"



Mime
View raw message