#68 Do not pull optional dependencies
Merged 6 years ago by ignatenkobrain. Opened 6 years ago by ignatenkobrain.
fedora-rust/ ignatenkobrain/rust2rpm no-optional-deps  into  master

file modified
+11 -9
@@ -2,8 +2,10 @@ 

  #   https://github.com/rust-lang/cargo/issues/6397

  # But we can set CARGO_HOME locally, which is a good idea anyway to make sure

  # it never writes to ~/.cargo during rpmbuild.

- %__cargo %{_bindir}/env CARGO_HOME=.cargo %{_bindir}/cargo

- %__cargo_common_opts %{?_smp_mflags}

+ # We also need RUSTC_BOOTSTRAP since we use -Z avoid-dev-deps

+ # until it gets stabilized: https://github.com/rust-lang/cargo/issues/5133

+ %__cargo %{_bindir}/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 %{_bindir}/cargo

+ %__cargo_common_opts %{?_smp_mflags} -Z avoid-dev-deps

  %__cargo_inspector %{_bindir}/cargo-inspector

  

  %cargo_registry %{_datadir}/cargo/registry
@@ -36,10 +38,6 @@ 

  replace-with = "local-registry"\

  EOF\

  %{__rm} -f Cargo.lock \

- %if ! %{with check} \

- # https://github.com/rust-lang/cargo/issues/3732 \

- %{__awk} -i inplace -v INPLACE_SUFFIX=.orig '/^\\\[dev-dependencies/{f=1;next} /^\\\[/{f=0}; !f' Cargo.toml \

- %endif \

  )

  

  %__cargo_parse_opts(naf:) %{shrink:\
@@ -74,10 +72,14 @@ 

    CRATE_VERSION=$(%__cargo_inspector --version Cargo.toml)          \

    REG_DIR=%{buildroot}%{cargo_registry}/$CRATE_NAME-$CRATE_VERSION  \

    %{__mkdir} -p $REG_DIR                                            \

+ # Drop all dependency/features information                          \

+ # so that cargo doesn't fail resolving dependencies:                \

+ # https://github.com/rust-lang/cargo/pull/6729                      \

+   %{__awk} -i inplace -v INPLACE_SUFFIX=.deps '/^\\\[((.+\\\.)?((dev|build)-)?dependencies|features)/{f=1;next} /^\\\[/{f=0}; !f' Cargo.toml \

    %{__cargo} package -l | xargs -d '\\\n' %{__cp} --parents -a -t $REG_DIR \

- %if ! %{with check}                                                 \

-   %{__cp} -a Cargo.toml.orig $REG_DIR/Cargo.toml                    \

- %endif                                                              \

+   %{__mv} Cargo.toml{.deps,}                                        \

+   %{__cp} -a Cargo.toml $REG_DIR/Cargo.toml                         \

+   %{__rm} -f $REG_DIR/Cargo.toml.orig                               \

    echo '{"files":{},"package":""}' > $REG_DIR/.cargo-checksum.json  \

  fi \

  if %__cargo_is_bin; then                                            \

file modified
+16 -13
@@ -24,13 +24,14 @@ 

  XDG_CACHE_HOME = os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))

  CACHEDIR = os.path.join(XDG_CACHE_HOME, "rust2rpm")

  API_URL = "https://crates.io/api/v1/"

- JINJA_ENV = jinja2.Environment(loader=jinja2.ChoiceLoader([

-                                    jinja2.FileSystemLoader(["/"]),

-                                    jinja2.PackageLoader("rust2rpm", "templates"),

-                                ]),

-                                extensions=["jinja2.ext.do"],

-                                trim_blocks=True,

-                                lstrip_blocks=True)

+ JINJA_ENV = jinja2.Environment(

+     loader=jinja2.ChoiceLoader([

+         jinja2.FileSystemLoader(["/"]),

+         jinja2.PackageLoader("rust2rpm", "templates"),

+     ]),

+     extensions=["jinja2.ext.do"],

+     trim_blocks=True,

+     lstrip_blocks=True)

  

  def get_default_target():

      # TODO: add fallback for /usr/lib/os-release
@@ -122,8 +123,7 @@ 

          req = requests.get(url, stream=True)

          req.raise_for_status()

          total = int(req.headers["Content-Length"])

-         with remove_on_error(cratef), \

-              open(cratef, "wb") as f:

+         with remove_on_error(cratef), open(cratef, "wb") as f:

              for chunk in tqdm.tqdm(req.iter_content(), f"Downloading {cratef_base}".format(cratef_base),

                                     total=total, unit="B", unit_scale=True):

                  f.write(chunk)
@@ -183,7 +183,7 @@ 

              cratef, crate, version = local_crate(crate, version)

          else:

              if store:

-                 raise ValueError('--store-crate can only be used for a crate')

+                 raise ValueError("--store-crate can only be used for a crate")

  

              toml, crate, version = local_toml(crate, version)

              diff = make_patch(toml, enabled=patch, tmpfile=True)
@@ -220,6 +220,8 @@ 

                          help="Do initial patching of Cargo.toml")

      parser.add_argument("-s", "--store-crate", action="store_true",

                          help="Store crate in current directory")

+     parser.add_argument("--all-features", action="store_true",

+                         help="Activate all available features")

      parser.add_argument("crate", help="crates.io name\n"

                                        "path/to/local.crate\n"

                                        "path/to/project/",
@@ -232,7 +234,7 @@ 

          return

  

      if args.crate is None:

-         parser.error('required crate/path argument missing')

+         parser.error("required crate/path argument missing")

  

      crate, diff, metadata = make_diff_metadata(args.crate, args.version,

                                                 patch=args.patch,
@@ -250,8 +252,9 @@ 

      kwargs = {}

      kwargs["crate"] = crate

      kwargs["target"] = args.target

+     kwargs["all_features"] = args.all_features

      bins = [tgt for tgt in metadata.targets if tgt.kind == "bin"]

-     libs = [tgt for tgt in metadata.targets if tgt.kind in ("lib", "rlib", "proc-macro")]

+     libs = [tgt for tgt in metadata.targets if tgt.kind in {"lib", "rlib", "proc-macro"}]

      is_bin = len(bins) > 0

      is_lib = len(libs) > 0

      if is_bin:
@@ -268,7 +271,7 @@ 

      else:

          kwargs["auto_changelog_entry"] = True

  

-     if args.target in ("fedora", "mageia", "opensuse"):

+     if args.target in {"fedora", "mageia", "opensuse"}:

          kwargs["include_build_requires"] = True

          kwargs["include_provides"] = False

          kwargs["include_requires"] = False

file modified
+3 -3
@@ -17,12 +17,12 @@ 

  def spdx_to_fedora_map():

      with open(SPDX_TO_FEDORA_CSV, newline='') as f:

          reader = _csv.DictReader(f)

-         return {line['SPDX License Identifier'] : line['Fedora Short Name']

+         return {line['SPDX License Identifier']: line['Fedora Short Name']

                  for line in reader

                  if line['SPDX License Identifier']}

  

  def dump_sdpx_to_fedora_map(file):

-     for k,v in spdx_to_fedora_map().items():

+     for k, v in spdx_to_fedora_map().items():

          print(f"{k} → {v}", file=file)

  

  def translate_license_fedora(license):
@@ -39,7 +39,7 @@ 

              if mapped is None:

                  comments += f'# FIXME: Upstream uses unknown SPDX tag {tag}!'

                  final.append(tag)

-             elif mapped is '':

+             elif mapped == '':

                  comments += f"# FIXME: Upstream SPDX tag {tag} not listed in Fedora's good licenses list.\n"

                  comments += "# FIXME: This package might not be allowed in Fedora!\n"

                  final.append(tag)

file modified
+11 -11
@@ -25,13 +25,13 @@ 

  

      @classmethod

      def from_json(cls, metadata):

-         features = set(metadata['features'])

-         if metadata['uses_default_features']:

-             features.add('default')

-         kwargs = {'name': metadata['name'],

-                   'req': metadata['req'],

-                   'optional': metadata['optional'],

-                   'features': features}

+         features = set(metadata["features"])

+         if metadata["uses_default_features"]:

+             features.add("default")

+         kwargs = {"name": metadata["name"],

+                   "req": metadata["req"],

+                   "optional": metadata["optional"],

+                   "features": features}

          return cls(**kwargs)

  

      @staticmethod
@@ -45,7 +45,7 @@ 

                  # Any means any

                  continue

              ver = req.spec

-             if req.kind in (req.KIND_NEQ, req.KIND_EMPTY):

+             if req.kind in {req.KIND_NEQ, req.KIND_EMPTY}:

                  raise NotImplementedError(f"'!=' and empty kinds are not supported: {req}")

              coerced = str(semver.Version.coerce(str(ver)))

              if ver.prerelease:
@@ -54,7 +54,7 @@ 

                  ver = ver.next_patch()

              if req.kind == req.KIND_EQUAL:

                  req.kind = req.KIND_SHORTEQ

-             if req.kind in (req.KIND_CARET, req.KIND_COMPATIBLE):

+             if req.kind in {req.KIND_CARET, req.KIND_COMPATIBLE}:

                  if ver.major == 0:

                      if ver.minor is not None:

                          if ver.minor != 0 or ver.patch is None:
@@ -74,11 +74,11 @@ 

                      upper = ver.next_minor()

                  reqs.append((">=", coerced))

                  reqs.append(("<", upper))

-             elif req.kind in (req.KIND_SHORTEQ,

+             elif req.kind in {req.KIND_SHORTEQ,

                                req.KIND_GT,

                                req.KIND_GTE,

                                req.KIND_LT,

-                               req.KIND_LTE):

+                               req.KIND_LTE}:

                  reqs.append((str(req.kind), coerced))

              else:

                  raise AssertionError(f"Found unhandled kind: {req.kind}")

file modified
+7 -7
@@ -44,12 +44,12 @@ 

  ExclusiveArch:  %{rust_arches}

  

  BuildRequires:  rust-packaging

- {# We will put all non-optional and optional dependencies until

-    https://github.com/rust-lang/cargo/issues/5133

-    is solved

+ {% if not all_features %}

  {% set buildrequires = normalize_deps(md.requires("default", resolve=True))|sort %}

- #}

+ {% else %}

  {% set buildrequires = normalize_deps(md.all_dependencies)|sort %}

+ {% set cargo_args = " -a" %}

+ {% endif %}

  {% for req in buildrequires %}

  BuildRequires:  {{ req }}

  {% endfor %}
@@ -163,14 +163,14 @@ 

  %cargo_prep

  

  %build

- %cargo_build

+ %cargo_build{{ cargo_args }}

  

  %install

- %cargo_install

+ %cargo_install{{ cargo_args }}

  

  %if %{with check}

  %check

- %cargo_test

+ %cargo_test{{ cargo_args }}

  %endif

  

  %changelog

rebased onto ccc7ed42c168675efc4b9719dad12800b92450d5

6 years ago

rebased onto 5fbb0558d401c26f04e274b6b1fc5b0ed9d6e4cd

6 years ago

rebased onto 1788b1ed32f0114ae85f20c93c436d78a710bdc2

6 years ago

rebased onto 72d9afecc6da319e1d59170f07a7b78afbbb1a68

6 years ago

rebased onto 643bf0d32982b67854a39586244b25f54518de02

6 years ago

rebased onto 604938a8bab778c58333643c3e069533327699e2

6 years ago

rebased onto 5d7a0b2

6 years ago

2 new commits added

  • trivial: Use same codestyle
  • Add support for --all-features
6 years ago

3 new commits added

  • trivial: Use same codestyle
  • Add support for --all-features
  • Do not pull optional dependencies
6 years ago

Pull-Request has been merged by ignatenkobrain

6 years ago