Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make: introduce __SHORT_FILE__ define #2969

Merged
merged 1 commit into from
May 27, 2015

Conversation

kaspar030
Copy link
Contributor

While fiddling with the logging, I realized that currently the RIOT make system uses absolute paths for filenames, causing __FILE__ to contain the full path.

That is longer than necessary and also exposes the build system (the messages contain e.g., "/home/kaspar/src/riot.bullshit/*"...), it makes it a lot harder to get reproducable builds built on different build systems.

So I propose the define __SHORT_FILE__ that only contains the path starting from $(RIOTBASE).
I tried redefining __FILE__, but gcc complains about that.

Opinions?

@kaspar030 kaspar030 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer labels May 11, 2015
@OlegHahm
Copy link
Member

The idea sounds good, but the patch some doesn't work for me. It's still showing the full path.

@kaspar030
Copy link
Contributor Author

Well, did you use __SHORT_FILE__ instead of __FILE__? Can you check whether building with QUIET=0 shows the correct define?

I'm replacing $(RIOTBASE)/, maybe this breaks if $(RIOTBASE) already contains a trailing "/"?

@OlegHahm
Copy link
Member

Nevermind, I misinterpreted the purpose of this PR. I thought it should affect the output of the Make system itself.

@@ -57,10 +57,12 @@ CXXFLAGS = $(filter-out $(CXXUWFLAGS), $(CFLAGS)) $(CXXEXFLAGS)
# compile and generate dependency info

$(OBJC): $(BINDIR)$(MODULE)/%.o: %.c
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -MD -MP -c -o $@ $(abspath $<)
$(AD)$(CC) -D__SHORT_FILE__=\"$(subst $(RIOTBASE)/,,$(abspath $<))\" \
Copy link
Member

Choose a reason for hiding this comment

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

I think that a more robust way would be to do $(patsubst $(RIOTBASE)/%,,$(abspath $<))

@jnohlgard
Copy link
Member

I like this, I didn't like the output from the debug messages with filenames because of the length.

@kaspar030
Copy link
Contributor Author

@gebart changed to patsubst. Why do you think it's more robust?

@cgundogan
Copy link
Member

I also like this idea. What about additionally introducing something like __FILE_NAME__ which only extracts the non-directory part? So e.g. /home/cnk/RIOT/examples/rpl_udp/udp.c => udp.c?
Could be done easily with the $(notdir names…) function [1].

Opinions?

[1] https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html

@jnohlgard
Copy link
Member

@kaspar030

changed to patsubst. Why do you think it's more robust?

Because with patsubst you can make sure that you are only replacing the prefix of the filename, in case RIOTBASE is set to something really short, and that exists in the tree, like /sys/net (though I admit that example is quite stupid).

I'm replacing $(RIOTBASE)/, maybe this breaks if $(RIOTBASE) already contains a trailing "/"?

You don't have to worry about that since when you run abspath on the filename any multiple slashes will be replaced by single slashes and any /./ and /../ will be followed and eliminated from the path.

@cgundogan
Copy link
Member

How should symlinks be handled? abspath e.g. does not resolve symlinks, while realpath does. A matter of taste probably.

@jnohlgard
Copy link
Member

@cgundogan

How should symlinks be handled? abspath e.g. does not resolve symlinks, while realpath does. A matter of taste probably.

I would argue that if you have set RIOTBASE to a symlink, then you probably want to use the symlink to refer to that path and not the real path name.

@cgundogan
Copy link
Member

@gebart completely valid and I agree with you. I was just giving food for thought (:

@kaspar030
Copy link
Contributor Author

Is it me or did they disable the button to re-start a failed travis job?

@OlegHahm
Copy link
Member

It's still there. Are you logged in?

@kaspar030
Copy link
Contributor Author

Ah, no, I wasn't. Thx.

@kaspar030
Copy link
Contributor Author

I don't quite like that "short file" and "file name" don't really show what's the exact difference. "short file" alone made sense together with "file", but like this... Do you have ideas for better names?

@cgundogan
Copy link
Member

What about __RELATIVE_FILE__ and __SHORT_FILE__. With the latter being
the former __FILE_NAME_?
Am 12.05.2015 15:48 schrieb "Kaspar Schleiser" [email protected]:

I don't quite like that "short file" and "file name" don't really show
what's the exact difference. "short file" alone made sense together with
"file", but like this... Do you have ideas for better names?


Reply to this email directly or view it on GitHub
#2969 (comment).

@jnohlgard
Copy link
Member

@cgundogan How about the other way around, use FILE as a prefix:

__FILE_RELATIVE__
__FILE_NAME__

or, instead of __FILE_NAME__:
__FILE_BASENAME__ (to associate with basename in the shell)
or __FILE_NOPATH__

@kaspar030
Copy link
Contributor Author

I like __FILE_RELATIVE__ and __FILE_NOPATH__ best so far.

@cgundogan
Copy link
Member

+1 to FILE_RELATIVE and FILE_NOPATH
Am 13.05.2015 10:50 schrieb "Kaspar Schleiser" [email protected]:

I like FILE_RELATIVE and FILE_NOPATH best so far.


Reply to this email directly or view it on GitHub
#2969 (comment).

@Kijewski
Copy link
Contributor

I strongly vote against introducing new double underscores now that we eliminated them from the header file guards ...

@jnohlgard
Copy link
Member

@Kijewski you're right.
Is it too long to have RIOT_FILE_NOPATH and RIOT_FILE_RELATIVE?

@Kijewski
Copy link
Contributor

@gebart, I think RIOT_FILE_NOPATH and RIOT_FILE_RELATIVE are readable and self-explanatory. 👍

@OlegHahm OlegHahm added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label May 17, 2015
@kaspar030 kaspar030 force-pushed the make_short_filename_define branch from b344881 to aed4be3 Compare May 26, 2015 17:40
@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels May 26, 2015
@kaspar030 kaspar030 removed the Discussion: RFC The issue/PR is used as a discussion starting point about the item of the issue/PR label May 26, 2015
@kaspar030
Copy link
Contributor Author

Someone dares to say ACK and merge?

@jnohlgard
Copy link
Member

Untested ACK (from my phone, can't run it)

@jnohlgard
Copy link
Member

Go if Travis is green

jnohlgard pushed a commit that referenced this pull request May 27, 2015
@jnohlgard jnohlgard merged commit b288457 into RIOT-OS:master May 27, 2015
@kaspar030 kaspar030 deleted the make_short_filename_define branch February 7, 2017 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants