diff --git a/setup.py b/setup.py index b32c3fa3024..fa989d44efd 100644 --- a/setup.py +++ b/setup.py @@ -178,6 +178,7 @@ def read(*names, **kwargs): 'packageurl-python >= 0.7.0', 'xmltodict >= 0.11.0', 'javaproperties >= 0.5', + 'toml >= 0.10.0', # scancode 'click >= 6.0.0, < 7.0.0', diff --git a/src/packagedcode/__init__.py b/src/packagedcode/__init__.py index 704e2a843f8..668e24c444d 100644 --- a/src/packagedcode/__init__.py +++ b/src/packagedcode/__init__.py @@ -26,6 +26,7 @@ from __future__ import unicode_literals from packagedcode import models +from packagedcode import cargo from packagedcode import freebsd from packagedcode import haxe from packagedcode import maven @@ -54,6 +55,7 @@ npm.NpmPackage, phpcomposer.PHPComposerPackage, haxe.HaxePackage, + cargo.RustCargoCrate, models.MeteorPackage, models.BowerPackage, freebsd.FreeBSDPackage, diff --git a/src/packagedcode/cargo.py b/src/packagedcode/cargo.py new file mode 100644 index 00000000000..bde7a1ac8dc --- /dev/null +++ b/src/packagedcode/cargo.py @@ -0,0 +1,124 @@ + +# Copyright (c) 2019 nexB Inc. and others. All rights reserved. +# http://nexb.com and https://github.com/nexB/scancode-toolkit/ +# The ScanCode software is licensed under the Apache License version 2.0. +# Data generated with ScanCode require an acknowledgment. +# ScanCode is a trademark of nexB Inc. +# +# You may not use this software except in compliance with the License. +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# +# When you publish or redistribute any data created with ScanCode or any ScanCode +# derivative work, you must accompany this data with the following acknowledgment: +# +# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from +# ScanCode should be considered or used as legal advice. Consult an Attorney +# for any legal advice. +# ScanCode is a free software code scanning tool from nexB Inc. and others. +# Visit https://github.com/nexB/scancode-toolkit/ for support and download. + +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +from collections import OrderedDict + +import io +import toml +import logging + +import attr + +from commoncode import filetype +from commoncode import fileutils +from packagedcode import models + + +""" +Handle Rust cargo crates +""" + +TRACE = False + +logger = logging.getLogger(__name__) + +if TRACE: + import sys + logging.basicConfig(stream=sys.stdout) + logger.setLevel(logging.DEBUG) + + +@attr.s() +class RustCargoCrate(models.Package): + metafiles = ('Cargo.toml',) + default_type = 'cargo' + default_primary_language = 'Rust' + default_web_baseurl = "https://crates.io/" + default_download_baseurl = "https://crates.io/api/v1/" + default_api_baseurl = "https://crates.io/api/v1/" + + @classmethod + def recognize(cls, location): + return parse(location) + + @classmethod + def get_package_root(cls, manifest_resource, codebase): + return manifest_resource.parent(codebase) + + def repository_homepage_url(self, baseurl=default_web_baseurl): + return '{}/crates/{}'.format(baseurl, self.name) + + def repository_download_url(self, baseurl=default_download_baseurl): + return '{}/crates/{}/{}/download'.format(baseurl, self.name, self.version) + + def api_data_url(self, baseurl=default_api_baseurl): + return '{}/crates/{}'.format(baseurl, self.name) + + def compute_normalized_license(self): + return models.compute_normalized_license(self.declared_license) + + +def is_cargo_toml(location): + return (filetype.is_file(location) and fileutils.file_name(location).lower() == 'cargo.toml') + + +def parse(location): + """ + Return a Package object from a Cargo.toml file or None. + """ + if not is_cargo_toml(location): + return + + with io.open(location, encoding='utf-8') as loc: + package_data = toml.load(location, _dict=OrderedDict) + + return build_package(package_data) + + +def build_package(package_data): + """ + Return a Pacakge object from a package data mapping or None. + """ + + name = package_data.get('package').get('name') + version = package_data.get('package').get('version') + + # TODO: Remove this ordered_dict_map once cargo.py is able to handle + # the appropriate data (source_packages, dependencies, etc..) + # At the moment, this is only useful for making tests pass + ordered_dict_map = {} + for key in ("source_packages", "dependencies", "keywords", "parties"): + ordered_dict_map[key] = OrderedDict() + + package = RustCargoCrate( + name=name, + version=version, + **ordered_dict_map + ) + + return package diff --git a/src/packagedcode/npm.py b/src/packagedcode/npm.py index 9ffac177390..25db164966a 100644 --- a/src/packagedcode/npm.py +++ b/src/packagedcode/npm.py @@ -219,7 +219,7 @@ def build_package(package_data): if homepage: homepage = homepage[0] else: - homepage ='' + homepage = '' namespace, name = split_scoped_package_name(name) package = NpmPackage( namespace=namespace or None, diff --git a/tests/packagedcode/data/cargo/clap/Cargo.toml b/tests/packagedcode/data/cargo/clap/Cargo.toml new file mode 100644 index 00000000000..e71e3d4c0be --- /dev/null +++ b/tests/packagedcode/data/cargo/clap/Cargo.toml @@ -0,0 +1,92 @@ +[package] + +name = "clap" +version = "2.32.0" +authors = ["Kevin K. "] +exclude = ["examples/*", "clap-test/*", "tests/*", "benches/*", "*.png", "clap-perf/*", "*.dot"] +repository = "https://github.com/clap-rs/clap" +documentation = "https://docs.rs/clap/" +homepage = "https://clap.rs/" +readme = "README.md" +license = "MIT" +keywords = ["argument", "cli", "arg", "parser", "parse"] +categories = ["command-line-interface"] +description = """ +A simple to use, efficient, and full featured Command Line Argument Parser +""" + +[badges] +travis-ci = { repository = "clap-rs/clap" } +appveyor = { repository = "clap-rs/clap" } +coveralls = { repository = "clap-rs/clap", branch = "master" } +is-it-maintained-issue-resolution = { repository = "clap-rs/clap" } +is-it-maintained-open-issues = { repository = "clap-rs/clap" } +maintenance = {status = "actively-developed"} + +[dependencies] +bitflags = "1.0" +unicode-width = "0.1.4" +textwrap = "0.10.0" +strsim = { version = "0.8", optional = true } +yaml-rust = { version = "0.3.5", optional = true } +clippy = { version = "~0.0.166", optional = true } +atty = { version = "0.2.2", optional = true } +vec_map = { version = "0.8", optional = true } +term_size = { version = "0.3.0", optional = true } + +[target.'cfg(not(windows))'.dependencies] +ansi_term = { version = "0.11", optional = true } + +[dev-dependencies] +regex = "1" +# lazy_static 1.2 requires Rust 1.24.1+ +lazy_static = "~1.1" +version-sync = "0.5" + +[features] +default = ["suggestions", "color", "vec_map"] +suggestions = ["strsim"] +color = ["ansi_term", "atty"] +wrap_help = ["term_size", "textwrap/term_size"] +yaml = ["yaml-rust"] +unstable = [] # for building with unstable clap features (doesn't require nightly Rust) (currently none) +nightly = [] # for building with unstable Rust features (currently none) +lints = ["clippy"] # Requires nightly Rust +debug = [] # Enables debug messages +no_cargo = [] # Enable if you're not using Cargo, disables Cargo-env-var-dependent macros +doc = ["yaml"] # All the features which add to documentation + +[profile.release] +opt-level = 3 +debug = false +rpath = false +lto = true +debug-assertions = false +codegen-units = 1 + +[profile.dev] +opt-level = 0 +debug = true +rpath = false +lto = false +debug-assertions = true +codegen-units = 4 + +[profile.test] +opt-level = 1 +debug = true +rpath = false +lto = false +debug-assertions = true +codegen-units = 4 + +[profile.bench] +opt-level = 3 +debug = false +rpath = false +lto = true +debug-assertions = false +codegen-units = 1 + +[package.metadata.docs.rs] +features = ["doc"] diff --git a/tests/packagedcode/data/cargo/clap/Cargo.toml.expected b/tests/packagedcode/data/cargo/clap/Cargo.toml.expected new file mode 100644 index 00000000000..ac6afeec877 --- /dev/null +++ b/tests/packagedcode/data/cargo/clap/Cargo.toml.expected @@ -0,0 +1,35 @@ +{ + "type": "cargo", + "namespace": null, + "name": "clap", + "version": "2.32.0", + "qualifiers": null, + "subpath": null, + "primary_language": "Rust", + "description": null, + "release_date": null, + "parties": {}, + "keywords": {}, + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "manifest_path": null, + "dependencies": {}, + "contains_source_code": null, + "source_packages": {}, + "purl": "pkg:cargo/clap@2.32.0", + "repository_homepage_url": "https://crates.io//crates/clap", + "repository_download_url": "https://crates.io/api/v1//crates/clap/2.32.0/download", + "api_data_url": "https://crates.io/api/v1//crates/clap" +} diff --git a/tests/packagedcode/data/cargo/clippy/Cargo.toml b/tests/packagedcode/data/cargo/clippy/Cargo.toml new file mode 100644 index 00000000000..024b8ff28ad --- /dev/null +++ b/tests/packagedcode/data/cargo/clippy/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "clippy" +version = "0.0.212" +authors = [ + "Manish Goregaokar ", + "Andre Bogus ", + "Georg Brandl ", + "Martin Carton ", + "Oliver Schneider " +] +description = "A bunch of helpful lints to avoid common pitfalls in Rust" +repository = "https://github.com/rust-lang/rust-clippy" +readme = "README.md" +license = "MIT/Apache-2.0" +keywords = ["clippy", "lint", "plugin"] +categories = ["development-tools", "development-tools::cargo-plugins"] +build = "build.rs" +edition = "2018" +publish = false + +[badges] +travis-ci = { repository = "rust-lang/rust-clippy" } +appveyor = { repository = "rust-lang/rust-clippy" } + +[lib] +name = "clippy" +plugin = true +test = false + +[[bin]] +name = "cargo-clippy" +test = false +path = "src/main.rs" + +[[bin]] +name = "clippy-driver" +path = "src/driver.rs" + +[dependencies] +# begin automatic update +clippy_lints = { version = "0.0.212", path = "clippy_lints" } +# end automatic update +regex = "1" +semver = "0.9" +rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"} + +[dev-dependencies] +clippy_dev = { version = "0.0.1", path = "clippy_dev" } +cargo_metadata = "0.7.1" +compiletest_rs = "0.3.19" +lazy_static = "1.0" +serde_derive = "1.0" +clippy-mini-macro-test = { version = "0.2", path = "mini-macro" } +serde = "1.0" +derive-new = "0.5" + +# A noop dependency that changes in the Rust repository, it's a bit of a hack. +# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` +# for more information. +rustc-workspace-hack = "1.0.0" + +[build-dependencies] +rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"} + +[features] +debugging = [] diff --git a/tests/packagedcode/data/cargo/clippy/Cargo.toml.expected b/tests/packagedcode/data/cargo/clippy/Cargo.toml.expected new file mode 100644 index 00000000000..7cd77746e0e --- /dev/null +++ b/tests/packagedcode/data/cargo/clippy/Cargo.toml.expected @@ -0,0 +1,35 @@ +{ + "type": "cargo", + "namespace": null, + "name": "clippy", + "version": "0.0.212", + "qualifiers": null, + "subpath": null, + "primary_language": "Rust", + "description": null, + "release_date": null, + "parties": {}, + "keywords": {}, + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "manifest_path": null, + "dependencies": {}, + "contains_source_code": null, + "source_packages": {}, + "purl": "pkg:cargo/clippy@0.0.212", + "repository_homepage_url": "https://crates.io//crates/clippy", + "repository_download_url": "https://crates.io/api/v1//crates/clippy/0.0.212/download", + "api_data_url": "https://crates.io/api/v1//crates/clippy" +} diff --git a/tests/packagedcode/data/cargo/mdbook/Cargo.toml b/tests/packagedcode/data/cargo/mdbook/Cargo.toml new file mode 100644 index 00000000000..aa5129e47d9 --- /dev/null +++ b/tests/packagedcode/data/cargo/mdbook/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "mdbook" +version = "0.2.4-alpha.0" +authors = [ + "Mathieu David ", + "Michael-F-Bryan ", + "Matt Ickstadt " +] +description = "Create books from markdown files" +documentation = "http://rust-lang-nursery.github.io/mdBook/index.html" +repository = "https://github.com/rust-lang-nursery/mdBook" +keywords = ["book", "gitbook", "rustbook", "markdown"] +license = "MPL-2.0" +readme = "README.md" +exclude = ["book-example/*"] + +[dependencies] +clap = "2.24" +chrono = "0.4" +handlebars = "1.0" +serde = "1.0" +serde_derive = "1.0" +error-chain = "0.12" +serde_json = "1.0" +pulldown-cmark = "0.1.2" +lazy_static = "1.0" +log = "0.4" +env_logger = "0.5" +toml = "0.4.8" +memchr = "2.0" +open = "1.1" +regex = "1.0.0" +tempfile = "3.0" +itertools = "0.7" +shlex = "0.1" +toml-query = "0.7" + +# Watch feature +notify = { version = "4.0", optional = true } + +# Serve feature +iron = { version = "0.6", optional = true } +staticfile = { version = "0.5", optional = true } +ws = { version = "0.7", optional = true} + +# Search feature +elasticlunr-rs = { version = "2.3", optional = true, default-features = false } +ammonia = { version = "1.1", optional = true } + +[dev-dependencies] +select = "0.4" +pretty_assertions = "0.5" +walkdir = "2.0" +pulldown-cmark-to-cmark = "1.1.0" + +[features] +default = ["output", "watch", "serve", "search"] +debug = [] +output = [] +watch = ["notify"] +serve = ["iron", "staticfile", "ws"] +search = ["elasticlunr-rs", "ammonia"] + +[[bin]] +doc = false +name = "mdbook" diff --git a/tests/packagedcode/data/cargo/mdbook/Cargo.toml.expected b/tests/packagedcode/data/cargo/mdbook/Cargo.toml.expected new file mode 100644 index 00000000000..febed74eaf9 --- /dev/null +++ b/tests/packagedcode/data/cargo/mdbook/Cargo.toml.expected @@ -0,0 +1,35 @@ +{ + "type": "cargo", + "namespace": null, + "name": "mdbook", + "version": "0.2.4-alpha.0", + "qualifiers": null, + "subpath": null, + "primary_language": "Rust", + "description": null, + "release_date": null, + "parties": {}, + "keywords": {}, + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "manifest_path": null, + "dependencies": {}, + "contains_source_code": null, + "source_packages": {}, + "purl": "pkg:cargo/mdbook@0.2.4-alpha.0", + "repository_homepage_url": "https://crates.io//crates/mdbook", + "repository_download_url": "https://crates.io/api/v1//crates/mdbook/0.2.4-alpha.0/download", + "api_data_url": "https://crates.io/api/v1//crates/mdbook" +} diff --git a/tests/packagedcode/data/cargo/rustfmt/Cargo.toml b/tests/packagedcode/data/cargo/rustfmt/Cargo.toml new file mode 100644 index 00000000000..2274ae86bd2 --- /dev/null +++ b/tests/packagedcode/data/cargo/rustfmt/Cargo.toml @@ -0,0 +1,67 @@ +[package] + +name = "rustfmt-nightly" +version = "1.0.3" +authors = ["Nicholas Cameron ", "The Rustfmt developers"] +description = "Tool to find and fix Rust formatting issues" +repository = "https://github.com/rust-lang/rustfmt" +readme = "README.md" +license = "Apache-2.0/MIT" +build = "build.rs" +categories = ["development-tools"] +edition = "2018" + +[[bin]] +name = "rustfmt" +path = "src/bin/main.rs" + +[[bin]] +name = "cargo-fmt" +path = "src/cargo-fmt/main.rs" + +[[bin]] +name = "rustfmt-format-diff" +path = "src/format-diff/main.rs" + +[[bin]] +name = "git-rustfmt" +path = "src/git-rustfmt/main.rs" + +[features] +default = ["cargo-fmt", "rustfmt-format-diff"] +cargo-fmt = [] +rustfmt-format-diff = [] +generic-simd = ["bytecount/generic-simd"] + +[dependencies] +atty = "0.2" +itertools = "0.8" +toml = "0.4" +serde = "1.0" +serde_derive = "1.0" +serde_json = "1.0" +unicode-segmentation = "1.0.0" +regex = "1.0" +term = "0.5" +diff = "0.1" +log = "0.4" +env_logger = "0.6" +getopts = "0.2" +derive-new = "0.5" +cargo_metadata = "0.7" +rustc-ap-rustc_target = "373.0.0" +rustc-ap-syntax = "373.0.0" +rustc-ap-syntax_pos = "373.0.0" +failure = "0.1.3" +bytecount = "0.5" +unicode-width = "0.1.5" +unicode_categories = "0.1.1" +dirs = "1.0.4" + +# A noop dependency that changes in the Rust repository, it's a bit of a hack. +# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` +# for more information. +rustc-workspace-hack = "1.0.0" + +[dev-dependencies] +lazy_static = "1.0.0" diff --git a/tests/packagedcode/data/cargo/rustfmt/Cargo.toml.expected b/tests/packagedcode/data/cargo/rustfmt/Cargo.toml.expected new file mode 100644 index 00000000000..91273dbe431 --- /dev/null +++ b/tests/packagedcode/data/cargo/rustfmt/Cargo.toml.expected @@ -0,0 +1,35 @@ +{ + "type": "cargo", + "namespace": null, + "name": "rustfmt-nightly", + "version": "1.0.3", + "qualifiers": null, + "subpath": null, + "primary_language": "Rust", + "description": null, + "release_date": null, + "parties": {}, + "keywords": {}, + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "manifest_path": null, + "dependencies": {}, + "contains_source_code": null, + "source_packages": {}, + "purl": "pkg:cargo/rustfmt-nightly@1.0.3", + "repository_homepage_url": "https://crates.io//crates/rustfmt-nightly", + "repository_download_url": "https://crates.io/api/v1//crates/rustfmt-nightly/1.0.3/download", + "api_data_url": "https://crates.io/api/v1//crates/rustfmt-nightly" +} diff --git a/tests/packagedcode/data/cargo/rustup/Cargo.toml b/tests/packagedcode/data/cargo/rustup/Cargo.toml new file mode 100644 index 00000000000..b5485de2283 --- /dev/null +++ b/tests/packagedcode/data/cargo/rustup/Cargo.toml @@ -0,0 +1,79 @@ +[package] + +name = "rustup" +version = "1.17.0" +edition = "2018" +authors = [ "Diggory Blake " ] +description = "Manage multiple rust installations with ease" + +documentation = "http://rust-lang.github.io/rustup.rs/rustup/index.html" +homepage = "https://github.com/rust-lang/rustup.rs" +repository = "https://github.com/rust-lang/rustup.rs" + +readme = "README.md" + +keywords = ["rustup", "multirust", "install", "proxy"] + +license = "MIT OR Apache-2.0" + +build = "build.rs" + +[features] + +default = ["curl-backend", "reqwest-backend"] + +curl-backend = ["download/curl-backend"] +reqwest-backend = ["download/reqwest-backend"] +vendored-openssl = ['openssl/vendored'] + +# Include in the default set to disable self-update and uninstall. +no-self-update = [] + +[dependencies] +rustup-dist = { path = "src/rustup-dist" } +rustup-utils = { path = "src/rustup-utils" } +download = { path = "src/download" } +clap = "2.18.0" +error-chain = "0.12.0" +itertools = "0.7.6" +libc = "0.2.0" +markdown = "0.2" +rand = "0.5.2" +regex = "1.0.1" +remove_dir_all = "0.5.1" +same-file = "1.0" +scopeguard = "0.3" +sha2 = "0.7.0" +tempdir = "0.3.4" +term = "0.5.1" +time = "0.1.34" +toml = "0.4" +url = "1.1.0" +wait-timeout = "0.1.5" +openssl = { version = '0.10.15', optional = true } + +[target."cfg(windows)".dependencies] +winapi = { version = "0.3", features = ["jobapi", "jobapi2", "processthreadsapi", "psapi", "synchapi", "winuser"] } +winreg = "0.5.0" +gcc = "0.3.50" + +[dev-dependencies] +rustup-mock = { path = "src/rustup-mock", version = "1.1.0" } +lazy_static = "1.0.0" + +[workspace] +members = ["src/download"] + +[lib] +name = "rustup" +path = "src/rustup/lib.rs" +test = false # no unit tests + +[[bin]] +name = "rustup-init" +path = "src/rustup-cli/main.rs" +test = false # no unit tests + +[profile.release] +lto = true +codegen-units = 1 diff --git a/tests/packagedcode/data/cargo/rustup/Cargo.toml.1 b/tests/packagedcode/data/cargo/rustup/Cargo.toml.1 new file mode 100644 index 00000000000..b5485de2283 --- /dev/null +++ b/tests/packagedcode/data/cargo/rustup/Cargo.toml.1 @@ -0,0 +1,79 @@ +[package] + +name = "rustup" +version = "1.17.0" +edition = "2018" +authors = [ "Diggory Blake " ] +description = "Manage multiple rust installations with ease" + +documentation = "http://rust-lang.github.io/rustup.rs/rustup/index.html" +homepage = "https://github.com/rust-lang/rustup.rs" +repository = "https://github.com/rust-lang/rustup.rs" + +readme = "README.md" + +keywords = ["rustup", "multirust", "install", "proxy"] + +license = "MIT OR Apache-2.0" + +build = "build.rs" + +[features] + +default = ["curl-backend", "reqwest-backend"] + +curl-backend = ["download/curl-backend"] +reqwest-backend = ["download/reqwest-backend"] +vendored-openssl = ['openssl/vendored'] + +# Include in the default set to disable self-update and uninstall. +no-self-update = [] + +[dependencies] +rustup-dist = { path = "src/rustup-dist" } +rustup-utils = { path = "src/rustup-utils" } +download = { path = "src/download" } +clap = "2.18.0" +error-chain = "0.12.0" +itertools = "0.7.6" +libc = "0.2.0" +markdown = "0.2" +rand = "0.5.2" +regex = "1.0.1" +remove_dir_all = "0.5.1" +same-file = "1.0" +scopeguard = "0.3" +sha2 = "0.7.0" +tempdir = "0.3.4" +term = "0.5.1" +time = "0.1.34" +toml = "0.4" +url = "1.1.0" +wait-timeout = "0.1.5" +openssl = { version = '0.10.15', optional = true } + +[target."cfg(windows)".dependencies] +winapi = { version = "0.3", features = ["jobapi", "jobapi2", "processthreadsapi", "psapi", "synchapi", "winuser"] } +winreg = "0.5.0" +gcc = "0.3.50" + +[dev-dependencies] +rustup-mock = { path = "src/rustup-mock", version = "1.1.0" } +lazy_static = "1.0.0" + +[workspace] +members = ["src/download"] + +[lib] +name = "rustup" +path = "src/rustup/lib.rs" +test = false # no unit tests + +[[bin]] +name = "rustup-init" +path = "src/rustup-cli/main.rs" +test = false # no unit tests + +[profile.release] +lto = true +codegen-units = 1 diff --git a/tests/packagedcode/data/cargo/rustup/Cargo.toml.expected b/tests/packagedcode/data/cargo/rustup/Cargo.toml.expected new file mode 100644 index 00000000000..60edc410175 --- /dev/null +++ b/tests/packagedcode/data/cargo/rustup/Cargo.toml.expected @@ -0,0 +1,35 @@ +{ + "type": "cargo", + "namespace": null, + "name": "rustup", + "version": "1.17.0", + "qualifiers": null, + "subpath": null, + "primary_language": "Rust", + "description": null, + "release_date": null, + "parties": {}, + "keywords": {}, + "homepage_url": null, + "download_url": null, + "size": null, + "sha1": null, + "md5": null, + "sha256": null, + "sha512": null, + "bug_tracking_url": null, + "code_view_url": null, + "vcs_url": null, + "copyright": null, + "license_expression": null, + "declared_license": null, + "notice_text": null, + "manifest_path": null, + "dependencies": {}, + "contains_source_code": null, + "source_packages": {}, + "purl": "pkg:cargo/rustup@1.17.0", + "repository_homepage_url": "https://crates.io//crates/rustup", + "repository_download_url": "https://crates.io/api/v1//crates/rustup/1.17.0/download", + "api_data_url": "https://crates.io/api/v1//crates/rustup" +} diff --git a/tests/packagedcode/data/recon/Cargo.toml b/tests/packagedcode/data/recon/Cargo.toml new file mode 100644 index 00000000000..024b8ff28ad --- /dev/null +++ b/tests/packagedcode/data/recon/Cargo.toml @@ -0,0 +1,66 @@ +[package] +name = "clippy" +version = "0.0.212" +authors = [ + "Manish Goregaokar ", + "Andre Bogus ", + "Georg Brandl ", + "Martin Carton ", + "Oliver Schneider " +] +description = "A bunch of helpful lints to avoid common pitfalls in Rust" +repository = "https://github.com/rust-lang/rust-clippy" +readme = "README.md" +license = "MIT/Apache-2.0" +keywords = ["clippy", "lint", "plugin"] +categories = ["development-tools", "development-tools::cargo-plugins"] +build = "build.rs" +edition = "2018" +publish = false + +[badges] +travis-ci = { repository = "rust-lang/rust-clippy" } +appveyor = { repository = "rust-lang/rust-clippy" } + +[lib] +name = "clippy" +plugin = true +test = false + +[[bin]] +name = "cargo-clippy" +test = false +path = "src/main.rs" + +[[bin]] +name = "clippy-driver" +path = "src/driver.rs" + +[dependencies] +# begin automatic update +clippy_lints = { version = "0.0.212", path = "clippy_lints" } +# end automatic update +regex = "1" +semver = "0.9" +rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"} + +[dev-dependencies] +clippy_dev = { version = "0.0.1", path = "clippy_dev" } +cargo_metadata = "0.7.1" +compiletest_rs = "0.3.19" +lazy_static = "1.0" +serde_derive = "1.0" +clippy-mini-macro-test = { version = "0.2", path = "mini-macro" } +serde = "1.0" +derive-new = "0.5" + +# A noop dependency that changes in the Rust repository, it's a bit of a hack. +# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust` +# for more information. +rustc-workspace-hack = "1.0.0" + +[build-dependencies] +rustc_tools_util = { version = "0.1.1", path = "rustc_tools_util"} + +[features] +debugging = [] diff --git a/tests/packagedcode/data/rubygems/gemspec/cat.gemspec.expected.json b/tests/packagedcode/data/rubygems/gemspec/cat.gemspec.expected.json index f8ffc66c7c9..5b0c126fc26 100644 --- a/tests/packagedcode/data/rubygems/gemspec/cat.gemspec.expected.json +++ b/tests/packagedcode/data/rubygems/gemspec/cat.gemspec.expected.json @@ -32785,6 +32785,9 @@ "thirdparty/text_unidecode-1.2-py2.py3-none-any.whl", "thirdparty/text_unidecode-1.2-py2.py3-none-any.whl.ABOUT", "thirdparty/text_unidecode-1.2-py2.py3-none-any.whl.NOTICE", + "thirdparty/toml-0.10.0-py2.py3-none-any.whl", + "thirdparty/toml-0.10.0-py2.py3-none-any.whl.ABOUT", + "thirdparty/toml-0.10.0-py2.py3-none-any.whl.LICENSE", "thirdparty/typecode_libmagic-5.22-py2-none-manylinux1_x86_64.whl", "thirdparty/typecode_libmagic-5.22-py2-none-win32.whl", "thirdparty/typecode_libmagic-5.22-py2-none-win_amd64.whl", @@ -32840,4 +32843,4 @@ "original_platform": null, "new_platform": "ruby", "specification_version": 4 -} \ No newline at end of file +} diff --git a/tests/packagedcode/test_cargo.py b/tests/packagedcode/test_cargo.py new file mode 100644 index 00000000000..741487b26c0 --- /dev/null +++ b/tests/packagedcode/test_cargo.py @@ -0,0 +1,67 @@ + +# Copyright (c) 2019 nexB Inc. and others. All rights reserved. +# http://nexb.com and https://github.com/nexB/scancode-toolkit/ +# The ScanCode software is licensed under the Apache License version 2.0. +# Data generated with ScanCode require an acknowledgment. +# ScanCode is a trademark of nexB Inc. +# +# You may not use this software except in compliance with the License. +# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 +# Unless required by applicable law or agreed to in writing, software distributed +# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +# CONDITIONS OF ANY KIND, either express or implied. See the License for the +# specific language governing permissions and limitations under the License. +# +# When you publish or redistribute any data created with ScanCode or any ScanCode +# derivative work, you must accompany this data with the following acknowledgment: +# +# Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES +# OR CONDITIONS OF ANY KIND, either express or implied. No content created from +# ScanCode should be considered or used as legal advice. Consult an Attorney +# for any legal advice. +# ScanCode is a free software code scanning tool from nexB Inc. and others. +# Visit https://github.com/nexB/scancode-toolkit/ for support and download. + +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +import os + +from packagedcode import cargo + +from packages_test_utils import PackageTester + + +class TestCargo(PackageTester): + test_data_dir = os.path.join(os.path.dirname(__file__), 'data') + + def test_parse_clap(self): + test_file = self.get_test_loc('cargo/clap/Cargo.toml') + expected_loc = self.get_test_loc('cargo/clap/Cargo.toml.expected') + package = cargo.parse(test_file) + self.check_package(package, expected_loc, regen=False) + + def test_parse_clippy(self): + test_file = self.get_test_loc('cargo/clippy/Cargo.toml') + expected_loc = self.get_test_loc('cargo/clippy/Cargo.toml.expected') + package = cargo.parse(test_file) + self.check_package(package, expected_loc, regen=False) + + def test_parse_mdbook(self): + test_file = self.get_test_loc('cargo/mdbook/Cargo.toml') + expected_loc = self.get_test_loc('cargo/mdbook/Cargo.toml.expected') + package = cargo.parse(test_file) + self.check_package(package, expected_loc, regen=False) + + def test_parse_rustfmt(self): + test_file = self.get_test_loc('cargo/rustfmt/Cargo.toml') + expected_loc = self.get_test_loc('cargo/rustfmt/Cargo.toml.expected') + package = cargo.parse(test_file) + self.check_package(package, expected_loc, regen=False) + + def test_parse_rustup(self): + test_file = self.get_test_loc('cargo/rustup/Cargo.toml') + expected_loc = self.get_test_loc('cargo/rustup/Cargo.toml.expected') + package = cargo.parse(test_file) + self.check_package(package, expected_loc, regen=False) diff --git a/tests/packagedcode/test_recognize.py b/tests/packagedcode/test_recognize.py index 4d9cebaa1d9..f993e998dad 100644 --- a/tests/packagedcode/test_recognize.py +++ b/tests/packagedcode/test_recognize.py @@ -33,6 +33,7 @@ from packagedcode import freebsd from packagedcode import maven from packagedcode import npm +from packagedcode import cargo from packagedcode import phpcomposer from packagedcode import rpm from packagedcode.recognize import recognize_package @@ -110,6 +111,11 @@ def test_recognize_npm(self): package = recognize_package(test_file) assert isinstance(package, npm.NpmPackage) + def test_recognize_cargo(self): + test_file = self.get_test_loc('recon/Cargo.toml') + package = recognize_package(test_file) + assert isinstance(package, cargo.RustCargoCrate) + def test_recognize_composer(self): test_file = self.get_test_loc('recon/composer.json') package = recognize_package(test_file) diff --git a/thirdparty/toml-0.10.0-py2.py3-none-any.whl b/thirdparty/toml-0.10.0-py2.py3-none-any.whl new file mode 100644 index 00000000000..bcfb2c68c90 Binary files /dev/null and b/thirdparty/toml-0.10.0-py2.py3-none-any.whl differ diff --git a/thirdparty/toml-0.10.0-py2.py3-none-any.whl.ABOUT b/thirdparty/toml-0.10.0-py2.py3-none-any.whl.ABOUT new file mode 100644 index 00000000000..043d787f185 --- /dev/null +++ b/thirdparty/toml-0.10.0-py2.py3-none-any.whl.ABOUT @@ -0,0 +1,15 @@ +about_resource: toml-0.10.0-py2.py3-none-any.whl +checksum_md5: 70f2a3ce1fc099c20702b55f44f0b130 +checksum_sha1: 5a6d4ad5089719e4f567997a24da13204db2eb28 +contact: uiri@xqz.ca +copyright: Copyright 2013-2018 William Pearson +description: Python Library for Tom's Obvious, Minimal Language +download_url: https://files.pythonhosted.org/packages/b9/19/5cbd78eac8b1783671c40e34bb0fa83133a06d340a38b55c645076d40094/toml-0.10.0.tar.gz +homepage_url: https://github.com/uiri/toml +license_expression: mit +name: toml +notes: Used for parsing for TOML configuration files. +owner: Willam Pearson +owner_url: https://github.com/uiri +vcs_url: https://github.com/uiri/toml +version: 0.10.0 diff --git a/thirdparty/toml-0.10.0.tar.gz b/thirdparty/toml-0.10.0.tar.gz new file mode 100644 index 00000000000..c44def8b0cf Binary files /dev/null and b/thirdparty/toml-0.10.0.tar.gz differ diff --git a/thirdparty/toml.LICENSE b/thirdparty/toml.LICENSE new file mode 100644 index 00000000000..32ff3596f3c --- /dev/null +++ b/thirdparty/toml.LICENSE @@ -0,0 +1,26 @@ +The MIT License + +Copyright 2013-2018 William Pearson +Copyright 2015-2016 Julien Enselme +Copyright 2016 Google Inc. +Copyright 2017 Samuel Vasko +Copyright 2017 Nate Prewitt +Copyright 2017 Jack Evans + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE.