On 12/12/2020 19:32, Andrej Shadura wrote:
> Have you had a chance to have a look at it? :)

For your convenience, I’ve rebased it to the current HEAD.

-- 
Cheers,
  Andrej
>From 393f06dcf7be43488b3410a38308bf12df321707 Mon Sep 17 00:00:00 2001
From: Andrej Shadura <andrew.shad...@collabora.co.uk>
Date: Fri, 13 Dec 2019 16:07:46 +0100
Subject: [PATCH v2] WIP: Scan Rust source code getting the defaults from
 Cargo.toml

---
 lib/Dpkg/Copyright/Scanner.pm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/Dpkg/Copyright/Scanner.pm b/lib/Dpkg/Copyright/Scanner.pm
index f24aeb43..4369096d 100644
--- a/lib/Dpkg/Copyright/Scanner.pm
+++ b/lib/Dpkg/Copyright/Scanner.pm
@@ -9,6 +9,7 @@ use Array::IntSpan;
 use Path::Tiny;
 use Time::localtime;
 use Carp;
+use TOML;
 use YAML::XS qw/LoadFile/;
 
 $YAML::XS::LoadBlessed = 0;
@@ -136,6 +137,7 @@ $default{check} = << 'EOR2' ;
        |sh
        |php
        |py(|x)
+       |rs                       # rust
        |rb
        |java
        |js
@@ -661,6 +663,27 @@ sub __load_fill_blank_data ($current_dir) {
         }
     }
 
+    my $cargotoml = $current_dir->child('Cargo.toml');
+    if ($cargotoml->is_file) {
+        my $toml = $cargotoml->slurp_utf8;
+        my $data = TOML::from_toml($toml);
+        my $l = $data->{'package'}{'license'};
+        my $c = $data->{'package'}{'authors'};
+        if (!$fill_blanks{'.*'}) {
+            if (defined $l) {
+                # Cargo.toml spells AND and OR in capitals
+                # and allows / as a synonym to OR
+                $l =~ s! AND ! and !g;
+                $l =~ s! OR ! or !g;
+                $l =~ s!/! or !g;
+                $fill_blanks{'.*'}->{license} = $l;
+            }
+            if (defined $c) {
+                $fill_blanks{'.*'}->{copyright} = join("\n ", @$c);
+            }
+        }
+    }
+
     return \%fill_blanks;
 }
 
-- 
2.27.0

Reply via email to