Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Metadata not correct if used with conanfile.py #101

@weichslgartner

Description

@weichslgartner

When the conan project uses a conanfile.py instead of conanfile.txt the metadata is not correct.
With the following conanfile.py:

import os
from conans import ConanFile, CMake

class TestConan(ConanFile):
    name = "conan-test"
    version = "1.0.0"
    author = "John J. Smith (john.smith@company.com)"
    license = "MIT"
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake", "cmake_find_package"

    def requirements(self):
        self.requires("fmt/8.0.0")
        if os.environ.get("build_flag"):
            self.requires("ms-gsl/3.1.0")

it produce the following output (with command cyclonedx-conan conanfile.py):

{
  "bomFormat": "CycloneDX",
  "specVersion": "1.3",
  "serialNumber": "urn:uuid:7d5b053a-fa8b-44ac-9f2b-0bff188f01cc",
  "version": 1,
  "metadata": {
    "component": {
      "bom-ref": "unknown@0.0.0",
      "type": "application",
      "name": "unknown",
      "version": "0.0.0"
    }
  },
  "components": [
    {
      "bom-ref": "pkg:conan/conan-test@1.0.0?repository_url=localhost",
      "type": "library",
      "name": "conan-test",
      "version": "1.0.0",
      "purl": "pkg:conan/conan-test@1.0.0?repository_url=localhost"
    },
    {
      "bom-ref": "pkg:conan/fmt@8.0.0?repository_url=https://center.conan.io",
      "type": "library",
      "name": "fmt",
      "version": "8.0.0",
      "purl": "pkg:conan/fmt@8.0.0?repository_url=https://center.conan.io"
    }
  ],
  "dependencies": [
    {
      "ref": "pkg:conan/conan-test@1.0.0?repository_url=localhost",
      "dependsOn": [
        "pkg:conan/fmt@8.0.0?repository_url=https://center.conan.io"
      ]
    },
    {
      "ref": "pkg:conan/fmt@8.0.0?repository_url=https://center.conan.io",
      "dependsOn": []
    }
  ]
}

"name" and "version" attributes are set not correctly as node.ref is None is never true.
I also think if the name is defined in the conanfile.py it is better to directly get this attribute from the conanfile instead from the folder name.

I tried to address this issue here:
https://github.com/weichslgartner/cyclonedx-conan/blob/a119c52ba1c6887787b24853a6d2d646d0e78911/src/command.py#L141

It should still work with conanfile.txt as shown in this test:
https://github.com/weichslgartner/cyclonedx-conan/blob/main/tests/test_command.py

I am happy to contribute a PR and open for feedback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions