Repository: conan-io/conan-center-index

Issue:
[package] hash-library/8.0: Errors in recipe for Conan v2
### Description

Building hash-library/8.0 with Conan v2 results in the following errors:

```
ERROR: hash-library/8.0: Error in validate() method, line 64
        if self.settings.os == "Windows" and self.options.shared:
        ConanException: 'self.settings' access in 'validate()' method is forbidden
```

and 

```
ERROR: hash-library/8.0: Error in package() method, line 55
        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
        AttributeError: 'HashLibraryConan' object has no attribute 'copy'
```

### Package and Environment Details

* Package Name/Version: **hash-library/8.0**
* Operating System+version: **Linux Fedora 35**
* Compiler+version: **GCC 10**
* Conan version: **conan 2.0.0-beta4**
* Python version: **Python 3.8.12**


### Conan profile

[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=10
os=Linux
[buildenv]
CC=/usr/local/bin/gcc-10
CXX=/usr/local/bin/g++-10

### Steps to reproduce

conan create . --version 8.0

### Logs

<details><summary>Click to expand log for error 1</summary>

```
Exporting the recipe
WARN: Name containing special chars is discouraged 'hash-library'
hash-library/8.0: Exporting package recipe
hash-library/8.0 exports: File 'conandata.yml' found. Exporting it...
hash-library/8.0: Copied 1 '.yml' file: conandata.yml
hash-library/8.0 exports: Copied 1 '.yml' file: conandata.yml
hash-library/8.0: Copied 1 '.txt' file: CMakeLists.txt
hash-library/8.0: Copied 1 '.patch' file: 001-fix-macos.patch
hash-library/8.0 exports_sources: Copied 1 '.txt' file: CMakeLists.txt
hash-library/8.0 exports_sources: Copied 1 '.patch' file: 001-fix-macos.patch
hash-library/8.0: Using the exported files summary hash as the recipe revision: 71479e04ff80814eb28b343aac9b9b57 
hash-library/8.0: A new conanfile.py version was exported
hash-library/8.0: Folder: /home/lkloeckner/.conan2/p/ed3873a492c80f09/e
hash-library/8.0: Exported revision: 71479e04ff80814eb28b343aac9b9b57

-------- Input profiles --------
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=10
os=Linux
[buildenv]
CC=/usr/local/bin/gcc-10
CXX=/usr/local/bin/g++-10

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=10
os=Linux
[buildenv]
CC=/usr/local/bin/gcc-10
CXX=/usr/local/bin/g++-10


-------- Computing dependency graph --------
Graph root
    virtual
Requirements
    hash-library/8.0#71479e04ff80814eb28b343aac9b9b57 - Cache

-------- Computing necessary packages --------
ERROR: hash-library/8.0: Error in validate() method, line 66
        if self.settings.os == "Windows" and self.options.shared:
        ConanException: 'self.settings' access in 'validate()' method is forbidden
```

</details>

<details><summary>Click to expand log for error 2</summary>

```
Exporting the recipe
WARN: Name containing special chars is discouraged 'hash-library'
hash-library/8.0: Exporting package recipe
hash-library/8.0 exports: File 'conandata.yml' found. Exporting it...
hash-library/8.0: Copied 1 '.yml' file: conandata.yml
hash-library/8.0 exports: Copied 1 '.yml' file: conandata.yml
hash-library/8.0: Copied 1 '.txt' file: CMakeLists.txt
hash-library/8.0: Copied 1 '.patch' file: 001-fix-macos.patch
hash-library/8.0 exports_sources: Copied 1 '.txt' file: CMakeLists.txt
hash-library/8.0 exports_sources: Copied 1 '.patch' file: 001-fix-macos.patch
hash-library/8.0: Using the exported files summary hash as the recipe revision: 202d973623faca5eea85508d796fd06e 
hash-library/8.0: A new conanfile.py version was exported
hash-library/8.0: Folder: /home/lkloeckner/.conan2/p/490f677c75abb1ce/e
hash-library/8.0: Exported revision: 202d973623faca5eea85508d796fd06e

-------- Input profiles --------
Profile host:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=10
os=Linux
[buildenv]
CC=/usr/local/bin/gcc-10
CXX=/usr/local/bin/g++-10

Profile build:
[settings]
arch=x86_64
build_type=Release
compiler=gcc
compiler.cppstd=17
compiler.libcxx=libstdc++11
compiler.version=10
os=Linux
[buildenv]
CC=/usr/local/bin/gcc-10
CXX=/usr/local/bin/g++-10


-------- Computing dependency graph --------
Graph root
    virtual
Requirements
    hash-library/8.0#202d973623faca5eea85508d796fd06e - Cache

-------- Computing necessary packages --------
hash-library/8.0: Forced build from source
Requirements
    hash-library/8.0#202d973623faca5eea85508d796fd06e:c02f97045ac96d3afb248507181d5e11c72951c9 - Build

-------- Installing packages --------

-------- Installing (downloading, building) binaries... --------
hash-library/8.0: Calling source() in /home/lkloeckner/.conan2/p/490f677c75abb1ce/s
Downloading hash_library_v8.tar.gz

hash-library/8.0: Copying sources to build folder
hash-library/8.0: Building your package in /home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b
hash-library/8.0: Writing generators to /home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b
hash-library/8.0: Generator 'CMakeToolchain' calling 'generate()'
hash-library/8.0: Preset 'release' added to CMakePresets.json. Invoke it manually using 'cmake --preset release'
hash-library/8.0: If your CMake version is not compatible with CMakePresets (<3.19) call cmake like: 'cmake <path> -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=Release'
hash-library/8.0: Aggregating env generators
hash-library/8.0: Calling build()
hash-library/8.0: CMake command: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b"
hash-library/8.0: RUN: cmake -G "Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b/conan_toolchain.cmake" -DCMAKE_INSTALL_PREFIX="/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/p" -DCMAKE_POLICY_DEFAULT_CMP0091="NEW" -DCMAKE_BUILD_TYPE="Release" "/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b"
-- Using Conan toolchain: /home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b/conan_toolchain.cmake
-- Conan toolchain: Setting CMAKE_POSITION_INDEPENDENT_CODE=ON (options.fPIC)
-- Conan toolchain: C++ Standard 17 with extensions OFF
-- Conan toolchain: Setting BUILD_SHARED_LIBS = OFF
-- The CXX compiler identification is GNU 10.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/local/bin/g++-10 - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_POLICY_DEFAULT_CMP0091


-- Build files have been written to: /home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b
hash-library/8.0: CMake command: cmake --build "/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b" -- -j8
hash-library/8.0: RUN: cmake --build "/home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b" -- -j8
[ 28%] Building CXX object CMakeFiles/hash-library.dir/source_subfolder/keccak.cpp.o
[ 28%] Building CXX object CMakeFiles/hash-library.dir/source_subfolder/crc32.cpp.o
[ 42%] Building CXX object CMakeFiles/hash-library.dir/source_subfolder/md5.cpp.o
[ 57%] Building CXX object CMakeFiles/hash-library.dir/source_subfolder/sha1.cpp.o
[ 71%] Building CXX object CMakeFiles/hash-library.dir/source_subfolder/sha256.cpp.o
[ 85%] Building CXX object CMakeFiles/hash-library.dir/source_subfolder/sha3.cpp.o
[100%] Linking CXX static library libhash-library.a
[100%] Built target hash-library
hash-library/8.0: Package 'c02f97045ac96d3afb248507181d5e11c72951c9' built
hash-library/8.0: Build folder /home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/b
hash-library/8.0: Generated conaninfo.txt
hash-library/8.0: Generating the package
hash-library/8.0: Temporary package folder /home/lkloeckner/.conan2/p/tmp/a575c474cf7ea733/p
hash-library/8.0: Calling package()
ERROR: hash-library/8.0: Error in package() method, line 57
        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
        AttributeError: 'HashLibraryConan' object has no attribute 'copy'
```

</details>


Discussion:

Resolving patch:
diff --git a/recipes/hash-library/all/conanfile.py b/recipes/hash-library/all/conanfile.py
--- a/recipes/hash-library/all/conanfile.py
+++ b/recipes/hash-library/all/conanfile.py
@@ -1,6 +1,8 @@
+from os.path import join
+
 from conan import ConanFile
 from conan.tools.cmake import CMake
-from conan.tools.files import apply_conandata_patches, get
+from conan.tools.files import apply_conandata_patches, copy, get
 from conan.errors import ConanInvalidConfiguration
 
 required_conan_version = ">=1.52.0"
@@ -52,7 +54,7 @@ def build(self):
         cmake.build()
 
     def package(self):
-        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
+        copy(self, "LICENSE", self._source_subfolder, join(self.package_folder, "licenses"))
         cmake = CMake(self)
         cmake.configure()
         cmake.install()
@@ -61,5 +63,5 @@ def package_info(self):
         self.cpp_info.libs = ["hash-library"]
 
     def validate(self):
-        if self.settings.os == "Windows" and self.options.shared:
+        if self.info.settings.os == "Windows" and self.info.options.shared:
             raise ConanInvalidConfiguration("hash-library does not support shared builds on Windows.")


Test patch: