public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Qin Long <qin.long@intel.com>
To: edk2-devel@lists.01.org
Cc: ting.ye@intel.com, jiaxin.wu@intel.com, lersek@redhat.com,
	ard.biesheuvel@linaro.org, glin@suse.com, ronald.cron@arm.com,
	David Woodhouse <dwmw2@infradead.org>
Subject: [PATCH v1 4/9] CryptoPkg/OpensslLib: Use new Perl script for file list generation.
Date: Tue, 21 Mar 2017 23:56:07 +0800	[thread overview]
Message-ID: <20170321155612.1192-5-qin.long@intel.com> (raw)
In-Reply-To: <20170321155612.1192-1-qin.long@intel.com>

OpenSSL-1.1.0xx updated its configuration mechanism with new configdata.
This patch update process_file.sh script to new Perl-based script for
auto generation of file list and openssl config file (opensslconf.h).

This only needs to be done once by a developer when updating to a new
version of OpenSSL (or changing options, etc.). Normal users do not need
to do this, since the results are already stored in the EDK2 git repository.

Cc: Ting Ye <ting.ye@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Gary Lin <glin@suse.com>
Cc: Ronald Cron <ronald.cron@arm.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Qin Long <qin.long@intel.com>
---
 CryptoPkg/Library/OpensslLib/process_files.pl | 223 ++++++++++++++++++++++++++
 CryptoPkg/Library/OpensslLib/process_files.sh | 110 -------------
 2 files changed, 223 insertions(+), 110 deletions(-)
 create mode 100644 CryptoPkg/Library/OpensslLib/process_files.pl
 delete mode 100755 CryptoPkg/Library/OpensslLib/process_files.sh

diff --git a/CryptoPkg/Library/OpensslLib/process_files.pl b/CryptoPkg/Library/OpensslLib/process_files.pl
new file mode 100644
index 0000000000..210811b9ed
--- /dev/null
+++ b/CryptoPkg/Library/OpensslLib/process_files.pl
@@ -0,0 +1,223 @@
+#!/usr/bin/perl -w
+#
+# This script runs the OpenSSL Configure script, then processes the
+# resulting file list into our local OpensslLib[Crypto].inf and also
+# takes a copy of opensslconf.h.
+#
+# This only needs to be done once by a developer when updating to a
+# new version of OpenSSL (or changing options, etc.). Normal users
+# do not need to do this, since the results are stored in the EDK2
+# git repository for them.
+#
+use strict;
+use Cwd;
+use File::Copy;
+
+#
+# Find the openssl directory name for use lib. We have to do this
+# inside of BEGIN. The variables we create here, however, don't seem
+# to be available to the main script, so we have to repeat the
+# exercise.
+#
+my $inf_file;
+my $OPENSSL_PATH;
+my @inf;
+
+BEGIN {
+    $inf_file = "OpensslLib.inf";
+
+    # Read the contents of the inf file
+    open( FD, "<" . $inf_file ) ||
+        die "Cannot open \"" . $inf_file . "\"!";
+    @inf = (<FD>);
+    close(FD) ||
+        die "Cannot close \"" . $inf_file . "\"!";
+
+    foreach (@inf) {
+        if (/DEFINE\s+OPENSSL_PATH\s*=\s*([a-z]+)/) {
+
+            # We need to run Configure before we can include its result...
+            $OPENSSL_PATH = $1;
+
+            my $basedir = getcwd();
+
+            chdir($OPENSSL_PATH) ||
+                die "Cannot change to OpenSSL directory \"" . $OPENSSL_PATH . "\"";
+
+            # Configure UEFI
+            system(
+                "./Configure",
+                "UEFI",
+                "no-afalgeng",
+                "no-asm",
+                "no-async",
+                "no-autoalginit",
+                "no-autoerrinit",
+                "no-bf",
+                "no-blake2",
+                "no-camellia",
+                "no-capieng",
+                "no-cast",
+                "no-chacha",
+                "no-cms",
+                "no-ct",
+                "no-deprecated",
+                "no-dgram",
+                "no-dsa",
+                "no-dynamic-engine",
+                "no-ec",
+                "no-ec2m",
+                "no-engine",
+                "no-err",
+                "no-filenames",
+                "no-gost",
+                "no-hw",
+                "no-idea",
+                "no-mdc2",
+                "no-pic",
+                "no-ocb",
+                "no-poly1305",
+                "no-posix-io",
+                "no-rc2",
+                "no-rfc3779",
+                "no-rmd160",
+                "no-scrypt",
+                "no-seed",
+                "no-sock",
+                "no-srp",
+                "no-ssl",
+                "no-stdio",
+                "no-threads",
+                "no-ts",
+                "no-ui",
+                "no-whirlpool"
+                ) == 0 ||
+                    die "OpenSSL Configure failed!\n";
+
+            # Generate opensslconf.h per config data
+            system(
+                "perl -I. -Mconfigdata util/dofile.pl " .
+                "include/openssl/opensslconf.h.in " .
+                "> include/openssl/opensslconf.h"
+                ) == 0 ||
+                    die "Failed to generate opensslconf.h!\n";
+
+            chdir($basedir) ||
+                die "Cannot change to base directory \"" . $basedir . "\"";
+
+            push @INC, $1;
+            last;
+        }
+    }
+}
+
+#
+# Retrieve file lists from OpenSSL configdata
+#
+use configdata qw/%unified_info/;
+
+my @cryptofilelist = ();
+my @sslfilelist = ();
+foreach my $product ((@{$unified_info{libraries}},
+                      @{$unified_info{engines}})) {
+    foreach my $o (@{$unified_info{sources}->{$product}}) {
+        foreach my $s (@{$unified_info{sources}->{$o}}) {
+            next if ($unified_info{generate}->{$s});
+            next if $s =~ "crypto/bio/b_print.c";
+            if ($product =~ "libssl") {
+                push @sslfilelist, '  $(OPENSSL_PATH)/' . $s . "\r\n";
+                next;
+            }
+            push @cryptofilelist, '  $(OPENSSL_PATH)/' . $s . "\r\n";
+        }
+    }
+}
+
+#
+# Update OpensslLib.inf with autogenerated file list
+#
+my @new_inf = ();
+my $subbing = 0;
+print "\n--> Updating OpensslLib.inf ... ";
+foreach (@inf) {
+    if ( $_ =~ "# Autogenerated files list starts here" ) {
+        push @new_inf, $_, @cryptofilelist, @sslfilelist;
+        $subbing = 1;
+        next;
+    }
+    if ( $_ =~ "# Autogenerated files list ends here" ) {
+        push @new_inf, $_;
+        $subbing = 0;
+        next;
+    }
+
+    push @new_inf, $_
+        unless ($subbing);
+}
+
+my $new_inf_file = $inf_file . ".new";
+open( FD, ">" . $new_inf_file ) ||
+    die $new_inf_file;
+print( FD @new_inf ) ||
+    die $new_inf_file;
+close(FD) ||
+    die $new_inf_file;
+rename( $new_inf_file, $inf_file ) ||
+    die "rename $inf_file";
+print "Done!";
+
+#
+# Update OpensslLibCrypto.inf with auto-generated file list (no libssl)
+#
+$inf_file = "OpensslLibCrypto.inf";
+
+# Read the contents of the inf file
+@inf = ();
+@new_inf = ();
+open( FD, "<" . $inf_file ) ||
+    die "Cannot open \"" . $inf_file . "\"!";
+@inf = (<FD>);
+close(FD) ||
+    die "Cannot close \"" . $inf_file . "\"!";
+
+$subbing = 0;
+print "\n--> Updating OpensslLibCrypto.inf ... ";
+foreach (@inf) {
+    if ( $_ =~ "# Autogenerated files list starts here" ) {
+        push @new_inf, $_, @cryptofilelist;
+        $subbing = 1;
+        next;
+    }
+    if ( $_ =~ "# Autogenerated files list ends here" ) {
+        push @new_inf, $_;
+        $subbing = 0;
+        next;
+    }
+
+    push @new_inf, $_
+        unless ($subbing);
+}
+
+$new_inf_file = $inf_file . ".new";
+open( FD, ">" . $new_inf_file ) ||
+    die $new_inf_file;
+print( FD @new_inf ) ||
+    die $new_inf_file;
+close(FD) ||
+    die $new_inf_file;
+rename( $new_inf_file, $inf_file ) ||
+    die "rename $inf_file";
+print "Done!";
+
+#
+# Copy opensslconf.h generated from OpenSSL Configuration
+#
+print "\n--> Duplicating opensslconf.h into Include/openssl ... ";
+copy($OPENSSL_PATH . "/include/openssl/opensslconf.h",
+     $OPENSSL_PATH . "/../../../Include/openssl/") ||
+   die "Cannot copy opensslconf.h!";
+print "Done!\n";
+
+print "\nProcessing Files Done!\n";
+
+exit(0);
diff --git a/CryptoPkg/Library/OpensslLib/process_files.sh b/CryptoPkg/Library/OpensslLib/process_files.sh
deleted file mode 100755
index 9f10409824..0000000000
--- a/CryptoPkg/Library/OpensslLib/process_files.sh
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/bin/sh
-#
-# This script runs the OpenSSL Configure script, then processes the resulting
-# file list into our local OpensslLib.inf and OpensslLibCrypto.inf, and also
-# takes a copy of opensslconf.h.
-#
-# This only needs to be done once by a developer when updating to a
-# new version of OpenSSL (or changing options, etc.). Normal users
-# do not need to do this, since the results are stored in the EDK2
-# git repository for them.
-
-OPENSSL_PATH=$(sed -n '/DEFINE OPENSSL_PATH/{s/.* \(openssl-[0-9.]*[a-z]*\)[[:space:]]*/\1/ p}' OpensslLib.inf)
-OPENSSL_CRYPTO_PATH=$(sed -n '/DEFINE OPENSSL_PATH/{s/.* \(openssl-[0-9.]*[a-z]*\)[[:space:]]*/\1/ p}' OpensslLibCrypto.inf)
-
-if [ "$OPENSSL_PATH" != "$OPENSSL_CRYPTO_PATH" ]; then
-    echo "OPENSSL_PATH diverges between OpensslLib.inf and OpensslLibCrypto.inf"
-    exit 1
-fi
-
-if ! cd "${OPENSSL_PATH}" ; then
-    echo "Cannot change to OpenSSL directory \"${OPENSSL_PATH}\""
-    exit 1
-fi
-
-./Configure UEFI \
-	no-asm \
-	no-bf \
-	no-camellia \
-	no-capieng \
-	no-cast \
-	no-cms \
-	no-deprecated \
-	no-dgram \
-	no-dsa \
-	no-dynamic-engine \
-	no-ec \
-	no-ecdh \
-	no-ecdsa \
-	no-engine \
-	no-engines \
-	no-err \
-	no-filenames \
-	no-fp-api \
-	no-hw \
-	no-idea \
-	no-jpake \
-	no-krb5 \
-	no-locking \
-	no-mdc2 \
-	no-posix-io \
-	no-rc2 \
-	no-rcs \
-	no-rfc3779 \
-	no-ripemd \
-	no-scrypt \
-	no-sct \
-	no-seed \
-	no-sha0 \
-	no-sock \
-	no-srp \
-	no-ssl \
-	no-stdio \
-	no-threads \
-	no-ts \
-	no-ui \
-	no-whirlpool \
-    || exit 1
-
-make files
-cd -
-
-function filelist ()
-{
-    SSL_SELECT="$1"
-
-    echo '1,/# Autogenerated files list starts here/p'
-    echo '/# Autogenerated files list ends here/,$p'
-    echo '/# Autogenerated files list starts here/a\'
-
-    while read LINE; do
-	case "$LINE" in
-	    RELATIVE_DIRECTORY=*)
-		eval "$LINE"
-		;;
-	    LIBSRC=*)
-		LIBSRC=$(echo "$LINE" | sed s/^LIBSRC=//)
-		if [ "$RELATIVE_DIRECTORY" != "ssl" ] ||
-		   [ "$SSL_SELECT" = "crypto-and-ssl" ]; then
-		    for FILE in $LIBSRC; do
-			if [ "$FILE" != "b_print.c" ]; then
-			    echo -e '  $(OPENSSL_PATH)/'$RELATIVE_DIRECTORY/$FILE\\r\\
-			fi
-		    done
-		fi
-		;;
-	esac
-    done
-    echo -e \\r
-}
-
-filelist crypto-and-ssl < "${OPENSSL_PATH}/MINFO" \
-| sed -n -f - -i OpensslLib.inf
-
-filelist crypto-only < "${OPENSSL_PATH}/MINFO" \
-| sed -n -f - -i OpensslLibCrypto.inf
-
-# We can tell Windows users to put this back manually if they can't run
-# Configure. For now, until the git repository is fixed to store things
-# sanely, also convert to DOS line-endings
-unix2dos -n "${OPENSSL_PATH}/crypto/opensslconf.h" opensslconf.h
-- 
2.11.1.windows.1



  parent reply	other threads:[~2017-03-21 15:57 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-21 15:56 [PATCH v1 0/9] *** Upgrade CryptoPkg to use the latest OpenSSL 1.1.0xx/stable release *** Qin Long
2017-03-21 15:56 ` [PATCH v1 1/9] CryptoPkg/OpensslLib: Update INF files to support OpenSSL-1.1.0xx build Qin Long
2017-03-22 12:02   ` Laszlo Ersek
2017-03-22 12:18   ` Laszlo Ersek
2017-03-21 15:56 ` [PATCH v1 2/9] CryptoPkg/OpensslLib: Remove patch file and installation scripts Qin Long
2017-03-22 12:05   ` Laszlo Ersek
2017-03-21 15:56 ` [PATCH v1 3/9] CryptoPkg: Fix handling of &strcmp function pointers Qin Long
2017-03-22 10:11   ` Gary Lin
2017-03-23  2:16     ` Long, Qin
2017-03-23  3:39       ` Long, Qin
2017-03-21 15:56 ` Qin Long [this message]
2017-03-21 15:56 ` [PATCH v1 5/9] CryptoPkg: Clean-up CRT Library Wrapper Qin Long
2017-03-21 15:56 ` [PATCH v1 6/9] CryptoPkg: Add extra build option to disable VS build warning Qin Long
2017-03-21 15:56 ` [PATCH v1 7/9] CryptoPkg: Update HMAC Wrapper implementation with opaque HMAC_CTX object Qin Long
2017-03-21 15:56 ` [PATCH v1 8/9] CryptoPkg: Update PK Ciphers Wrapper Implementations work with opaque objects Qin Long
2017-03-21 15:56 ` [PATCH v1 9/9] CryptoPkg/TlsLib: Update TLS Wrapper Library to align with OpenSSL changes Qin Long
2017-03-21 17:42   ` Palmer, Thomas
2017-03-22  1:32     ` Long, Qin
2017-03-23  1:20       ` Wu, Jiaxin
2017-03-23 16:23         ` Palmer, Thomas
2017-03-22  2:22 ` [PATCH v1 0/9] *** Upgrade CryptoPkg to use the latest OpenSSL 1.1.0xx/stable release *** Gao, Liming
2017-03-22  2:44   ` Long, Qin
2017-03-22 13:02 ` Laszlo Ersek
2017-03-22 16:20   ` Long, Qin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170321155612.1192-5-qin.long@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox