fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 1 | # Copyright (C) 2011 Apple Inc. All rights reserved. |
| 2 | # |
| 3 | # Redistribution and use in source and binary forms, with or without |
| 4 | # modification, are permitted provided that the following conditions |
| 5 | # are met: |
| 6 | # 1. Redistributions of source code must retain the above copyright |
| 7 | # notice, this list of conditions and the following disclaimer. |
| 8 | # 2. Redistributions in binary form must reproduce the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer in the |
| 10 | # documentation and/or other materials provided with the distribution. |
| 11 | # |
| 12 | # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 13 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 14 | # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 15 | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 16 | # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 17 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 18 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 19 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 20 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 21 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 22 | # THE POSSIBILITY OF SUCH DAMAGE. |
| 23 | |
commit-queue@webkit.org | 782c20b | 2012-07-14 00:44:47 +0000 | [diff] [blame] | 24 | require "config" |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 25 | require "digest/sha1" |
| 26 | require "pathname" |
| 27 | |
| 28 | # |
fpizlo@apple.com | 64b9285 | 2012-02-26 00:19:07 +0000 | [diff] [blame] | 29 | # dirHash(directory, regexp) -> SHA1 hexdigest |
| 30 | # |
| 31 | # Returns a hash of all files in the given directory that fit the given |
| 32 | # pattern. |
| 33 | # |
| 34 | |
| 35 | def dirHash(directory, regexp) |
| 36 | directory = Pathname.new(directory) |
| 37 | contents = "" |
| 38 | Dir.foreach(directory) { |
| 39 | | entry | |
| 40 | if entry =~ regexp |
| 41 | contents += IO::read(directory + entry) |
| 42 | end |
| 43 | } |
| 44 | return Digest::SHA1.hexdigest(contents) |
| 45 | end |
| 46 | |
| 47 | # |
msaboff@apple.com | 8f8907e | 2014-04-10 22:33:59 +0000 | [diff] [blame] | 48 | # fileListHash(fileList) -> SHA1 hexdigest |
| 49 | # |
| 50 | # Returns a hash of all files in the list. |
| 51 | # |
| 52 | |
| 53 | def fileListHash(fileList) |
| 54 | contents = "" |
| 55 | fileList.each { |
| 56 | | fileName | |
| 57 | contents += IO::read(fileName) |
| 58 | } |
| 59 | return Digest::SHA1.hexdigest(contents) |
| 60 | end |
| 61 | |
| 62 | # |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 63 | # selfHash -> SHA1 hexdigest |
| 64 | # |
| 65 | # Returns a hash of the offlineasm source code. This allows dependency |
| 66 | # tracking for not just changes in input, but also changes in the assembler |
| 67 | # itself. |
| 68 | # |
| 69 | |
| 70 | def selfHash |
fpizlo@apple.com | 64b9285 | 2012-02-26 00:19:07 +0000 | [diff] [blame] | 71 | dirHash(Pathname.new(__FILE__).dirname, /\.rb$/) |
fpizlo@apple.com | 7bbcaab | 2012-02-22 05:23:19 +0000 | [diff] [blame] | 72 | end |
| 73 | |