Skip to content

Commit

Permalink
otp: Make sure filelib:find_source finds all sources
Browse files Browse the repository at this point in the history
Adjust eunit and public_key to place sources in the correct
folders during a release so that filelib:find_source can
find them.

Also adds a test that makes sure that we don't break this in
the future.

Closes erlang#5655
  • Loading branch information
garazdawi committed Feb 2, 2022
1 parent 0068092 commit a7ecc5b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/eunit/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ release_spec: opt
$(INSTALL_DIR) "$(RELSYSDIR)/ebin"
$(INSTALL_DATA) $(PARSE_TRANSFORM_BIN) $(OBJECTS) "$(RELSYSDIR)/ebin"
$(INSTALL_DIR) "$(RELSYSDIR)/src"
$(INSTALL_DATA) $(PARSE_TRANSFORM) $(SOURCES) "$(RELSYSDIR)/src"
$(INSTALL_DATA) $(PARSE_TRANSFORM) $(SOURCES) $(BEHAVIOUR_SOURCES) "$(RELSYSDIR)/src"
$(INSTALL_DATA) $(INTERNAL_HRL_FILES) "$(RELSYSDIR)/src"
$(INSTALL_DIR) "$(RELSYSDIR)/include"
$(INSTALL_DATA) $(INCLUDE_DELIVERABLES) "$(RELSYSDIR)/include"
Expand Down
8 changes: 5 additions & 3 deletions lib/public_key/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# public_key

asn1/*.asn1db
asn1/*.erl
asn1/*.hrl
src/*.asn1db
src/OTP-PUB-KEY.erl
src/OTP-PUB-KEY.hrl
src/PKCS-FRAME.erl
src/PKCS-FRAME.hrl
include/OTP-PUB-KEY.hrl
include/PKCS-FRAME.hrl
31 changes: 17 additions & 14 deletions lib/public_key/asn1/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
# %CopyrightEnd%
#

EGEN = ../src
ESRC = ../src

include $(ERL_TOP)/make/target.mk
include $(ERL_TOP)/make/$(TARGET)/otp.mk

Expand All @@ -39,28 +42,26 @@ RELSYSDIR = $(RELEASE_PATH)/lib/public_key-$(VSN)
.SUFFIXES: .asn1
.PRECIOUS: %.erl

INCLUDE = ../include
EBIN = ../ebin

ASN_TOP = OTP-PUB-KEY PKCS-FRAME
ASN_MODULES = PKIX1Explicit88 PKIX1Implicit88 PKIX1Algorithms88 \
PKIXAttributeCertificate PKCS-1 PKCS-3 PKCS-7 PKCS-8 PKCS-10 PKCS5v2-0 OTP-PKIX \
InformationFramework RFC5639 CMSAesRsaesOaep
ASN_ASNS = $(ASN_MODULES:%=%.asn1)
ASN_ERLS = $(ASN_TOP:%=%.erl)
ASN_ERLS = $(ASN_TOP:%=$(ESRC)/%.erl)
ASN_HRLS = $(ASN_TOP:%=%.hrl)
ASN_CONFIGS = OTP-PUB-KEY.asn1config
ASN_DBS = $(ASN_MODULES:%=%.asn1db) OTP-PUB-KEY.asn1db
ASN_TABLES = $(ASN_MODULES:%=%.table)

GEN_MODULES =
GEN_ERLS = $(GEN_MODULES:%=%.erl)
ERL_MODULES = $(ASN_TOP) $(GEN_MODULES)

TARGET_FILES= $(ERL_MODULES:%=$(EBIN)/%.$(EMULATOR))

HRL_FILES = $(ASN_HRLS:%=$(INCLUDE)/%)

INCLUDE = ../include
EBIN = ../ebin

# ----------------------------------------------------
# FLAGS
# ----------------------------------------------------
Expand All @@ -76,15 +77,15 @@ ASN_FLAGS = -bber +der +noobj +asn1config
$(TYPES): $(TARGET_FILES) $(HRL_FILES)

clean:
-rm -f $(ASN_ERLS) $(GEN_ERLS) $(ASN_HRLS) $(HRL_FILES) $(ASN_DBS) \
-rm -f $(ASN_ERLS) $(ASN_HRLS) $(HRL_FILES) $(ASN_DBS) \
$(ASN_TABLES) $(TARGET_FILES) *.beam *~

docs:

%.erl %.hrl: %.set.asn
$(asn_verbose)erlc $(ASN_FLAGS) $<
$(ESRC)/%.erl $(ESRC)/%.hrl: %.set.asn
$(asn_verbose)erlc $(ASN_FLAGS) -o $(ESRC) $<

$(INCLUDE)/%.hrl: %.hrl
$(INCLUDE)/%.hrl: $(ESRC)/%.hrl
$(gen_verbose)cp -p $< $@

# ----------------------------------------------------
Expand All @@ -96,8 +97,10 @@ release_spec: opt
$(INSTALL_DIR) "$(RELSYSDIR)/include"
$(INSTALL_DATA) $(HRL_FILES) "$(RELSYSDIR)/include"
$(INSTALL_DIR) "$(RELSYSDIR)/asn1"
$(INSTALL_DATA) $(ASN_ASNS) $(ASN_ERLS) $(ASN_HRLS) $(ASN_CONFIGS) \
$(GEN_ERLS) "$(RELSYSDIR)/asn1"
$(INSTALL_DATA) $(ASN_ASNS) $(ASN_CONFIGS) \
"$(RELSYSDIR)/asn1"
$(INSTALL_DIR) "$(RELSYSDIR)/src"
$(INSTALL_DATA) $(ASN_ERLS) "$(RELSYSDIR)/src"
$(INSTALL_DIR) "$(RELSYSDIR)/ebin"
$(INSTALL_DATA) $(TARGET_FILES) "$(RELSYSDIR)/ebin"

Expand All @@ -106,7 +109,7 @@ release_docs_spec:
#
# Dependencies

$(EBIN)/OTP-PUB-KEY.beam: OTP-PUB-KEY.erl OTP-PUB-KEY.hrl
$(EBIN)/OTP-PUB-KEY.beam: $(ESRC)/OTP-PUB-KEY.erl $(INCLUDE)/OTP-PUB-KEY.hrl
OTP-PUB-KEY.erl OTP-PUB-KEY.hrl: OTP-PUB-KEY.asn1db
OTP-PUB-KEY.asn1db: PKIX1Algorithms88.asn1 \
PKIX1Explicit88.asn1 \
Expand All @@ -120,7 +123,7 @@ OTP-PUB-KEY.asn1db: PKIX1Algorithms88.asn1 \
OTP-PKIX.asn1 \
RFC5639.asn1

$(EBIN)/PKCS-FRAME.beam: PKCS-FRAME.erl PKCS-FRAME.hrl
$(EBIN)/PKCS-FRAME.beam: $(ESRC)/PKCS-FRAME.erl $(INCLUDE)/PKCS-FRAME.hrl
PKCS-FRAME.erl PKCS-FRAME.hrl: PKCS-FRAME.asn1db
PKCS-FRAME.asn1db: PKCS5v2-0.asn1\
PKCS-8.asn1\
32 changes: 28 additions & 4 deletions lib/stdlib/test/filelib_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
wildcard_one/1,wildcard_two/1,wildcard_errors/1,
fold_files/1,otp_5960/1,ensure_dir_eexist/1,ensure_dir_symlink/1,
wildcard_symlink/1, is_file_symlink/1, file_props_symlink/1,
find_source/1, find_source_subdir/1, safe_relative_path/1,
safe_relative_path_links/1]).
find_source/1, find_source_subdir/1, find_source_otp/1,
safe_relative_path/1, safe_relative_path_links/1]).

-import(lists, [foreach/2]).

Expand All @@ -50,8 +50,8 @@ all() ->
[wildcard_one, wildcard_two, wildcard_errors,
fold_files, otp_5960, ensure_dir_eexist, ensure_dir_symlink,
wildcard_symlink, is_file_symlink, file_props_symlink,
find_source, find_source_subdir, safe_relative_path,
safe_relative_path_links].
find_source, find_source_subdir, find_source_otp,
safe_relative_path, safe_relative_path_links].

groups() ->
[].
Expand Down Expand Up @@ -652,6 +652,30 @@ find_source_subdir(Config) when is_list(Config) ->

ok.

%% Test that all available beam files in Erlang/OTP can be
%% tracked to their source files.
find_source_otp(Config) when is_list(Config) ->
%% We do this in a peer as testcases before this may have
%% edited the code path and thus more modules show up as
%% available than should.
{ok, Peer, Node} = ?CT_PEER(),
erpc:call(
Node,
fun() ->
lists:map(
fun F({Module, preloaded, Loaded}) ->
F({Module, code:where_is_file(Module ++ ".beam"), Loaded});
F({Module, Filename, _Loaded}) ->
case filelib:find_source(Filename) of
{ok, _} -> ok;
{error,_} = E ->
ct:fail({failed_to_find, Module, Filename, E})
end
end, code:all_available())
end),
peer:stop(Peer),
ok.

safe_relative_path(Config) ->
PrivDir = proplists:get_value(priv_dir, Config),
Root = filename:join(PrivDir, "filelib_SUITE_safe_relative_path"),
Expand Down

0 comments on commit a7ecc5b

Please sign in to comment.