After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 734630 - make fails on OSX due to sed
make fails on OSX due to sed
Status: RESOLVED FIXED
Product: libsecret
Classification: Other
Component: General
unspecified
Other Mac OS
: Normal normal
: ---
Assigned To: libsecret maintainer(s)
libsecret maintainer(s)
Depends on:
Blocks: 774453
 
 
Reported: 2014-08-11 21:05 UTC by Richard Dowinton
Modified: 2018-03-31 07:31 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
build: Use $-quoted string to escape newline (1.23 KB, patch)
2016-02-17 05:59 UTC, Philip Chimento
none Details | Review
build: Make DBus code generation more portable (1.61 KB, patch)
2018-03-30 15:36 UTC, Daiki Ueno
committed Details | Review

Description Richard Dowinton 2014-08-11 21:05:56 UTC
make fails on OSX on the following error:

sed -e '1i\
	#define GLIB_DISABLE_DEPRECATION_WARNINGS' \
		-e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
		-e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
		temp-dbus-generated.c > secret-dbus-generated.c
sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
		temp-dbus-generated.h > secret-dbus-generated.h
sed: 1: "1i#define GLIB_DISABLE_ ...": command i expects \ followed by text

This is due to OSX using a BSD version of sed, which in this case seems to strip the backslash after i. The workaround I'm using is to use GNU sed instead, but ideally it would be better to change this to something compatible with both BSD and GNU sed.
Comment 1 Stef Walter 2014-08-12 06:06:12 UTC

*** This bug has been marked as a duplicate of bug 720087 ***
Comment 2 Stef Walter 2014-08-12 06:07:33 UTC
Oh sorry, I thought this was about 'sed -i' which is also non-portable. 

In any case a non-intrusive patch would be welcome.
Comment 3 Andrew Janke 2015-10-19 16:08:05 UTC
I think the issue isn't that BSD sed itself is stripping the backslash. It's that the backslash and newline inside that '...' aren't there in the first place by the time it gets to sed. But the GNU version of sed is happy without them.

$ echo foo | sed -e "1i#whatever"
sed: 1: "1i#whatever
": command i expects \ followed by text
$ echo foo | gsed -e "1i#whatever"
#whatever
foo

The problem looks like that the backslashes at the end of the lines are being processed by the shell before it calls sed.

I can't figure out how to get an arrangement of backslashes in the Makefile command such that the argument to that first -e will contain a literal backslash followed by a literal newline. Make needs the backslash to be the last thing on the line for a multi-line command, but it doesn't consume the backslash either. So I end up with too many or too few backslashes, or a quoting syntax error.

Here's a workaround that just avoids the `i` issue.

secret-dbus-generated.c: temp-dbus-generated.c Makefile.am
	$(AM_V_GEN) echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS' > secret-dbus-generated.c \
		&& sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
		-e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
		temp-dbus-generated.c >> secret-dbus-generated.c


But look: your ./configure script is already detecting gsed.

eilonwy% grep gsed config.log
configure:5957: result: /usr/local/bin/gsed
ac_cv_path_SED=/usr/local/bin/gsed
SED='/usr/local/bin/gsed'
eilonwy%

Maybe you just need to use the detected "$(SED)" instead of literal plain "sed" in your Makefile.
Comment 4 Andrew Janke 2015-10-19 16:44:46 UTC
Here's a patch. This was enough to get it building on OS X 10.9.5 for me. (You need to re-run automake and autoconf after applying this patch.)

diff --git a/libsecret/Makefile.am b/libsecret/Makefile.am
index 0601460..4f5a164 100644
--- a/libsecret/Makefile.am
+++ b/libsecret/Makefile.am
@@ -89,13 +89,13 @@ temp-dbus-generated.c: $(DBUS_XML_DEFINITIONS) Makefile.am
 	$(AM_V_GEN) gdbus-codegen --interface-prefix org.freedesktop.Secret. \
 		--generate-c-code temp-dbus-generated --c-namespace SecretGen $<
 secret-dbus-generated.c: temp-dbus-generated.c Makefile.am
-	$(AM_V_GEN) sed -e '1i\
+	$(AM_V_GEN) $(SED) -e '1i\
 	#define GLIB_DISABLE_DEPRECATION_WARNINGS' \
 		-e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
 		-e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
 		temp-dbus-generated.c > secret-dbus-generated.c
 secret-dbus-generated.h: temp-dbus-generated.c Makefile.am
-	$(AM_V_GEN) sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
+	$(AM_V_GEN) $(SED) -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
 		temp-dbus-generated.h > secret-dbus-generated.h
 
 libsecret/secret-enum-types.h: libsecret/secret-enum-types.h.template $(libsecret_HEADS)
Comment 5 Philip Chimento 2016-02-17 05:59:01 UTC
Using a $-quoted string makes BSD sed happy as well. Here's a patch.
Comment 6 Philip Chimento 2016-02-17 05:59:27 UTC
Created attachment 321461 [details] [review]
build: Use $-quoted string to escape newline

BSD sed doesn't like escaping a literal newline character with a
backslash. Instead, use a $-quoted string to escape the newline as \n.
Comment 7 Philip Chimento 2017-05-21 17:56:14 UTC
Anyone have an objection to this patch? If not, I'd like to commit it.
Comment 8 Stef Walter 2017-05-22 09:37:45 UTC
Thanks. Merged into git master.

Attachment 321461 [details] pushed as 4d7b190 - build: Use $-quoted string to escape newline
Comment 9 Antoine Jacoutot 2018-03-29 20:25:13 UTC
Hi.

I am seeing a regression with this.

Using GNU sed 4.2.2:
gsed -e $'1i\\\n#define GLIB_DISABLE_DEPRECATION_WARNINGS' \
        -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
        -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
        temp-dbus-generated.c > secret-dbus-generated.c
gsed: -e expression #1, char 2: unknown command: `1'

Using BSD sed (from OpenBSD):
sed -e $'1i\\\n#define GLIB_DISABLE_DEPRECATION_WARNINGS' \
        -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
        -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
        temp-dbus-generated.c > secret-dbus-generated.c
sed: 1: "$1i\\\n#define GLIB_DIS ...: invalid command code 1
Comment 10 Philip Chimento 2018-03-30 04:52:51 UTC
Could it be your shell does not understand $-quoted strings? It looks like the $ is getting passed into sed.
Comment 11 Daiki Ueno 2018-03-30 06:24:13 UTC
I thought that $-quoted strings were Bash extension for gettext integration:
https://www.gnu.org/software/gettext/manual/html_node/bash.html

Given that this is only used for inserting a single line, how about just calling echo, something like:

$(AM_V_GEN) { echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS'; \
              sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
                  -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
                  temp-dbus-generated.c } > secret-dbus-generated.c
Comment 12 Antoine Jacoutot 2018-03-30 07:18:25 UTC
(In reply to Daiki Ueno from comment #11)
> I thought that $-quoted strings were Bash extension for gettext integration:
> https://www.gnu.org/software/gettext/manual/html_node/bash.html
> 
> Given that this is only used for inserting a single line, how about just
> calling echo, something like:
> 
> $(AM_V_GEN) { echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS'; \
>               sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
>                   -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
>                   temp-dbus-generated.c } > secret-dbus-generated.c

Works for me :-)

One typo though, there's a missing ';' after temp-dbus-generated.c.
i.e.
$(AM_V_GEN) { echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS'; \
              sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \
                  -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \
                  temp-dbus-generated.c; } > secret-dbus-generated.c
Comment 13 Daiki Ueno 2018-03-30 15:36:12 UTC
Created attachment 370348 [details] [review]
build: Make DBus code generation more portable

The $'...' quoting syntax is a Bash extension and might not be
available in other Bourne shell compatible shells:
https://www.gnu.org/software/bash/manual/html_node/Major-Differences-From-The-Bourne-Shell.html#Major-Differences-From-The-Bourne-Shell
Comment 14 Philip Chimento 2018-03-31 03:23:12 UTC
TIL that $'' and $"" are seemingly totally unrelated...
Comment 15 Daiki Ueno 2018-03-31 05:49:22 UTC
Yeah, my bad; although $'' is also listed in the link quoted in comment 13.
Comment 16 Antoine Jacoutot 2018-03-31 06:55:08 UTC
(In reply to Daiki Ueno from comment #13)
> Created attachment 370348 [details] [review] [review]
> build: Make DBus code generation more portable
> 
> The $'...' quoting syntax is a Bash extension and might not be
> available in other Bourne shell compatible shells:
> https://www.gnu.org/software/bash/manual/html_node/Major-Differences-From-
> The-Bourne-Shell.html#Major-Differences-From-The-Bourne-Shell

Thanks, applied and working.
Comment 17 Daiki Ueno 2018-03-31 07:31:20 UTC
Anyway, I am pushing this.  I am also wondering if this GLIB_DISABLE_DEPRECATION_WARNINGS setting is still needed; it seems a bit strange that the glib-generated code requires it to compile...

Attachment 370348 [details] pushed as a7f2efc - build: Make DBus code generation more portable