anestisb / android-prepare-vendor

Set of scripts to automate AOSP compatible vendor blobs generation from factory images
347 stars 156 forks source link

syntax error, unexpected QQSTRING_START with jq 1.3 from Ubuntu 14.04 repos #166

Open asnelling opened 5 years ago

asnelling commented 5 years ago

The scripts, in my case ./execute-all.sh, produce the following error upon invoking jq version 1.3:

error: syntax error, unexpected QQSTRING_START, expecting $end
."supported-apis"[]
 ^
1 compile error
./execute-all.sh: line 290: supportedAPIs[@]: unbound variable

Sure, the latest release of jq is 1.6, but version 1.3 ships with the official repositories in the environment recommended by the Android team: Ubuntu LTS 14.04 - Trusty

...and I didn't notice ./hostTools/Linux/bin/jq sitting in this repo until I already started digging in.

Seems like there was some confusion regarding which is the correct syntax (see stedolan/jq#273), but it seems that wrapping the object accessor is at least more correct and may save some people valuable debugging time when they start to build the AOSP tree.

Attached is a shell script to reproduce the error when executed in an ubuntu:14.04 Docker image.

asnelling commented 5 years ago

From FAQ - General Questions in the jq repo:

𝑸: How can I access the value of a key with hyphens or $ or other special characters in it? Why does .a.["$"] produce a syntax error?

A: The basic form for accessing the value of a key is .["KEYNAME"] where "KEYNAME" is any valid JSON string, but recent versions of jq also allow ."KEYNAME".

So I imagine that, given a hyphenated key, such as "supported-apis", this syntax below is not compatible with the version 1.3

https://github.com/anestisb/android-prepare-vendor/blob/e853d17c89f6962d3fd6f408db8576e6b445f643/scripts/common.sh#L81

Whereas this bracketed syntax is still valid and should work with previous versions of jq:

$ jq -r ".[\"$query\"] | .[]" "$conf_file"

# which after parameter expansion will become:
$ jq -r .["supported-apis"] | .[]  ./file...