From 720a0a9d41a8a7aef23512990c0e84f6aabb48ec Mon Sep 17 00:00:00 2001 From: Paul Harris Date: Wed, 26 Oct 2022 21:09:48 +0800 Subject: [PATCH] (#13485) nasm - upgrade to conan v2, based on prior work done by @czoido * nasm - upgrade to conan v2, based on prior work done by @czoido * nasm - fix for linter * nasm - fixup cflags * nasm - guess what to do with tools.get_env() * nasm - don't require replace to be successful * nasm - try removing autotools.autoreconf() as the CI wasn't building * nasm - reenable autoreconf() * Update recipes/nasm/all/conanfile.py Co-authored-by: Carlos Zoido * Update recipes/nasm/all/conanfile.py Co-authored-by: Carlos Zoido * Update recipes/nasm/all/conanfile.py Co-authored-by: Carlos Zoido * nasm - remove share dir * nasm - fix test_v1_package * Fixes from uilianries review * Fixes from @prince-chrismc review * Moved the (conan < 2) check to a diff spot * Replace shutil.copy() with shutil.copy2() * Apply suggestions from code review Co-authored-by: Chris Mc Co-authored-by: Carlos Zoido Co-authored-by: Chris Mc --- recipes/nasm/all/conandata.yml | 1 - recipes/nasm/all/conanfile.py | 120 ++++++++++-------- recipes/nasm/all/test_package/conanfile.py | 21 ++- recipes/nasm/all/test_v1_package/conanfile.py | 18 +++ .../nasm/all/test_v1_package/hello_linux.asm | 16 +++ 5 files changed, 114 insertions(+), 62 deletions(-) create mode 100644 recipes/nasm/all/test_v1_package/conanfile.py create mode 100644 recipes/nasm/all/test_v1_package/hello_linux.asm diff --git a/recipes/nasm/all/conandata.yml b/recipes/nasm/all/conandata.yml index 6cd038086b3e9..c97415979c9f2 100644 --- a/recipes/nasm/all/conandata.yml +++ b/recipes/nasm/all/conandata.yml @@ -14,4 +14,3 @@ sources: patches: "2.15.05": - patch_file: "patches/2.15.05-0001-disable-newly-integrated-dependency-tracking.patch" - base_path: "source_subfolder" diff --git a/recipes/nasm/all/conanfile.py b/recipes/nasm/all/conanfile.py index fd394629da656..3ae5789bf6256 100644 --- a/recipes/nasm/all/conanfile.py +++ b/recipes/nasm/all/conanfile.py @@ -1,8 +1,15 @@ -from conans import ConanFile, AutoToolsBuildEnvironment, tools import os import shutil -required_conan_version = ">=1.33.0" +from conan import ConanFile, conan_version +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import chdir, copy, get, rmdir, apply_conandata_patches, export_conandata_patches, replace_in_file +from conan.tools.gnu import Autotools, AutotoolsToolchain +from conan.tools.layout import basic_layout +from conan.tools.microsoft import VCVars, is_msvc +from conan.tools.scm import Version + +required_conan_version = ">=1.52.0" class NASMConan(ConanFile): @@ -11,85 +18,90 @@ class NASMConan(ConanFile): homepage = "http://www.nasm.us" description = "The Netwide Assembler, NASM, is an 80x86 and x86-64 assembler" license = "BSD-2-Clause" - settings = "os", "arch", "compiler", "build_type" topics = ("nasm", "installer", "assembler") - exports_sources = "patches/*" - _autotools = None + settings = "os", "arch", "compiler", "build_type" + - @property - def _source_subfolder(self): - return "source_subfolder" + def export_sources(self): + export_conandata_patches(self) - @property - def _settings_build(self): - return getattr(self, "settings_build", self.settings) + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC def configure(self): - del self.settings.compiler.libcxx - del self.settings.compiler.cppstd + try: + del self.settings.compiler.libcxx + except Exception: + pass + try: + del self.settings.compiler.cppstd + except Exception: + pass + + def layout(self): + basic_layout(self, src_folder="src") def build_requirements(self): - if self._settings_build.os == "Windows": - self.build_requires("strawberryperl/5.30.0.1") + if self.info.settings.os == "Windows": + self.tool_requires("strawberryperl/5.32.1.1") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True) def package_id(self): del self.info.settings.compiler - def _build_vs(self): - with tools.chdir(self._source_subfolder): - with tools.vcvars(self): - autotools = AutoToolsBuildEnvironment(self) - autotools.flags.append("-nologo") - self.run("nmake /f {} {}".format(os.path.join("Mkfiles", "msvc.mak"), " ".join("{}=\"{}\"".format(k, v) for k, v in autotools.vars.items()))) - shutil.copy("nasm.exe", "nasmw.exe") - shutil.copy("ndisasm.exe", "ndisasmw.exe") - - def _configure_autotools(self): - if self._autotools: - return self._autotools - self._autotools = AutoToolsBuildEnvironment(self, win_bash=(self._settings_build.os == "Windows")) + def generate(self): + tc = AutotoolsToolchain(self) + if is_msvc(self): + VCVars(self).generate() + tc.configure_args.append("-nologo") if self.settings.arch == "x86": - self._autotools.flags.append("-m32") + tc.extra_cflags.append("-m32") elif self.settings.arch == "x86_64": - self._autotools.flags.append("-m64") - self._autotools.configure(configure_dir=self._source_subfolder) + tc.extra_cflags.append("-m64") + tc.generate() - # GCC9 - "pure" attribute on function returning "void" - tools.replace_in_file("Makefile", "-Werror=attributes", "") + env = VirtualBuildEnv(self) + env.generate() - # Need "-arch" flag for the linker when cross-compiling. - # FIXME: Revisit after https://github.com/conan-io/conan/issues/9069, using new Autotools integration - if str(self.version).startswith("2.13"): - tools.replace_in_file("Makefile", "$(CC) $(LDFLAGS) -o", "$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o") - - return self._autotools def build(self): - for patch in self.conan_data.get("patches", {}).get(self.version, []): - tools.patch(**patch) - if self.settings.compiler == "Visual Studio": - self._build_vs() + apply_conandata_patches(self) + + if is_msvc(self): + with chdir(self, self.source_folder): + self.run("nmake /f {}".format(os.path.join("Mkfiles", "msvc.mak"))) else: - autotools = self._configure_autotools() + autotools = Autotools(self) + autotools.configure() + + # GCC9 - "pure" attribute on function returning "void" + replace_in_file(self, "Makefile", "-Werror=attributes", "") + + # Need "-arch" flag for the linker when cross-compiling. + # FIXME: Revisit after https://github.com/conan-io/conan/issues/9069, using new Autotools integration + # TODO it is time to revisit, not sure what to do here though... + if str(self.version).startswith("2.13"): + replace_in_file(self, "Makefile", "$(CC) $(LDFLAGS) -o", "$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o") + replace_in_file(self, "Makefile", "$(INSTALLROOT)", "$(DESTDIR)") autotools.make() + def package(self): - self.copy(pattern="LICENSE", src=self._source_subfolder, dst="licenses") - if self.settings.compiler == "Visual Studio": - self.copy(pattern="*.exe", src=self._source_subfolder, dst="bin", keep_path=False) + copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) + if is_msvc(self): + copy(self, pattern="*.exe", src=self.source_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False) + with chdir(self, os.path.join(self.package_folder, "bin")): + shutil.copy2("nasm.exe", "nasmw.exe") + shutil.copy2("ndisasm.exe", "ndisasmw.exe") else: - autotools = self._configure_autotools() + autotools = Autotools(self) autotools.install() - tools.rmdir(os.path.join(self.package_folder, "share")) + rmdir(self, os.path.join(self.package_folder, "share")) def package_info(self): - bin_path = os.path.join(self.package_folder, "bin") - self.output.info("Appending PATH environment variable: {}".format(bin_path)) - self.env_info.PATH.append(bin_path) self.cpp_info.libdirs = [] self.cpp_info.includedirs = [] diff --git a/recipes/nasm/all/test_package/conanfile.py b/recipes/nasm/all/test_package/conanfile.py index 116e500b7291d..95d517d9ebe3b 100644 --- a/recipes/nasm/all/test_package/conanfile.py +++ b/recipes/nasm/all/test_package/conanfile.py @@ -1,18 +1,25 @@ +from conan import ConanFile +from conan.tools.build import can_run import os -from conans import ConanFile, tools class TestPackageConan(ConanFile): - settings = "os", "arch", + settings = "os", "arch", "compiler", "build_type" + generators = "VirtualBuildEnv" + test_type = "explicit" + + def build_requirements(self): + self.tool_requires(self.tested_reference_str) def test(self): - if not tools.cross_building(self, skip_x64_x86=True): - self.run("nasm --version", run_environment=True) + if can_run(self): + self.run("nasm --version", env="conanbuild") asm_file = os.path.join(self.source_folder, "hello_linux.asm") out_file = os.path.join(self.build_folder, "hello_linux.o") bin_file = os.path.join(self.build_folder, "hello_linux") - self.run("nasm -felf64 {} -o {}".format(asm_file, out_file), run_environment=True) + self.run(f"nasm -felf64 {asm_file} -o {out_file}", env="conanbuild") if self.settings.os == "Linux" and self.settings.arch == "x86_64": - ld = tools.get_env("LD", "ld") - self.run("{} hello_linux.o -o {}".format(ld, bin_file), run_environment=True) + # TODO was tools.get_env, what should it be? + ld = os.getenv("LD", "ld") + self.run(f"{ld} hello_linux.o -o {bin_file}", env="conanbuild") self.run(bin_file) diff --git a/recipes/nasm/all/test_v1_package/conanfile.py b/recipes/nasm/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..e044b0e4f83c5 --- /dev/null +++ b/recipes/nasm/all/test_v1_package/conanfile.py @@ -0,0 +1,18 @@ +import os +from conans import ConanFile, tools + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + + def test(self): + if not tools.cross_building(self, skip_x64_x86=True): + self.run("nasm --version", run_environment=True) + asm_file = os.path.join(self.source_folder, "hello_linux.asm") + out_file = os.path.join(self.build_folder, "hello_linux.o") + bin_file = os.path.join(self.build_folder, "hello_linux") + self.run(f"nasm -felf64 {asm_file} -o {out_file}", run_environment=True) + if self.settings.os == "Linux" and self.settings.arch == "x86_64": + ld = tools.get_env("LD", "ld") + self.run(f"{ld} hello_linux.o -o {bin_file}", run_environment=True) + self.run(bin_file) diff --git a/recipes/nasm/all/test_v1_package/hello_linux.asm b/recipes/nasm/all/test_v1_package/hello_linux.asm new file mode 100644 index 0000000000000..c219477df732c --- /dev/null +++ b/recipes/nasm/all/test_v1_package/hello_linux.asm @@ -0,0 +1,16 @@ +; Print "Hello, Conan" + + global _start + + section .text +_start: mov rax, 1 ; system call for write + mov rdi, 1 ; file handle 1 is stdout + mov rsi, message ; address of string to output + mov rdx, 13 ; number of bytes + syscall ; invoke operating system to do the write + mov rax, 60 ; system call for exit + xor rdi, rdi ; exit code 0 + syscall ; invoke operating system to exit + + section .data +message: db "Hello, Conan", 10 ; note the newline at the end \ No newline at end of file