Revision: 859 http://trac.macosforge.org/projects/darwinbuild/changeset/859 Author: wsiegrist@apple.com Date: 2010-08-06 14:39:09 -0700 (Fri, 06 Aug 2010) Log Message: ----------- Add digest helper to replace openssl dgst -sha1 Modified Paths: -------------- branches/PR-8279204/darwinbuild/darwinbuild.common branches/PR-8279204/darwinbuild/darwinbuild.in branches/PR-8279204/darwinbuild.xcodeproj/project.pbxproj Added Paths: ----------- branches/PR-8279204/darwinbuild/digest.c Modified: branches/PR-8279204/darwinbuild/darwinbuild.common =================================================================== --- branches/PR-8279204/darwinbuild/darwinbuild.common 2010-08-06 21:36:40 UTC (rev 858) +++ branches/PR-8279204/darwinbuild/darwinbuild.common 2010-08-06 21:39:09 UTC (rev 859) @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2005, Apple Computer, Inc. All rights reserved. +# Copyright (c) 2005-2010, Apple Computer, Inc. All rights reserved. # # @APPLE_BSD_LICENSE_HEADER_START@ # @@ -533,10 +533,10 @@ echo "ERROR: Could not access $HashSource" 1>&2 exit 1 fi - Hash=$(openssl dgst -sha1 < "$HashSource") + Hash=$($DIGEST < "$HashSource") echo "# Hash of $HashSource" >> "$TmpFile" else - Hash=$(openssl dgst -sha1 < "$TmpFile") + Hash=$($DIGEST < "$TmpFile") fi cp "$TmpFile" "$receipts/$Hash" Modified: branches/PR-8279204/darwinbuild/darwinbuild.in =================================================================== --- branches/PR-8279204/darwinbuild/darwinbuild.in 2010-08-06 21:36:40 UTC (rev 858) +++ branches/PR-8279204/darwinbuild/darwinbuild.in 2010-08-06 21:39:09 UTC (rev 859) @@ -1,6 +1,6 @@ #!/bin/sh # -# Copyright (c) 2004-2005, Apple Computer, Inc. All rights reserved. +# Copyright (c) 2004-2010, Apple Computer, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -81,6 +81,7 @@ NFSDIR=.build/buildroot.nfs DARWINXREF=$PREFIX/bin/darwinxref DATADIR=$PREFIX/share/darwinbuild +DIGEST=$DATADIR/digest COMMONFILE=$DATADIR/darwinbuild.common DARWINTRACE=$DATADIR/darwintrace.dylib DITTO=$DATADIR/ditto @@ -993,7 +994,7 @@ ### Output the manifest MANIFEST="/tmp/$projnam.$$" "$DARWINXREF" register "$projnam" "$REAL_DSTROOT" | tee "$MANIFEST" - SHA1=$(cat "$MANIFEST" | openssl dgst -sha1) + SHA1=$(cat "$MANIFEST" | $DIGEST) mkdir -p "$REAL_DSTROOT/usr/local/darwinbuild/receipts" cp "$MANIFEST" "$REAL_DSTROOT/usr/local/darwinbuild/receipts/$SHA1" ln -s "$SHA1" "$REAL_DSTROOT/usr/local/darwinbuild/receipts/$projnam.hdrs" @@ -1007,7 +1008,7 @@ ### in the receipts directory after registration. MANIFEST="/tmp/$projnam.$$" "$DARWINXREF" register "$projnam" "$REAL_DSTROOT" | tee "$MANIFEST" - SHA1=$(cat "$MANIFEST" | openssl dgst -sha1) + SHA1=$(cat "$MANIFEST" | $DIGEST) mkdir -p "$REAL_DSTROOT/usr/local/darwinbuild/receipts" cp "$MANIFEST" "$REAL_DSTROOT/usr/local/darwinbuild/receipts/$SHA1" ln -s "$SHA1" "$REAL_DSTROOT/usr/local/darwinbuild/receipts/$projnam" Added: branches/PR-8279204/darwinbuild/digest.c =================================================================== --- branches/PR-8279204/darwinbuild/digest.c (rev 0) +++ branches/PR-8279204/darwinbuild/digest.c 2010-08-06 21:39:09 UTC (rev 859) @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2010 Apple Computer, Inc. All rights reserved. + * + * @APPLE_BSD_LICENSE_HEADER_START@ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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. + * + * @APPLE_BSD_LICENSE_HEADER_END@ + */ + +#include <sys/types.h> +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <CommonCrypto/CommonDigest.h> + + +void print_usage() { + fprintf(stdout, "digest [-1] \n"); + fprintf(stdout, " Print digest hash of stdin to stdout. \n"); + fprintf(stdout, " \n"); + fprintf(stdout, " -1 Use SHA1 hash (default) \n"); + fprintf(stdout, " \n"); +} + +char* format_digest(const unsigned char* m) { + char* result = NULL; + // SHA-1 + asprintf(&result, + "%02x%02x%02x%02x" + "%02x%02x%02x%02x" + "%02x%02x%02x%02x" + "%02x%02x%02x%02x" + "%02x%02x%02x%02x", + m[0], m[1], m[2], m[3], + m[4], m[5], m[6], m[7], + m[8], m[9], m[10], m[11], + m[12], m[13], m[14], m[15], + m[16], m[17], m[18], m[19] + ); + return result; +} + +char* calculate_digest(int fd) { + unsigned char md[20]; + CC_SHA1_CTX c; + CC_SHA1_Init(&c); + + memset(md, 0, 20); + + ssize_t len; + const unsigned int blocklen = 8192; + unsigned char* block = (unsigned char*)malloc(blocklen); + if (!block) { + errno = ENOMEM; + return NULL; + } + while(1) { + len = read(fd, block, blocklen); + if (len == 0) { close(fd); break; } + if ((len < 0) && (errno == EINTR)) continue; + if (len < 0) { close(fd); return NULL; } + CC_SHA1_Update(&c, block, (size_t)len); + } + + CC_SHA1_Final(md, &c); + free(block); + return format_digest(md); +} + + +int main(int argc, char* argv[]) { + + int digest = 1; // default to SHA1 + + int ch; + while ((ch = getopt(argc, argv, "1")) != -1) { + switch (ch) { + case '1': + digest = 1; + break; + case '?': + default: + print_usage(); + exit(1); + } + } + argc -= optind; + argv += optind; + + fprintf(stdout, "%s\n", calculate_digest(fileno(stdin))); + + return 0; +} Modified: branches/PR-8279204/darwinbuild.xcodeproj/project.pbxproj =================================================================== --- branches/PR-8279204/darwinbuild.xcodeproj/project.pbxproj 2010-08-06 21:36:40 UTC (rev 858) +++ branches/PR-8279204/darwinbuild.xcodeproj/project.pbxproj 2010-08-06 21:39:09 UTC (rev 859) @@ -25,6 +25,7 @@ 7227AD1B109A053900BE33D7 /* CopyFiles */, ); dependencies = ( + 720BE2F6120C90E500B3C4A5 /* PBXTargetDependency */, 7227AC421098DC6A00BE33D7 /* PBXTargetDependency */, 7227AC401098DC6A00BE33D7 /* PBXTargetDependency */, 7227AC3E1098DC6A00BE33D7 /* PBXTargetDependency */, @@ -101,6 +102,7 @@ /* Begin PBXBuildFile section */ 61E0A6BD10A8DCC700DA7EBC /* exportIndex.c in Sources */ = {isa = PBXBuildFile; fileRef = 72C86BFF10965EEA00C66E90 /* exportIndex.c */; }; + 720BE2F4120C90C500B3C4A5 /* digest.c in Sources */ = {isa = PBXBuildFile; fileRef = 720BE2E9120C909E00B3C4A5 /* digest.c */; }; 7227AB41109897D500BE33D7 /* binary_sites.tcl in CopyFiles */ = {isa = PBXBuildFile; fileRef = 72C86BF310965EEA00C66E90 /* binary_sites.tcl */; }; 7227AB42109897D500BE33D7 /* branch.tcl in CopyFiles */ = {isa = PBXBuildFile; fileRef = 72C86BF410965EEA00C66E90 /* branch.tcl */; }; 7227AB43109897D500BE33D7 /* currentBuild.tcl in CopyFiles */ = {isa = PBXBuildFile; fileRef = 72C86BF610965EEA00C66E90 /* currentBuild.tcl */; }; @@ -171,6 +173,13 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 720BE2F5120C90E500B3C4A5 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 726DD14910965C5700D5AEAB /* Project object */; + proxyType = 1; + remoteGlobalIDString = 720BE2EA120C90A700B3C4A5; + remoteInfo = digest; + }; 7227AB0F1097BBA900BE33D7 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 726DD14910965C5700D5AEAB /* Project object */; @@ -658,6 +667,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 720BE2E9120C909E00B3C4A5 /* digest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = digest.c; path = darwinbuild/digest.c; sourceTree = "<group>"; }; + 720BE2F2120C90A700B3C4A5 /* digest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = digest; sourceTree = BUILT_PRODUCTS_DIR; }; 7227AB6D10989A9900BE33D7 /* manifest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = manifest; sourceTree = BUILT_PRODUCTS_DIR; }; 7227AB871098A7BF00BE33D7 /* buildlist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = buildlist; path = darwinbuild/buildlist; sourceTree = "<group>"; }; 7227AB881098A7BF00BE33D7 /* buildorder */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = buildorder; path = darwinbuild/buildorder; sourceTree = "<group>"; }; @@ -784,6 +795,13 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 720BE2ED120C90A700B3C4A5 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 7227AB6B10989A9900BE33D7 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1007,6 +1025,7 @@ 72C86BD510965DC900C66E90 /* darwinbuild */ = { isa = PBXGroup; children = ( + 720BE2E9120C909E00B3C4A5 /* digest.c */, 7227AB871098A7BF00BE33D7 /* buildlist */, 7227AB881098A7BF00BE33D7 /* buildorder */, 7227AB891098A7BF00BE33D7 /* ditto */, @@ -1162,6 +1181,7 @@ 7227AC251098DB9200BE33D7 /* installXcode */, 7227AC2E1098DBDF00BE33D7 /* installXcode32 */, 72D05CB711D267C400B33EDD /* query.so */, + 720BE2F2120C90A700B3C4A5 /* digest */, ); name = Products; sourceTree = "<group>"; @@ -1188,6 +1208,22 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 720BE2EA120C90A700B3C4A5 /* digest */ = { + isa = PBXNativeTarget; + buildConfigurationList = 720BE2EE120C90A700B3C4A5 /* Build configuration list for PBXNativeTarget "digest" */; + buildPhases = ( + 720BE2EB120C90A700B3C4A5 /* Sources */, + 720BE2ED120C90A700B3C4A5 /* Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = digest; + productName = digest; + productReference = 720BE2F2120C90A700B3C4A5 /* digest */; + productType = "com.apple.product-type.tool"; + }; 7227AB6C10989A9900BE33D7 /* manifest */ = { isa = PBXNativeTarget; buildConfigurationList = 7227AB7310989ACD00BE33D7 /* Build configuration list for PBXNativeTarget "manifest" */; @@ -1816,6 +1852,7 @@ 7227AC1E1098DB9200BE33D7 /* installXcode */, 7227AC271098DBDF00BE33D7 /* installXcode32 */, 7227AC7E1098EF6400BE33D7 /* libredo_prebinding.a */, + 720BE2EA120C90A700B3C4A5 /* digest */, ); }; /* End PBXProject section */ @@ -2017,6 +2054,14 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 720BE2EB120C90A700B3C4A5 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 720BE2F4120C90C500B3C4A5 /* digest.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 7227AB6A10989A9900BE33D7 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2258,6 +2303,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 720BE2F6120C90E500B3C4A5 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 720BE2EA120C90A700B3C4A5 /* digest */; + targetProxy = 720BE2F5120C90E500B3C4A5 /* PBXContainerItemProxy */; + }; 7227AB101097BBA900BE33D7 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 725740981097B051008AD4D7 /* darwinxref_plugins */; @@ -2571,6 +2621,33 @@ /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ + 720BE2EF120C90A700B3C4A5 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7227AB9C1098AAE100BE33D7 /* prefix.xcconfig */; + buildSettings = { + INSTALL_PATH = "$(DATDIR)/darwinbuild"; + PRODUCT_NAME = digest; + }; + name = Debug; + }; + 720BE2F0120C90A700B3C4A5 /* Public */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7227AB9C1098AAE100BE33D7 /* prefix.xcconfig */; + buildSettings = { + INSTALL_PATH = "$(DATDIR)/darwinbuild"; + PRODUCT_NAME = digest; + }; + name = Public; + }; + 720BE2F1120C90A700B3C4A5 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7227AB9C1098AAE100BE33D7 /* prefix.xcconfig */; + buildSettings = { + INSTALL_PATH = "$(DATDIR)/darwinbuild"; + PRODUCT_NAME = digest; + }; + name = Release; + }; 7227AB3E1098977D00BE33D7 /* Debug */ = { isa = XCBuildConfiguration; baseConfigurationReference = 7227AB9C1098AAE100BE33D7 /* prefix.xcconfig */; @@ -3599,6 +3676,16 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 720BE2EE120C90A700B3C4A5 /* Build configuration list for PBXNativeTarget "digest" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 720BE2EF120C90A700B3C4A5 /* Debug */, + 720BE2F0120C90A700B3C4A5 /* Public */, + 720BE2F1120C90A700B3C4A5 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Public; + }; 7227AB4A109897E500BE33D7 /* Build configuration list for PBXAggregateTarget "tcl_plugins" */ = { isa = XCConfigurationList; buildConfigurations = (
participants (1)
-
source_changes@macosforge.org