How to define AM_CONDITIONAL and AC_DEFINE based on PKG_CHECK_MODULES result? - sh

I am trying to write a configure.ac file to do these tasks:
The configure script should accept a --with-libuv parameter.
A variable with_libuv should be set to either yes, no or check (with check being the default value when nothing was passed on the command line).
When with_libuv == "yes" a mandatory PKG_CHECK_MODULES check for libuv >= 1.9.0 should be done and HAVE_LIBUV = 1 should be set on success (On error configure should abort).
When with_libuv == "no" nothing should be checked,
When with_libuv == "false" an optional PKG_CHECK_MODULES check (for the same library as in 3.) should be done and HAVE_LIBUV should be set to either 0 or 1 accordingly.
If with_libuv != "no" && HAVE_LIBUV == 1 AC_DEFINE should set -DUSE_LIBUV and AM_CONDITIONAL should set USE_LIBUV as a conditional for automake.
If not with_libuv != "no" && HAVE_LIBUV == 1 the preprocessor directive should not be set and the AM_CONDITIONAL should be set to 0.
I have figured out how to do steps 1-5, but I am struggeling with 6 and 7.
Here is my current attempt:
AC_INIT(
[mumble-pluginbot-plusplus],
[0.5],
[https://github.com/promi/mumble-pluginbot-plusplus/issues],
[],
[https://github.com/promi/mumble-pluginbot-plusplus])
AC_CONFIG_MACRO_DIR([m4])
AM_INIT_AUTOMAKE([foreign])
AM_SILENT_RULES([yes])
AC_PROG_CXX
LT_INIT
# Make sure that pkg-config is installed!
# The PKG_CHECK_MODULES macro prints a horrible error message when
# pkg-config is not installed at autogen time.
#
# It is also required when the first PKG_CHECK_MODULES is inside a conditional
PKG_PROG_PKG_CONFIG
PKG_CHECK_MODULES(OPUS, [opus >= 1.1])
PKG_CHECK_MODULES(OPENSSL, [openssl])
PKG_CHECK_MODULES(PROTOBUF, [protobuf])
PKG_CHECK_MODULES(MPDCLIENT, [libmpdclient])
AC_ARG_WITH(
[libuv],
[AS_HELP_STRING([--with-libuv], [support efficient MPD status polling #<:#default=check#:>#])],
[],
[with_libuv=check])
# if --with-libuv -> it must be installed
# elseif --without-libuv -> do nothing
# else -> check whether it is installed
AS_CASE(
["$with_libuv"],
[yes], [PKG_CHECK_MODULES(UV, [libuv >= 1.9.0], [HAVE_LIBUV=1])],
[no], [],
[PKG_CHECK_MODULES(UV, [libuv >= 1.9.0], [HAVE_LIBUV=1], [HAVE_LIBUV=0])])
if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
AM_CONDITIONAL([USE_LIBUV], [1])
AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
else
AM_CONDITIONAL([USE_LIBUV], [0])
fi
#AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
The problematic part is this:
if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
AM_CONDITIONAL([USE_LIBUV], [1])
AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
else
AM_CONDITIONAL([USE_LIBUV], [0])
fi
Here is an excerpt from the configure output:
checking pkg-config is at least version 0.9.0... yes
checking for OPUS... yes
checking for OPENSSL... yes
checking for PROTOBUF... yes
checking for MPDCLIENT... yes
checking for UV... yes
./configure: line 16467: test: x1: integer expression expected
./configure: line 16480: 0: command not found
checking that generated files are newer than configure... done
How can I implement steps 6 and 7 in a way that actually works?

You aren't aborting when yes fails (step 3). AM_CONDITIONAL should always be run. Step 6 says -DUSE_LIBUV, but your existing code will add -DUSE_LIBUV=1 to DEFS. Portable shell scripting considers test -a broken, so you shouldn't be using that. Your no case is equivalent to the check (or false) case where the search fails.
AS_CASE(
["$with_libuv"],
[yes], [PKG_CHECK_MODULES(UV, [libuv >= 1.9.0], [HAVE_LIBUV=1],
[AC_MSG_ERROR("libuv >= 1.9.0 is not installed")])],
[no], [HAVE_LIBUV=0],
[PKG_CHECK_MODULES(UV, [libuv >= 1.9.0], [HAVE_LIBUV=1],[HAVE_LIBUV=0])])
AS_IF([test "x$HAVE_LIBUV" = x1], [AC_DEFINE([USE_LIBUV])])
AM_CONDITIONAL([USE_LIBUV], [test "x$HAVE_LIBUV" = x1])

I think you should use = instead of -eq. The -eq is a relation between integers - the x1 isn't integer!
if test "$with_libuv" != no -a "x$HAVE_LIBUV" -eq x1; then
replace to
if test "$with_libuv" != no -a "x$HAVE_LIBUV" = x1; then

This should do the trick:
if test "$with_libuv" != no -a "x$HAVE_LIBUV" == x1; then
AC_DEFINE([USE_LIBUV], [1], [Define when libuv should be used.])
fi
AM_CONDITIONAL([USE_LIBUV], [test "$with_libuv" != no -a "x$HAVE_LIBUV" == x1])
It's a bit ugly, because the test is executed twice, but it seems to work ok.

Related

Snakemake workflow, ChildIOException or MissingInputException

I am trying to add a file renaming step in my current workflow to make it easier on some of the other users. What I want to do is take the contigs.fasta file from a spades assembly directory and rename it to include the sample name. (i.e foo_de_novo/contigs.fasta to foo_de_novo/foo.fasta)
here is my code... well currently.
configfile: "config.yaml"
import os
def is_file_empty(file_path):
""" Check if file is empty by confirming if its size is 0 bytes"""
# Check if singleton file exist and it is empty from bbrepair output
return os.path.exists(file_path) and os.stat(file_path).st_size == 0
rule all:
input:
expand("{sample}_de_novo/{sample}.fasta", sample = config["names"]),
rule fastp:
input:
r1 = lambda wildcards: config["sample_reads_r1"][wildcards.sample],
r2 = lambda wildcards: config["sample_reads_r2"][wildcards.sample]
output:
r1 = temp("clean/{sample}_r1.trim.fastq.gz"),
r2 = temp("clean/{sample}_r2.trim.fastq.gz")
shell:
"fastp --in1 {input.r1} --in2 {input.r2} --out1 {output.r1} --out2 {output.r2} --trim_front1 20 --trim_front2 20"
rule bbrepair:
input:
r1 = "clean/{sample}_r1.trim.fastq.gz",
r2 = "clean/{sample}_r2.trim.fastq.gz"
output:
r1 = temp("clean/{sample}_r1.fixed.fastq"),
r2 = temp("clean/{sample}_r2.fixed.fastq"),
singles = temp("clean/{sample}.singletons.fastq")
shell:
"repair.sh -Xmx10g in1={input.r1} in2={input.r2} out1={output.r1} out2={output.r2} outs={output.singles}"
rule spades:
input:
r1 = "clean/{sample}_r1.fixed.fastq",
r2 = "clean/{sample}_r2.fixed.fastq",
s = "clean/{sample}.singletons.fastq"
output:
directory("{sample}_de_novo")
run:
isempty = is_file_empty("clean/{sample}.singletons.fastq")
if isempty == "False":
shell("spades.py --careful --phred-offset 33 -1 {input.r1} -2 {input.r2} -s {input.singletons} -o {output}")
else:
shell("spades.py --careful --phred-offset 33 -1 {input.r1} -2 {input.r2} -o {output}")
rule rename_spades:
input:
"{sample}_de_novo/contigs.fasta"
output:
"{sample}_de_novo/{sample}.fasta"
shell:
"cp {input} {output}"
When I have it written like this I get the MissingInputError and when I change it to this.
rule rename_spades:
input:
"{sample}_de_novo"
output:
"{sample}_de_novo/{sample}.fasta"
shell:
"cp {input} {output}"
I get the ChildIOException
I feel I understand why snakemake is unhappy with both versions. The first one is becasue I don't explicitly output the "{sample}_de_novo/contigs.fasta" file. Its just one of several files spades outputs. And the other error is because it doesn't like how I am asking it to look into the directory. I however am at a loss on how to fix this.
Is there a way to ask snakmake to look into a directory for a file and then perform the task requested?
Thank you,
Sean
EDIT File Structure of Spades output
Sample_de_novo
|-corrected/
|-K21/
|-K33/
|-K55/
|-K77/
|-misc/
|-mismatch_corrector/
|-tmp/
|-assembly_graph.fastg
|-assembly_graph_with_scaffolds.gfa
|-before_rr.fasta
|-contigs.fasta
|-contigs.paths
|-dataset.info
|-input_dataset.ymal
|-params.txt
|-scaffolds.fasta
|-scaffolds.paths
|spades.log
Make {sample}_de_novo/contigs.fasta to be the output of spades and parse its path to get the directory that will be the argument to spades -o. Snakemake won't mind if there are other files created in addition to contigs.fasta. This should run --dry-run mode:
rule all:
input:
expand('{sample}_de_novo/{sample}.fasta', sample=['A', 'B']),
rule spades:
output:
fasta='{sample}_de_novo/contigs.fasta',
run:
outdir=os.path.dirname(output.fasta)
shell(f'spades ... -o {outdir}')
rule rename:
input:
fasta='{sample}_de_novo/contigs.fasta',
output:
fasta='{sample}_de_novo/{sample}.fasta',
shell:
r"""
mv {input.fasta} {output.fasta}
"""
Nope, spoke too soon. It didn't name the output directory correctly, so I moved it to the params and, now, finailly is working the way I wanted.
rule spades:
input:
r1 = "clean/{sample}_r1.fixed.fastq",
r2 = "clean/{sample}_r2.fixed.fastq",
s = "clean/{sample}.singletons.fastq"
output:
"{sample}_de_novo/contigs.fasta"
params:
outdir = directory("{sample}_de_novo/")
run:
isempty = is_file_empty("clean/{sample}.singletons.fastq")
if isempty == "False":
shell("spades.py --isolate --phred-offset 33 -1 {input.r1} -2 {input.r2} -s {input.singletons} -o {params.outdir}")
else:
shell("spades.py --isolate --phred-offset 33 -1 {input.r1} -2 {input.r2} -o {params.outdir}")
rule rename_spades:
input:
"{sample}_de_novo/contigs.fasta"
output:
"{sample}_de_novo/{sample}.fasta"
shell:
"cp {input} {output}"

In neovim, how do I get a file to open at the same line number I closed it at last time?

au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
This code is valid in vim. It is the syntax of vimscript. It can also work in neovim's configuration file init.vim. how can I achieve the same effect in init.lua?
Tested on 0.7.2, if not available, the version may be too low.
vim.api.nvim_create_autocmd("BufReadPost", {
pattern = {"*"},
callback = function()
if vim.fn.line("'\"") > 1 and vim.fn.line("'\"") <= vim.fn.line("$") then
vim.api.nvim_exec("normal! g'\"",false)
end
end
})

How to print terraform variable values?

I am learning terraform. I want to print values of variables in "plan" stage. So I found how to do it. seems I am doing something wrong here....
in variables.tf:....
variable "VMCount" {
description = "How many VMs do you want to start with (number)? default=1 max=5"
type = number
}
in main.tf
output "VMCount" {
value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}"
}
after that i run terraform plan and the condition seem to be working fine (it creates right num of VMs)
but the variable output is not coming. why?
$ terraform output
VMC = 56
that VMC is might be from some previous attempts ( I tried several things).
How to print the value of user entry (variable)?
Thank you.
I tested with this:
variable "VMCount" {
description = "How many VMs do you want to start with (number)? default=1 max=5"
type = number
}
output "VMCount" {
value = "${var.VMCount > 2 && var.VMCount < 6 ? var.VMCount : 2}"
}
and it works well.
Terraform will perform the following actions:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ VMCount = 4
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
VMCount = 4
PS C:\d\m\terraform\output-and-variable> terraform output
VMCount = 4
PS C:\d\m\terraform\output-and-variable> terraform apply
var.VMCount
How many VMs do you want to start with (number)? default=1 max=5
Enter a value: 8
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
Terraform will perform the following actions:
Plan: 0 to add, 0 to change, 0 to destroy.
Changes to Outputs:
~ VMCount = 4 -> 2
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
VMCount = 2
PS C:\d\m\terraform\output-and-variable> terraform output
VMCount = 2
PS C:\d\m\terraform\output-and-variable>
Could you check what outouts doyou have in state? VMC or VMCount?
As stated here in the terraform documentation:
Outputs are only rendered when Terraform applies your plan. Running terraform plan will not render outputs.

Attempt to call global function is nil, but function is not shown in debugger?

I am using Eclipse LDT for development, using the packaged Lua EE and Interpreter for Lua 5.2. I need to call the commandDatabase() method from my main method, though when I try, I receive the error:
"attempt to call global 'commandDatabase' (a nil value)".
I have looked up this error, and I am, as far as I can tell, defining methods in the right order.
Lua - attempt to call global 'contains' (a nil value)
When I view it in the debugger, the interpreter does not seem to find any methods I define between commandSystem and commandHelp. It shows each other function in the Variables area as e.g. ["commandSystem"] = function() but commandDatabase() does not appear
I have tried calling a wrapper method like so:
function commandDatabaseStep()
return commandDatabase()
end
... but this did not work either (same error)
The relevant code:
-- System command
function commandSystem()
...
end
-- Database command
function commandDatabase()
if arguments[2] == "no_arg1" then
print("The 'database' command must have at least one argument: [generate, wipe, dump, delete, get <system_name>]", true)
return 2
elseif arguments[2] == "generate" then
local file = io.open(database, "w+")
file:write("#ssmhub database")
file:close(file)
return 1
elseif arguments[2] == "dump" then
print("= DUMP START =")
for line in io.lines(database) do
print(line)
end
print("= DUMP END =")
return 1
-- 1+
elseif arguments[2] == "get" then
-- 2+
if isEmpty(arguments[3]) then
print("The 'database get' command must have a <name> parameter")
return 0
-- 2-
else -- 3+
local file = io.open(database, "r")
for line in io.lines(file) do -- 4+
local state = ""
local id = ""
local dividersFound = 0
line:gsub(".", function(c) -- 5+
if c == "|" then -- 6+
if dividersFound == 0 then -- 7+
state = state .. c
end -- 7-
if dividersFound == 1 then -- 8+
id = id .. c
end -- 8-
dividersFound = dividersFound + 1
end -- 6-
end) -- 5-
io.close(file)
end -- 4-
end -- 3-
else -- 9+
print("Illegal argument for command. Use 'help' for a list of commands and arguments.")
return 0
end -- 9-
end -- 2-
end -- 1-
function commandHelp()
...
end
-- Main
function main()
arguments = readProgramArguments()
commandArgument = arguments[1]
commandCompleteCode = 0
-- Process help and system commands
if commandArgument == "database" then
commandCompleteCode = commandDatabase()
end
end main()
As #luther pointed out, I had one-too-many end-s in commandDatabase.
This wasn't flagged in my IDE because I had not end-ed commandSystem, so commandSystem was nested inside of it.
To fix: add an end to commandSystem, and remove the end which I tagged '-- 1-'.

man: MANPATH environment variable list too long (manpath list too long)

When having excessively long MANPATH env-vars I end up in a problem with this error:
$> man <any command>
man: manpath list too long
To figure out when the manpath list is too long I created this small script:
#!/bin/bash
export MANPATH=
for i in $(seq 50 10000)
do
export MANPATH=/usr:$MANPATH
man -k gcc > /dev/null
[ $? -ne 0 ] && echo "$i ${#MANPATH}" && exit 0
done
and it seems like it breaks at ${#MANPATH} close to 500.
Also man -d does not give me any information I can use... :(
I have never heard (nor found) a limitation to the number of entries in env-vars (besides the maximum length of the environment variables, from which I am far from).
Are there any fixes for this? Preferably a non-root fix ;)
I am running Debian 9.6.
EDIT: This was reported upstream and fixed!
Based on manp.c starting at line 786:
else if (sscanf (bp, "MANDATORY_MANPATH %511s", key) == 1)
add_mandatory (key);
else if (sscanf (bp, "MANPATH_MAP %511s %511s",
key, cont) == 2)
add_manpath_map (key, cont);
else if ((c = sscanf (bp, "MANDB_MAP %511s %511s",
key, cont)) > 0)
add_mandb_map (key, cont, c, user);
else if ((c = sscanf (bp, "DEFINE %511s %511[^\n]",
key, cont)) > 0)
add_def (key, cont, c, user);
else if (sscanf (bp, "SECTION %511[^\n]", cont) == 1)
add_sections (cont, user);
else if (sscanf (bp, "SECTIONS %511[^\n]", cont) == 1)
/* Since I keep getting it wrong ... */
...
I'd say the threshold is 511 characters. Interestingly there's a comment in the stating this should be fixed.
/* TODO: would like a (limited) replacement for sscanf()
* here that allocates its own memory. At that point check
* everything that sprintf()s manpath et al!
*/
References
man-db, the on-line manual database
man-db git repo