Java Version required to be checked.

Ryan Schmidt ryandesign at macports.org
Mon Mar 28 08:54:58 PDT 2016


> On Mar 27, 2016, at 7:14 PM, Abdulrahman Alshammari <a.turqi at hotmail.com> wrote:
> 
> Hey,
> 
> I am building a porfile of my software. Originally, the software requires at least  1.8 Java version. I have found some portfiles in available ports section, they use pre-fetch to check if the operation system is at least earlier than a certain version. Can I do that for to check for Java version? if yes, How can I perform that ?

You can run commands to determine the java version and compare it against the one you need. You would have to code it in such a way that you also account for the situation where the user does not have any java version installed. I do have java installed, so I'm not completely certain this handles the no-java case correctly, but here's some code I came up with:


    proc javac_version_ok {min_javac_version} {
        if {![catch {set javac_long_version [exec javac -version 2>@1]}]} {
            if {[regexp {^javac (.*)$} $javac_long_version -> javac_version]} {
                return [expr [vercmp $javac_version $min_javac_version] >= 0]
            }
        }
        return NO;
    }

    proc check_javac_version {} {
        set min_javac_version 1.8
        if {![javac_version_ok ${min_javac_version}]} {
            global name version
            ui_error "${name} @${version} requires java ${min_javac_version} or later"
            return -code error "incompatible java version"
        }
    }

    pre-archivefetch {
        check_javac_version
    }

    pre-configure {
        check_javac_version
    }


Here I'm assuming java is required both at build time and at runtime. If it's only needed at build time, then you should not use the pre-archivefetch block above.


> Other question is about file dependencies, Z3 is a theorem prover like CVC4. Unfortunately, Z3 is not available as a port. How can I deal with this as file dependency? Please let me know if there is an similar example to my situation? 

I don't know what Z3 is, but can you add a port for it?




More information about the macports-dev mailing list