Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added recipe for openjdk #5792

Merged
merged 8 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions recipes/openjdk/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
sources:
"16.0.1":
Windows:
url: "https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_windows-x64_bin.zip"
sha256: "733b45b09463c97133d70c2368f1b9505da58e88f2c8a84358dd4accfd06a7a4"
Linux:
url: "https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_linux-x64_bin.tar.gz"
sha256: "b1198ffffb7d26a3fdedc0fa599f60a0d12aa60da1714b56c1defbce95d8b235"
Macos:
url: "https://download.java.net/java/GA/jdk16.0.1/7147401fd7354114ac51ef3e1328291f/9/GPL/openjdk-16.0.1_osx-x64_bin.tar.gz"
sha256: "6098f839954439d4916444757c542c1b8778a32461706812d41cc8bbefce7f2f"
53 changes: 53 additions & 0 deletions recipes/openjdk/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"


class OpenJDK(ConanFile):
name = "openjdk"
url = "https://github.com/conan-io/conan-center-index/"
description = "Java Development Kit builds, from Oracle"
homepage = "https://jdk.java.net"
license = "GPL-2.0-with-classpath-exception"
topics = ("java", "jdk", "openjdk")
settings = "os", "arch"
no_copy_source = True

@property
def _source_subfolder(self):
return "source_subfolder"

def configure(self):
if self.settings.arch != "x86_64":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

raise ConanInvalidConfiguration("Unsupported Architecture. This package currently only supports x86_64.")
if self.settings.os not in ["Windows", "Macos", "Linux"]:
raise ConanInvalidConfiguration("Unsupported os. This package currently only support Linux/Macos/Windows")

def build(self):
tools.get(**self.conan_data["sources"][self.version][str(self.settings.os)],
destination=self._source_subfolder, strip_root=True)

def package(self):
if self.settings.os == "Macos":
_source_subfolder = os.path.join(self._source_subfolder, "jdk-{}.jdk".format(self.version), "Contents", "Home")
else:
_source_subfolder = self._source_subfolder
self.copy(pattern="*", dst="bin", src=os.path.join(_source_subfolder, "bin"),
excludes=("msvcp140.dll", "vcruntime140.dll", "vcruntime140_1.dll"))
self.copy(pattern="*", dst="include", src=os.path.join(_source_subfolder, "include"))
self.copy(pattern="*", dst="lib", src=os.path.join(_source_subfolder, "lib"))
self.copy(pattern="*", dst=os.path.join("lib", "jmods"), src=os.path.join(_source_subfolder, "jmods"))
self.copy(pattern="*", dst="licenses", src=os.path.join(_source_subfolder, "legal"))
# conf folder is required for security settings, to avoid
# java.lang.SecurityException: Can't read cryptographic policy directory: unlimited
# https://github.com/conan-io/conan-center-index/pull/4491#issuecomment-774555069
self.copy(pattern="*", dst="conf", src=os.path.join(_source_subfolder, "conf"))

def package_info(self):
self.output.info("Creating JAVA_HOME environment variable with : {0}".format(self.package_folder))
self.env_info.JAVA_HOME = self.package_folder

self.output.info("Appending PATH environment variable with : {0}".format(os.path.join(self.package_folder, "bin")))
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
22 changes: 22 additions & 0 deletions recipes/openjdk/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from conans import ConanFile
boussaffawalid marked this conversation as resolved.
Show resolved Hide resolved
from conans.errors import ConanException
from io import StringIO

required_conan_version = ">=1.36.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you're running an older version? The main recipe works and then it errors out during test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I know it raises an error, but I'm talking about the placement.
I usually see this line in the main conanfile.py. By having it on the test_package's conanfile.py, would you allow the package to build and then error out during test?
Are both conanfiles evaluated before build?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_package is not evaluated before the build

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so should I add the required_conan_version to the main conanfile ?

Copy link
Contributor

@madebr madebr Jul 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are correct here.
The main recipe needs conan 1.33. -> you need to add it there too
The test recipe needs conan 1.36.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it does not make sense to require two different versions. lets use 1.36 in main recipe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can build the main recipe without a test recipe (-tf None) or build with a different test recipe (-tf other_test_package).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok. For a client using 1.33 it will fail in a conan create command, but it is accurate and, as said before, you can avoid running these tests, or use a different test folder... and a conan install ... --build=openjdk won't fail, which is the command you would run when retrieving this recipe from a remote (test_package is not uploaded to the remote).



class TestPackage(ConanFile):
test_type = "build_requires"

def build(self):
pass # nothing to build, but tests should not warn
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps compiling something JNI?


def test(self):
output = StringIO()
self.run("java --version", output=output, run_environment=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be run conditionally, when not cross building.

print(output.getvalue)
version_info = output.getvalue()
if "openjdk" in version_info:
pass
else:
raise ConanException("java call seems not use the openjdk bin")
boussaffawalid marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions recipes/openjdk/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"16.0.1":
folder: all