[Genabel-commits] r1561 - pkg/GenABEL-general/scripts
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jan 26 17:06:16 CET 2014
Author: lckarssen
Date: 2014-01-26 17:06:16 +0100 (Sun, 26 Jan 2014)
New Revision: 1561
Added:
pkg/GenABEL-general/scripts/getdeps.awk
Log:
Added an AWK script to the set of distribution-preparation scripts in pkg/GenABEL_scripts.
This script extracts the dependencies (both "Depends" and "Suggests")
of a package based on the DESCRIPTION file and outputs them as a
comma-separated list and enclosed in quotes, so that they can easily
be fed to install.packages().
Its intended use is for the makedistrib_* scripts, where 'R CMD
check' wants all dependencies and suggestions installed.
Added: pkg/GenABEL-general/scripts/getdeps.awk
===================================================================
--- pkg/GenABEL-general/scripts/getdeps.awk (rev 0)
+++ pkg/GenABEL-general/scripts/getdeps.awk 2014-01-26 16:06:16 UTC (rev 1561)
@@ -0,0 +1,84 @@
+#!/usr/bin/gawk -f
+#
+# This script extracts the dependencies of an R package from the
+# description. It treats 'suggested' packages as required as well,
+# because that's how the --as-cran checks behave as well.
+# NOTE: This script ignores version numbers of packages!
+
+BEGIN{
+ FS=","
+ requirements = 0 # If 1: we have hit a line where a
+ # list of required/suggested packages
+ # starts
+ continued = 0 # If 1: we are continuing the list of
+ # required/suggested packages
+ pkgs = "" # Variable that will contain our list
+ # of packages.
+}
+
+
+$1 ~ "Depends" || $1 ~ "Suggests" {
+ requirements = 1
+}
+
+
+$1 ~ /^ / {
+ # If a line starts with a space it's a continuation of the
+ # previous heading.
+ continued = 1
+}
+
+
+$1 !~ "Depends" && $1 !~ "Suggests" && continued == 0 {
+ # If we're not on a continued line and we don't have the two
+ # keywords in the first field, this line doesn't contain a
+ # requirement.
+ requirements = 0
+}
+
+
+{
+ if (requirements || (requirements && continued)) {
+ # We're on a line with requirements or a continuation of such
+ # a line.
+ if ($1 ~ "Depends" || $1 ~ "Suggests") {
+ # Remove the words Depends: and Suggests: from the first
+ # field, they're not package names
+ gsub("Depends:", "", $1)
+ gsub("Suggests:", "", $1)
+ }
+
+ for (i = 1; i <= NF; i++) {
+ # Go over all
+ gsub(/ /, "", $i) # Remove spaces in the field
+ gsub(/\(.*\)/, "", $i)
+
+ if (i == NF) {
+ # Remove the end-of-line (carriage return) from the
+ # last field. Otherwise that character ends up in the
+ # pkgs variable as well, so the contents of pkgs gets
+ # overwritten every time.
+ gsub("\r", "", $NF)
+ }
+
+ if ($i != "" && $i != "R") {
+ # If what is left of the field is not the empty
+ # string, we add that text to the list of packages.
+ if (pkgs == "") {
+ # Don't add a comma if this is the first package
+ # in the list
+ pkgs = "\"" $i "\""
+ } else {
+ pkgs = pkgs ",\"" $i "\""
+ }
+ }
+ } # End of for-loop over all fields.
+ continued = 0 # Always reset 'continued'
+ } # End of if statement that checks whether we are looking at requirements
+}
+
+
+END {
+ # Print the entire list of required packages.
+ print pkgs
+}
Property changes on: pkg/GenABEL-general/scripts/getdeps.awk
___________________________________________________________________
Added: svn:executable
+ *
More information about the Genabel-commits
mailing list