Bug 1331765 - Synch. up with the default branch JSS_EXPERIMENTAL_BRANCH
authorElio Maldonado <emaldona@redhat.com>
Fri, 20 Jan 2017 13:16:06 -0800
branchJSS_EXPERIMENTAL_BRANCH
changeset 2122 819b115893f8aad1f972cc58221bce064a81f6e8
parent 2119 c764700160164d710cd661a102e4c7f3fd0581ae (current diff)
parent 2121 031cb8b9f5d2701566ec01cf87ad7283234485c7 (diff)
child 2144 a7e221b3cebccdb8187080f758bdec7747d2aa41
push id19
push useremaldona@redhat.com
push dateFri, 20 Jan 2017 21:16:12 +0000
bugs1331765
Bug 1331765 - Synch. up with the default branch
build_java.pl
--- a/Makefile
+++ b/Makefile
@@ -29,16 +29,18 @@ include $(CORE_DEPTH)/coreconf/config.mk
 #######################################################################
 # (5) Execute "global" rules. (OPTIONAL)                              #
 #######################################################################
 
 # have to put this here, instead of in rules.mk, so that Java gets
 # built first
 all:: buildJava
 
+test_jss: testJava
+
 include $(CORE_DEPTH)/coreconf/rules.mk
 
 #######################################################################
 # (6) Execute "component" rules. (OPTIONAL)                           #
 #######################################################################
 
 
 
--- a/build_java.pl
+++ b/build_java.pl
@@ -76,16 +76,19 @@ org.mozilla.jss.provider.java.security
 org.mozilla.jss.provider.javax.crypto
 org.mozilla.jss.SecretDecoderRing
 org.mozilla.jss.ssl
 org.mozilla.jss.tests
 org.mozilla.jss.util
 );
 
 
+# setup environment
+setup_env();
+
 # setup variables
 setup_vars(\@ARGV);
 
 # run the command with its arguments
 my $cmd = (shift || "build");   # first argument is command
 grep { s/(.*)/"$1"/ } @ARGV;    # enclose remaining arguments in quotes
 my $args = join(",",@ARGV);     # and comma-separate them
 eval "$cmd($args)";             # now run the command
@@ -106,23 +109,41 @@ sub grab_cmdline_vars {
 
 sub dump_cmdline_vars {
     print "Command variables:\n";
     for(keys %cmdline_vars) {
         print "$_=" . $cmdline_vars{$_} . "\n";
     }
 }
 
+sub setup_env {
+    # check that JAVA_HOME environment variable has been set externally
+    $ENV{JAVA_HOME} or
+    die "\nMust specify JAVA_HOME environment variable!\n"
+      . "(e. g. - export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0_openjdk)"
+      . "\n\n";
+    print "JAVA_HOME=$ENV{'JAVA_HOME'}\n";
+
+    # check that USE_64 environment variable has been set externally
+    # for 64-bit architectures (when applicable)
+    $bitsize = `getconf LONG_BIT`;
+    if( $bitsize == 64 ) {
+        $ENV{USE_64} or
+        die "\nMust specify USE_64 environment variable!\n"
+          . "(e. g. - export USE_64=1)\n\n";
+        print "USE_64=$ENV{'USE_64'}\n";
+    }
+}
+
 sub setup_vars {
     my $argv = shift;
 
     grab_cmdline_vars($argv);
     dump_cmdline_vars();
 
-    $ENV{JAVA_HOME} or die "Must specify JAVA_HOME environment variable";
     $jar = "$ENV{JAVA_HOME}/bin/jar";
     $javac = "$ENV{JAVA_HOME}/bin/javac";
     $javah = "$ENV{JAVA_HOME}/bin/javah";
     $javadoc = "$ENV{JAVA_HOME}/bin/javadoc";
 
     $dist_dir = $cmdline_vars{SOURCE_PREFIX};
     $jce_jar = $ENV{JCE_JAR};
 
@@ -140,16 +161,94 @@ sub setup_vars {
         $javac_opt_flag = "-g";
         $debug_source_file = "org/mozilla/jss/util/Debug_debug.jnot";
     }
     $jni_header_dir = "$dist_dir/private/jss/_jni";
 
     if( $jce_jar ) {
         $classpath = "-classpath $jce_jar";
     }
+
+    # retrieve present working directory
+    $pwd = `pwd`;
+    $pwd =~ chomp $pwd;
+
+    # retrieve architecture
+    $arch = `uname -m`;
+    $arch =~ chomp $arch;
+
+    # retrieve operating system
+    $os = `uname`;
+    $os =~ chomp $os;
+
+    # Verify existence of work area
+    if(( ! -d "$pwd/../nspr" ) ||
+       ( ! -d "$pwd/../nss" )  ||
+       ( ! -d "$pwd/../jss" )) {
+        my $workarea = "\nA work area must first be prepared; for example:\n\n"
+                     . "    mkdir sandbox\n"
+                     . "    cd sandbox\n"
+                     . "    hg clone https://hg.mozilla.org/projects/nspr\n"
+                     . "    hg clone https://hg.mozilla.org/projects/nss\n"
+                     . "    hg clone https://hg.mozilla.org/projects/jss\n"
+                     . "    cd ..\n\n";
+
+        die "$workarea";
+    }
+
+    # Build NSS if not already built
+    if( ! -d $dist_dir ) {
+        print("########################\n" .
+              "# BEGIN:  Building NSS #\n" .
+              "########################\n");
+        print_do("cd ../nss;make clean nss_build_all;cd ../jss");
+        print("######################\n" .
+              "# END:  Building NSS #\n" .
+              "######################\n");
+    }
+
+    if( $os eq 'Linux' || $os eq 'Darwin' ) {
+        # set major and minor release numbers
+        $majorrel = `uname -r | cut -f1 -d.`;
+        $majorrel =~ chomp $majorrel;
+        $minorrel = `uname -r | cut -f2 -d.`;
+        $minorrel =~ chomp $minorrel;
+
+        # read the contents of the $dist_dir into an array
+        opendir DIR, $dist_dir or die "Cannot open directory: $!";
+        my @files = readdir DIR;
+        closedir DIR;
+
+        # process the array to obtain the NSS OBJDIR_NAME
+        my $prefix = "$os$majorrel.$minorrel";
+        foreach my $file (@files) {
+            if ((index($file, $prefix) != -1) &&
+                (index($file, "_cc") != -1)) {
+                $nss_objdir_name = $file;
+                print "NSS OBJDIR_NAME=$nss_objdir_name\n";
+
+                # craft JSS OBJDIR_NAME based upon value of NSS OBJDIR_NAME
+                $jss_objdir_name = $nss_objdir_name;
+                $jss_objdir_name =~ s/_cc//;
+                print "JSS OBJDIR_NAME=$jss_objdir_name\n";
+
+                break;
+            } 
+        }
+
+        # create a JSS OBJDIR_NAME symlink to NSS OBJDIR_NAME in $dist_dir
+        $jss_symlink = "$pwd/../dist/$jss_objdir_name";
+        if( ! -l $jss_symlink ) {
+            my $cmd = "cd ../dist;"
+                    . "ln -s $nss_objdir_name $jss_objdir_name;"
+                    . "cd ../jss";
+            print_do($cmd);
+        }
+        print "jss_symlink=$jss_symlink\n"
+    }
 }
 
 sub clean {
     print_do("rm -rf $class_dir");
     print_do("rm -f $class_jar");
     print_do("rm -rf $jni_header_dir");
 }
 
@@ -324,8 +423,32 @@ sub javadoc {
     }
     ensure_dir_exists("$dist_dir/jssdoc");
     my $targets = join(" ", @packages);
     print "$targets\n";
     print_do("$javadoc -breakiterator -sourcepath . -d $dist_dir/jssdoc $html_header_opt $targets");
     print_do("cp $dist_dir/jssdoc/index.html $dist_dir/jssdoc/index.html.bak");
     print_do("cp $dist_dir/jssdoc/overview-summary.html $dist_dir/jssdoc/index.html");
 }
+
+sub test {
+    # Test JSS presuming that it has already been built
+    if( $os eq 'Linux' || $os eq 'Darwin' ) {
+        if(( -d $dist_dir )  &&
+           ( -l $jss_symlink )) {
+            my $cmd = "cd $pwd/org/mozilla/jss/tests;"
+                    . "perl all.pl dist $jss_symlink;"
+                    . "cd $pwd";
+
+            print("#######################\n" .
+                  "# BEGIN:  Testing JSS #\n" .
+                  "#######################\n");
+            print_do($cmd);
+            print("#####################\n" .
+                  "# END:  Testing JSS #\n" .
+                  "#####################\n");
+        } else {
+            die "JSS builds are not available at $jss_symlink.";
+        }
+    } else {
+        die "make test_jss is only available on Linux and MacOS platforms.";
+    }
+}
--- a/rules.mk
+++ b/rules.mk
@@ -1,11 +1,12 @@
 .PHONY: buildJava
 .PHONY: cleanJava
 .PHONY: releaseJava
+.PHONY: testJava
 
 clean:: cleanJava
 release_classes:: releaseJava
 
 # always do a private_export
 export:: private_export
 
 PERL_VARIABLES=     \
@@ -17,13 +18,16 @@ PERL_VARIABLES=     \
     "XPCLASS_JAR=$(XPCLASS_JAR)"
 
 buildJava:
 	perl build_java.pl $(PERL_VARIABLES) build
 
 cleanJava:
 	perl build_java.pl $(PERL_VARIABLES) clean
 
+testJava:
+	perl build_java.pl $(PERL_VARIABLES) test
+
 releaseJava:
 	perl build_java.pl $(PERL_VARIABLES) release
 
 javadoc:
 	perl build_java.pl $(PERL_VARIABLES) javadoc