]> git.e2factory.org Git - e2factory.git/commitdiff
ls-project: add --unused option
authorTobias Ulmer <tu@emlix.com>
Thu, 2 Mar 2017 16:14:05 +0000 (17:14 +0100)
committerTobias Ulmer <tu@emlix.com>
Thu, 2 Mar 2017 16:40:59 +0000 (17:40 +0100)
Shows all unused results, sources, licences and chroot groups,
respecting result selection on the command line.

Signed-off-by: Tobias Ulmer <tu@emlix.com>
Changelog
doc/man/e2-ls-project.1.in
local/e2-ls-project.lua

index f6856dc4e8ff2a50c442823660a48f99d1c49d6c..15a18ce68bf1d9e65ac0f7b44fe25406ddee71b5 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,5 @@
 NEXT:
+ * ls-project add --unused option
  * ls-project <result> only shows chroot groups used by listed results
  * ls-project <result> only shows licences used by the listed sources
  * Add new source type "licence", providing licence info to build environment
index b009bbc715d1bd27943b46c565b80189b3d2fe82..5e245ad8eda55edb73926c4a0559b472a41b0de8 100644 (file)
@@ -1,6 +1,6 @@
 .\" Man page for e2-ls-project
 .\"
-.\" (c)2007-2016 emlix GmbH
+.\" (c)2007-2017 emlix GmbH
 .\"
 .TH e2-ls-project 1 "@VERSION@"
 
@@ -8,23 +8,23 @@
 e2-ls-project \- show project information of an e2factory project
 
 .SH SYNOPSIS
-e2-ls-project [<option>]...  [<result> ]
+e2-ls-project [<option> ...]  [<result> ...]
 
 .SH DESCRIPTION
 \fBe2-ls-project\fR is part of the e2factory commandline tools.
-.br
 \fBe2-ls-project\fR displays the configuration and components of the
 current e2factory project.
 
-If <result> is given, reduce output to that result and all results it depends on.
+With no argument, the default results and dependencies are selected.
+If <result> is given, <result> and dependencies are selected instead.
 
 .SH RETURN VALUE
-Normally, exit status is 0. On error, it is non-zero.
+Normal exit status is 0. On error, it is non-zero.
 
 .SH OPTIONS
 .TP
 .BR \-\-all
-Show all sources and results, even if not currently used by the project.
+Select all results, sources, licences and chroot groups of the project.
 .TP
 .BR \-\-dot
 Generate graph for processing with graphviz, see dot(1).
@@ -41,6 +41,10 @@ Also show chroot groups.
 .BR \-\-env
 Also show env variables.
 .TP
+.BR \-\-unused
+Show unused results, sources, licences and chroot groups with respect to default
+results and arguments.
+.TP
 For further global options, see \fBe2factory\fR(1).
 .SH EXAMPLES
 Generate a graph and convert it to pdf.
@@ -51,6 +55,3 @@ e2-ls-project --dot | dot -Tpdf > project.pdf
 
 .SH SEE ALSO
 .BR e2factory (1)
-
-.SH COPYRIGHT
-(c)2007-2016 emlix GmbH
index 9c4ef8b700e6d4e708e1107889b7183ea4dd92b7..dd65a0b522e7f482cf94ef6e5a888bc32c3178d1 100644 (file)
@@ -1,7 +1,7 @@
 --- e2-ls-project command
 -- @module local.e2-ls-project
 
--- Copyright (C) 2007-2016 emlix GmbH, see file AUTHORS
+-- Copyright (C) 2007-2017 emlix GmbH, see file AUTHORS
 --
 -- This file is part of e2factory, the emlix embedded build system.
 -- For more information see http://www.e2factory.org
@@ -31,6 +31,59 @@ local project = require("project")
 local result = require("result")
 local source = require("source")
 
+--- Shows unused results, sources, licences, and chroot groups.
+-- @param results Vector of used result names.
+-- @param chrootgroups Vector of used chroot group names.
+-- @param sources Vector of used source names.
+-- @param licences Vector of used licence names.
+-- @return Always returns true.
+-- @raise Assert
+local function show_unused(results, chrootgroups, sources, licences)
+    assertIsTable(results)
+    assertIsTable(chrootgroups)
+    assertIsTable(sources)
+    assertIsTable(licences)
+
+    --- Returns all names from all_dict that are not found in seen_vec. Name
+    -- must be a string.
+    -- @param all_dict Dictionary filled with (name, ignored type) pairs
+    -- @param seen_vec Vector filled with (ignored number, name) pairs
+    -- @return Sorted vector with names.
+    local function subtract(all_dict, seen_vec)
+        local seen = {}
+        local ret = {}
+
+        for _,name in ipairs(seen_vec) do
+            assertIsString(name)
+            seen[name] = true
+        end
+
+        for name,_ in pairs(all_dict) do
+            assertIsString(name)
+            if not seen[name] then
+                table.insert(ret, name)
+            end
+        end
+
+        table.sort(ret)
+        return ret
+    end
+
+    console.infof("unused results: %s\n",
+        table.concat(subtract(result.results, results), " "))
+
+    console.infof("unused sources: %s\n",
+        table.concat(subtract(source.sources, sources), " "))
+
+    console.infof("unused licences: %s\n",
+        table.concat(subtract(licence.licences, licences), " "))
+
+    console.infof("unused chroot groups: %s\n",
+        table.concat(subtract(chroot.groups_byname, chrootgroups), " "))
+
+    return true
+end
+
 --- e2 ls-project entry point.
 -- @param arg Arguments.
 -- @return Always true.
@@ -53,6 +106,7 @@ local function e2_ls_project(arg)
     e2option.flag("all", "show unused results and sources, too")
     e2option.flag("chroot", "show chroot groups as well")
     e2option.flag("env", "show environment vars as well")
+    e2option.flag("unused", "show unused results, sources, licences and chroot groups")
 
     local opts, arguments = e2option.parse(arg)
     if not opts then
@@ -157,6 +211,10 @@ local function e2_ls_project(arg)
     end
     table.sort(licences)
 
+    if opts.unused then
+        return show_unused(results, chrootgroups, sources, licences)
+    end
+
     local function pempty(s1, s2, s3)
         console.infof("   %s  %s  %s\n", s1, s2, s3)
     end