Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

[minor] harden config/Makefile against '#' in PREFIX#1214

Merged
gasche merged 1 commit intoocaml:trunkfromgasche:escape-Makefile-injections
Jul 23, 2017

Conversation

gasche
Copy link
Member

The opam-compiler-conf script will generate an opam switch name
(and thus a directory name) from the name of the current git
branch. Branches named 'PR#1234-foo-bar' would have the ./configure
script generate a config/Makefile with the lines

PREFIX=~/.opam/4.06.0+local-git-PR#1234-foo-barBINDIR=$(PREFIX)/binBYTERUN=$(BINDIR)/ocamlrunLIBDIR=$(PREFIX)/lib/ocaml

The '#' in the first line parses as the start of a comment, so
the second part is ignored and the build system would then install
in ~/.opam/4.06.0+local-git-PR instead.

After this change, config/Makefile starts with:

# generated by ./configure --prefix ~/.opam/4.06.0+local-git-PR#1234-foo-barCONFIGURE_ARGS=--prefix ~/.opam/4.06.0+local-git-PR\#1234-foo-barPREFIX=~/.opam/4.06.0+local-git-PR\#1234-foo-bar

Copy link
Member

@dra27dra27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

With the two changes I suggest, I get an identical config/Makefile with the merge base.

configure Outdated
echo "PROGRAMS_MAN_SECTION=$programs_man_section" >> Makefile
echo "LIBRARIES_MAN_SECTION=$libraries_man_section" >> Makefile
config "PROGRAMS_MAN_SECTION=$programs_man_section"
config "LIBRARIES_MAN_SECTION=$libraries_man_section"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should be:

config PROGRAMS_MAN_SECTION "$programs_man_section"config LIBRARIES_MAN_SECTION "$libraries_man_section"

configure Outdated
# $(PREFIX) is also injected in C code where this escape is invalid
# -- see the definition of the OCAML_STDLIB_DIR macro below.

echo $1=$2 | sed 's/\#/\\#/g' >> Makefile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The$1=$2 needs double-quoting or spaces are being trimmed. It's irrelevant in most cases, but it removes the space at the end ofPACKLD which, amongst other things, I think is why the lib-dynlink-native test is failing.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So I tried to useecho $1=\"$2\" here but I don't like the fact that it makes the result very different from the previousconfig/Makefile where variables are not quoted. In the next iteration (I'll push now), I used"$partialld -o\\ \$(EMPTY)" instead as some other variables were already doing, does that sound reasonable to you?

If I diff the config/Makefile before and after the change, the differences are:

  • CPPFLAGS had a trailing space that is now gone (I think this is correct, it comes from the space before the empty variableinternal_cppflags)
  • BYTECCLIBS has 18 trailing spaces that are now gone (that again seems correct)
  • NATIVECCLIBS had two spaces instead of one in the middle
  • andPACKLD that needs a fix as you pointed out

Sorry, I should have made this comparison earlier.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I meant"$1=$2" which results in an identical Makefile for me?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

aah, sorry. Should I keep the $(EMPTY) trick for extra safety?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

So I used"$1=$2" and indeed the result are identical, which is good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yes - the$(EMPTY) trick is much better than what was there before. What happened was that trimming the space meant you escaped the newline, so it read the following line into PACKLD (creating garbage). If the space after the-o is critical (it is for some C compilers), then it should be obviously critical and$(EMPTY) is a good way of doing that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

dra@bean:~/ocaml$ ./ocamlc.opt -config | fgrep native_packnative_pack_linker: ld -r -o IFLEXDIR=

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

NATIVECCLIBS gets two spaces because$mathlib is empty (comes via$cclibs);BYTECCLIBS gets 18 spaces because of the "bad" line continuation. If it's changed to:

echo"BYTECCLIBS=$cclibs$dllib$curseslibs$pthread_link" \"$instrumented_runtime_libs">> Makefile

then it should work, however, none of them causes a problem as all those spaces get compacted when make loads config/Makefile so I'm not sure I'd change any of it (as much as I like perfectly generated files!)

@dra27
Copy link
Member

I like this change, but I wonder whether@shindere would prefer this kind of alteration post-autoconf (or considered with autoconf?)

@gaschegascheforce-pushed theescape-Makefile-injections branch 3 times, most recently from6b6c8f4 toe90a72aCompareJuly 7, 2017 12:17
@gasche
Copy link
MemberAuthor

gasche commentedJul 7, 2017
edited by damiendoligez
Loading

All checks now pass. Given that the change is not very invasive (it does not affect the structure of the code in any way), and that it fixes a bug for me (git branch names with a# +opam-compiler-conf), I would be in favor of not waiting for autoconf, but I won't self-merge.

P.S.: I forgot to update the Changes entry, will do.

@gasche
Copy link
MemberAuthor

(@dra27 do you mean to "approve" the PR? We are now in required-review mode. )

@dra27
Copy link
Member

I'm happy to approve it, but I would like Sébastien to have a chance to comment!

@shindere
Copy link
Contributor

shindere commentedJul 11, 2017 via email

David Allsopp (2017/07/07 09:53 +0000):
I like this change, but I wonder whether@shindere would prefer this kind of alteration post-autoconf (or considered with autoconf?)
@dra27: are you talking about the "config" function?In that case: I think it will simply go away with au"toconf. What willhappen is that there will be a config/Makefile.in (or Makefile.config.inin the toplevel source tree) with lines likePROGRAMS_MAN_SECTION="@@programs_man_section@@"Running configure a similarly named file (without the .in suffix) wherethe @@variables@@ are replaced by the values computed by configure.

Copy link
Member

@damiendoligezdamiendoligez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

LGTM and@shindere has not expressed any opposition

configure Outdated
# $(PREFIX) is also injected in C code where this escape is invalid
# -- see the definition of the OCAML_STDLIB_DIR macro below.

echo "$1=$2" | sed 's/\#/\\#/g' >> Makefile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You don't need the first\.

@gaschegascheforce-pushed theescape-Makefile-injections branch frombfb25a2 toba85206CompareJuly 18, 2017 12:35
@gasche
Copy link
MemberAuthor

Thanks, rebased. Someone (or myself) can merge if the CI passes again.

@gaschegascheforce-pushed theescape-Makefile-injections branch fromba85206 to890c8bbCompareJuly 23, 2017 06:16
The opam-compiler-conf script will generate an opam switch name(and thus a directory name) from the name of the current gitbranch. Branches named 'PR#1234-foo-bar' would have the ./configurescript generate a config/Makefile with the lines    PREFIX=~/.opam/4.06.0+local-git-PR#1234-foo-bar    BINDIR=$(PREFIX)/bin    BYTERUN=$(BINDIR)/ocamlrun    LIBDIR=$(PREFIX)/lib/ocamlThe '#' in the first line parses as the start of a comment, sothe second part is ignored and the build system would then installin ~/.opam/4.06.0+local-git-PR instead.After this change, config/Makefile starts with:    # generated by ./configure --prefix ~/.opam/4.06.0+local-git-PR#1234-foo-bar    CONFIGURE_ARGS=--prefix ~/.opam/4.06.0+local-git-PR\ocaml#1234-foo-bar    PREFIX=~/.opam/4.06.0+local-git-PR\ocaml#1234-foo-bar
@gaschegasche merged commitc43ebef intoocaml:trunkJul 23, 2017
stedolan pushed a commit to stedolan/ocaml that referenced this pull requestMar 21, 2023
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull requestJan 12, 2024
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dra27dra27dra27 left review comments

@damiendoligezdamiendoligezdamiendoligez approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@gasche@dra27@shindere@damiendoligez

[8]ページ先頭

©2009-2025 Movatter.jp