how to set include directory for rebar - erlang

In my module I have
-include("blah.hrl").
The .hrl file is not in the module's directory, but somewhere else on my system. How can I make rebar find it when compiling? Is there a way to add a path to the include directory in rebar.config?

{erl_opts, [{i, PathToIncludeFile}]}.
in rebar.config should do the thing. Or append {i, ...} to the existing erl_opts, if you have any.

Related

Command 'rebar doc' is inconsistent

First of all, 'rebar doc' works sometimes and sometimes not. It is strange.
Rebar version which I'm using is 2.5.1
My folder structure is:
Header_Directory
1.1 apps
1.1.1 sub_dir_1
1.1.2 sub_dir_2 / include
1.1.3 sub_dir_3
1.2 deps
1.3 confs
rebar.config
Modules in sub_dir_3 also use some include files from sub_dir_2/include folder.
The error I get when I use the command rebar doc is:
.sub_dir_3/src/my_log_worker.erl, in module header: at line 9: file
not found: some.hrl edoc: skipping source file
'sub_dir_3/src/my_log_worker.erl': {'EXIT',error}. edoc: error in
doclet 'edoc_doclet': {'EXIT',error}. ERROR: doc failed while
processing /home/learn/header_directory/apps/sub_dir_3: {'EXIT',error}
I do 'rebar clean' and then 'rebar compile' prior to 'rebar doc'
Also,when I do it in erl shell, I get error.
edoc:file("some_log_worker.erl", []).
edoc: error reading file 'some_log_worker.erl'.
** exception exit: {error,enoent}
in function edoc:read_source/2 (edoc.erl, line 664)
in call from edoc_extract:source/3 (edoc_extract.erl, line 52)
in call from edoc:read/2 (edoc.erl, line 537)
in call from edoc:file/2 (edoc.erl, line 116)
Is there any way by which I can include my hrl file either in rebar.config or edoc options?
I have '{edoc_opts, [{ i, "apps/sub_dir_3/include" }]}.' in rebar.config, still of no help.
It looks like you didn't follow the rebar/OTP conventions:
OTP Conventions
Rebar expects projects to follow the OTP conventions as described in
the OTP Design Principles document: Applications
An application should consists of the following set of directories:
src
ebin
priv
include
and have an application resource file: ebin/example_project.app or
src/example_project.app.src. In the later case, the
ebin/example_project.app file is generated from the
src/example_project.app.src one automatically during the compilation
phase.
Rebar & OTP convetions
I recommend you to move to that file organisation, it will be really much simpler to benefit from standard tools like rebar.
Yes, it is always in the best interest to follow the OTP principles. However, it worked for my app structure.
The only problem was because of #headerfile annotation in the erlang modules. Somehow, I don't know how to correctly use the #headerfile annotation.
Thanks for all the help. :)

Cannot add files to the bundle Cmake

I want to add two files inside MyPlugin.plugin directory.
I follow the instructions provided here but files are not added in the directory.
I have also tried to add them in "Contents" directory and failed.
What I managed to do is add them inside "Resources/English.lproj" directory.
The structure is the following:
MyPlugin.plugin/
Contents/
Info.plist
MacOS/
file1
Resources/
English.lproj/
InfoPlist.strings
Localized.rsrc
The code that I add inside projectDef.cmake in order to add files inside MyPlugin.plugin is:
file (GLOB MAC_FILES ${CMAKE_CURRENT_SOURCE_DIR}
MacFiles/file1
MacFiles/file2
)
set_source_files_properties(
${MAC_FILES}
PROPERTIES
MACOSX_PACKAGE_LOCATION "MyPlugin.plugin"
)
SOURCE_GROUP(Mac FILES ${PLATFORM})
set (SOURCES
${SOURCES}
${PLATFORM}
${MAC_FILES}
)
I should mention that I use the same code to add files inside Resources/English.lproj, only changing line:
MACOSX_PACKAGE_LOCATION "Resources/English.lproj"
Most likely you need a package location of "" or perhaps "/"; this should be the location inside the bundle, not the name of the bundle itself.

Which paths does Bower ignore by default?

bower.json can specify which files should be ignored:
ignore [array]: An array of paths not needed in production that you want Bower to ignore when installing your package.
Which paths are ignored by default?
From the source:
json.ignore = mout.array.combine(json.ignore || [], [
'**/.*',
'node_modules',
'bower_components',
config.directory,
'test',
'tests'
]);
Apparently all dotfiles are ignored, as are the bower_components, node_modules, test, and tests directories. I don't know what config.directory is.
Update: I just published a package, and the test directory was not ignored. Apparently I've misunderstood the source code. I'd love clarification from a Bower contributor.
Files which are listed in ignore property will not be installed by bower.
So, if you have a this kind of structure:
style.css
index.html
bower.json
script.js
and a bower.json file:
{
"ignore": [ "./script.js" ]
}
script.js will not be installed within this component.

ant zip; exclude all sub-directories and files

When creating a zip from ant, how can I exclude all sub directories and files from a given directory?
I have tried the following but it doesn't seem to prevent them from being included in the zip
<target name="zip">
<zip destfile="C:\Projects\example\builds\.zip"
excludes="C:\Projects\example\logs\**\*.*">
...
...
</zip>
</target>
From reading the documentation, and from reading the ant definitive guide I would assume that **\ should exclude any directory, and *.* would exclude any file of any extension
I want to include the logs directory, but nothing inside it.
I would recommend the following:
Change the name of your destfile to "C:\Projects\example\builds\logs.zip"
Set your basedir to "C:\Projects\example\"
Change your excludes value to "C:\Projects\example\logs\**\*" (that means any file)
Another option might be to use the project-defined basedir, and change all your paths to relative UNIX-like values.

How to Integrate Qt4 qm files into binary using cmake and QRC?

I have a Qt4 CMake project and I'd like to integrate the QM files for i18n into the output binary. These are the rules I have so far for generating the TS and QM files:
set(myapp_TRANSLATIONS
i18n/myapp_de.ts
)
set(FILES_TO_TRANSLATE
${myapp_SRCS}
${myapp_MOC_HDRS}
)
QT4_CREATE_TRANSLATION(QM_FILES ${FILES_TO_TRANSLATE} ${myapp_TRANSLATIONS})
QT4_ADD_TRANSLATION(QM ${myapp_TRANSLATIONS})
I tried the following to add the QM files to the executable:
add_executable(myapp ${myapp_SRCS} ${myapp_MOC_SRCS} ${myapp_RCC_SRCS} ${QM})
This is the initialization from main.cpp:
QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);
QTranslator appTranslator;
appTranslator.load("myapp_" + QLocale::system().name());
app.installTranslator(&appTranslator);
However, strings mypp shows that the translations are not going into the binary.
Update: I added each qm file to a i18n/translations.qrc:
<!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/resources">
<file>myapp_de.qm</file>
<file> ... .qm</file>
</qresource>
</RCC>
and using
QT4_ADD_RESOURCES(myapp_QM_RCC_SRCS i18n/translations.qrc)
and adding myapp_QM_RCC_SRCS to the executable dependencies.
But this fails during build time thanks to the fact that CMake does a shadow build (building outside the source dir) but parses the QRC files for dependencies expecting the referenced files relative to the QRC file (nice feature but there's no make rule how to build the QM file at that location). The QM files are in ${CMAKE_CURRENT_BINARY_DIR} (where they belong using shadow building) but expects it in ${CMAKE_CURRENT_SOURCE_DIR} (where non-generated files should be - so both locations would be correct, depending on situation).
I had the exact same problem. I came up with the following solution:
Create a QRC file that contains only the expected QM files, and give it a different prefix so it won't conflict with your other resources:
<RCC>
<qresource prefix="/translators">
<file>myapp_en.qm</file>
</qresource>
</RCC>
Add a CMake rule to copy the QRC file to the output directory and then another rule to run the resource compiler:
# Change 'myapp_en' to be the base file name of the qrc file.
SET( trans_file myapp_en )
SET( trans_srcfile ${CMAKE_CURRENT_SOURCE_DIR}/${trans_file}.qrc)
SET( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc)
SET( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx)
# Copy the QRC file to the output directory, because the files listed in the
# qrc file are relative to that directory.
ADD_CUSTOM_COMMAND(
OUTPUT ${trans_infile}
COMMAND ${CMAKE_COMMAND} -E copy ${trans_srcfile} ${trans_infile}
MAIN_DEPENDENCY ${trans_srcfile}
)
# Run the resource compiler (rcc_options should already be set). We can't
# use QT4_ADD_RESOURCES because the qrc file may not exist yet.
ADD_CUSTOM_COMMAND(
OUTPUT ${trans_outfile}
COMMAND ${QT_RCC_EXECUTABLE}
ARGS ${rcc_options} -name ${trans_file} -o ${trans_outfile} ${trans_infile}
MAIN_DEPENDENCY ${trans_infile}
DEPENDS ${qm_files}
)
# Add compiled resources to executable dependency list
ADD_EXECUTABLE( ${APP_NAME} ... ${trans_outfile} )
Use ${Qt5Core_RCC_EXECUTABLE} instead of ${QT_RCC_EXECUTABLE} if you use Qt 5.
I have found a very simple way to do it in CMake 3.0 (and, maybe, earlier) without ADD_CUSTOM_COMMAND and other complications.
First, you should create a QRC file with all .qm files listed ( thanks, the_fly_123 ):
<RCC>
<qresource prefix="/translators">
<file>myapp_en.qm</file>
</qresource>
</RCC>
Then you can copy this QRC file into the output directory using configure_file and use standard Qt routines to build and add it:
# Change lang.qrc to the name of QRC file, created on the previous step
set(lang_qrc "lang.qrc")
configure_file(${lang_qrc} ${lang_qrc} COPYONLY)
qt5_add_translation(myapp_QM ${myapp_TRANSLATIONS})
qt5_add_resources(myapp_QM_RC ${CMAKE_CURRENT_BINARY_DIR}/${lang_qrc})
Then include ${myapp_QM_RC} in add_executable along with other sources.
Note: For Qt4 replace all qt5_ prefixes with qt4_
My solution is to generate ts.qrc XML file with compiled translations from scratch and then complie it with app.
Here is example:
file(GLOB QRC_FILES *.qrc)
file(GLOB TS_FILES ts/*.ts)
...
# Option for updating translations
option(UPDATE_TRANSLATIONS "Update source translation ts/*.ts files (WARNING: make clean will delete the source *.ts files. Danger!)" OFF)
if(UPDATE_TRANSLATIONS)
qt4_create_translation(QM_FILES ${TS_FILES})
endif()
...
# Compiling translations *.ts -> *.qm
qt4_add_translation(QM_FILES ${TS_FILES})
...
# Create translations QRC file - ts.qrc
set(TRANSLATIONS_QRC "${CMAKE_CURRENT_BINARY_DIR}/ts.qrc")
file(WRITE ${TRANSLATIONS_QRC} "<RCC>\n\t<qresource prefix=\"/ts\">")
foreach(QM_FILE ${QM_FILES})
get_filename_component(QM_FILE_NAME ${QM_FILE} NAME)
file(APPEND ${TRANSLATIONS_QRC} "\n\t\t<file alias=\"${QM_FILE_NAME}\">${QM_FILE_NAME}</file>")
endforeach()
file(APPEND ${TRANSLATIONS_QRC} "\n\t</qresource>\n</RCC>")
list(APPEND QRC_FILES ${TRANSLATIONS_QRC})
...
# Compiling *.qrc files
qt4_add_resources(QRC_SRCS ${QRC_FILES})
...
# Add compiled resources to executable dependency list
add_executable(${APP_NAME} ... ${QRC_SRCS})
File tree:
/ - source code root
/rc.qrc - contains app icons etc.
/ts/appname_*.ts - application translations
...
/build - build root
/build/appname_*.qm - compiled translations
/build/ts.qrc - translations rescources
/build/Release/qrc_rc.cxx - compiled icon etc. resources
/build/Release/qrc_ts.cxx - compiled translation resources
Files in ts dir initially generated by lupdate tool.
You need to use Qt resources system to include your translation directly into your application binary. Use QT4_ADD_RESOURCES macro to do this. There is some example how to use it: http://www.qtcentre.org/wiki/index.php?title=Compiling_Qt4_apps_with_CMake

Resources