Skip to content

Commit

Permalink
(#16966) Prepare nodejs for v18
Browse files Browse the repository at this point in the history
* nodejs: conanfile.py: prepare for v18

Signed-off-by: Alexander Kozhinov <[email protected]>

* test_package: conanfile.py: update for conan v2 usage

Signed-off-by: Alexander Kozhinov <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* nodejs: conanfile.py: remove compiler verification

Signed-off-by: Alexander Kozhinov <[email protected]>

* nodejs: test_package: rework for v1 and v2

Signed-off-by: Alexander Kozhinov <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* nodejse: conanfile.py: rework conan_version test

Signed-off-by: Alexander Kozhinov <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Gregor Jasny <[email protected]>

* Update recipes/nodejs/all/test_package/conanfile.py

Co-authored-by: Gregor Jasny <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Gregor Jasny <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Gregor Jasny <[email protected]>

* nodejs: conanfile.py: use self.settings instead of self.info.settings

Signed-off-by: Alexander Kozhinov <[email protected]>

* nodejs: conanfile.py: do not use self.settings in source() method

Signed-off-by: Alexander Kozhinov <[email protected]>

* nodejs: conanfile.py: use subprocess in _glibc_version

Signed-off-by: Alexander Kozhinov <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* Update recipes/nodejs/all/conanfile.py

Co-authored-by: Chris Mc <[email protected]>

* nodejs: conanfile.py: fix arch / revert _glibc_version

Signed-off-by: Alexander Kozhinov <[email protected]>

* nodejs: conanfile.py: remove dobule defined build() method

Signed-off-by: Alexander Kozhinov <[email protected]>

* nodejs: conanfile.py: fix glibc version aquisition

Signed-off-by: Alexander Kozhinov <[email protected]>

---------

Signed-off-by: Alexander Kozhinov <[email protected]>
Co-authored-by: Chris Mc <[email protected]>
Co-authored-by: Gregor Jasny <[email protected]>
  • Loading branch information
3 people authored May 2, 2023
1 parent b47c03b commit 89fa481
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 18 deletions.
47 changes: 33 additions & 14 deletions recipes/nodejs/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import os
from conans import ConanFile, tools
from conans.errors import ConanInvalidConfiguration
import re
from six import StringIO
from conan import ConanFile, conan_version
from conan.tools.scm import Version
from conan.tools.files import copy, get
from conan.errors import ConanInvalidConfiguration

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.59.0"


class NodejsConan(ConanFile):
name = "nodejs"
description = "nodejs binaries for use in recipes"
topics = ("conan", "node", "nodejs")
topics = ("node", "javascript", "runtime")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://nodejs.org"
license = "MIT"
settings = "os", "arch"
settings = "os", "arch", "compiler"
no_copy_source = True
short_paths = True

@property
def _source_subfolder(self):
Expand All @@ -28,21 +33,35 @@ def _nodejs_arch(self):
return "armv8"
return str(self.settings.arch)

@property
def _glibc_version(self):
cmd = ['ldd', '--version'] if conan_version.major == "1" else ['ldd --version']
buff = StringIO()
self.run(cmd, buff)
return str(re.search(r'GLIBC (\d{1,3}.\d{1,3})', buff.getvalue()).group(1))

def validate(self):
if (not (self.version in self.conan_data["sources"]) or
not (str(self.settings.os) in self.conan_data["sources"][self.version]) or
not (self._nodejs_arch in self.conan_data["sources"][self.version][str(self.settings.os)] ) ):
if not self.version in self.conan_data["sources"] or \
not str(self.settings.os) in self.conan_data["sources"][self.version] or \
not self._nodejs_arch in self.conan_data["sources"][self.version][str(self.settings.os)]:
raise ConanInvalidConfiguration("Binaries for this combination of architecture/version/os not available")

if Version(self.version) >= "18.0.0":
if str(self.settings.os) == "Linux":
if Version(self._glibc_version) < '2.27':
raise ConanInvalidConfiguration("Binaries for this combination of architecture/version/os not available")

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

def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*", src=os.path.join(self._source_subfolder, "bin"), dst="bin")
self.copy(pattern="node.exe", src=self._source_subfolder, dst="bin")
self.copy(pattern="npm", src=self._source_subfolder, dst="bin")
self.copy(pattern="npx", src=self._source_subfolder, dst="bin")
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self._source_subfolder)
copy(self, pattern="*", dst=os.path.join(self.package_folder, "bin"), src=os.path.join(self._source_subfolder, "bin"))
copy(self, pattern="*", dst=os.path.join(self.package_folder, "lib"), src=os.path.join(self._source_subfolder, "lib"))
copy(self, pattern="node.exe", dst=os.path.join(self.package_folder, "bin"), src=self._source_subfolder)
copy(self, pattern="npm", dst=os.path.join(self.package_folder, "bin"), src=self._source_subfolder)
copy(self, pattern="npx", dst=os.path.join(self.package_folder, "bin"), src=self._source_subfolder)

def package_info(self):
self.cpp_info.includedirs = []
Expand Down
12 changes: 8 additions & 4 deletions recipes/nodejs/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import os
from conans import ConanFile, tools
from conan import ConanFile
from conan.tools.build import can_run


class TestPackageConan(ConanFile):

settings = "os", "arch"
test_type = "explicit"

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def test(self):
if not tools.cross_building(self):
if can_run(self):
self.output.info("Node version:")
self.run("node --version", run_environment=True)
self.run("node --version")
16 changes: 16 additions & 0 deletions recipes/nodejs/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from conan import ConanFile
from conan.tools.build import cross_building


class TestPackageConan(ConanFile):

settings = "os", "arch"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def test(self):
if not cross_building(self):
self.output.info("Node version:")
self.run("node --version")

0 comments on commit 89fa481

Please sign in to comment.