Bazel and visibility of classes - intellij-idea

I have a monorepo project with the structure
backend
|- jvm
|- apps
|- core-service
|- api
|- src
|- BUILD.bazel
|- app
|- src
|- BUILD.bazel
|- post-service
|- api
|- src
|- BUILD.bazel
|- app
|- src
|- BUILD.bazel
...
|- libs
|-core
|- src
|- BUILD.bazel
...
|- BUILD.bazel
|- .bazelproject
|- BUILD.bazel
I have an issue. For instance, if I have two classes with the same name in different services. When I use this class in a code (for example, in core-service), I can accidentally import the wrong class (from post-service). And I will understand this only when I run the build. Bu some reason, IDEA imported the wrong class, and everything is looking fine till I run the build.
Is it part of Bazel configuration or IDEA configuration?

Related

How to resolve dependencies in PNPM workspace?

I have a pnpm workspace with the following structure:
root
|- example
| |- package.json
|
|- packages
| |- a
| | |- package.json
| |
| |- b
| | |- package.json
| |
| |- c
| | |- package.json
The package c is a package that should contain a and b:
{
"name": "c",
"dependencies": {
"a": "workspace:*",
"b": "workspace:*"
}
}
package.json file in example looks like this:
{
"name": "example",
"dependencies": {
"c": "workspace:*"
}
}
When I do pnpm install it places only c dependency in example/node_modules - it does not install necessary packages a and b.
What do I have to do to have all nested dependencies installed correctly?
They are installed correctly. The c inside root/example/node_modules is a symlink to root/packages/c. The dependencies of c are symlinked to root/packages/c/node_modules.

setup.py sdist creates an archive without the package

I have a project called Alexandria that I want to upload on PyPi as a package. To do so, I have a top folder called alexandria-python in which I put the package and all the elements required to create a package archive with setup.py. The folder alexandria-python has the following structure:
|- setup.py
|- README.md
|- alexandria (root folder for the package)
|- __init__.py
|- many sub-packages
Then, following many tutorials to create an uploadable archive, I open a terminal, cd to alexandria-python, and use the command:
python setup.py sdist
This creates additional folders, so the structure of alexandria-python is now:
|- setup.py
|- README.md
|- alexandria (root folder for the package)
|- __init__.py
|- many sub-packages
|- alexandria.egg-info
|- dist
everything looks fine, and from my understanding the package should now be archived in the dist folder. But when I open the dist folder and extract the alexandria-0.0.2.tar.gz archive that has been created, it does not contain the 'alexandria' package. Everything else thus seems to be there, except the most important element: the package, as shown on the image:
Following, when I upload the project to test-PyPi and then pip install it, any attempt to import a module from the toolbox results in a ModuleNotFoundError. How is it that my package does not get uploaded to the archive? Am I doing something very silly?
Note: in case it can help, this is the structure of my setup.py file:
from setuptools import setup
# set up the package
setup(
name = "alexandria",
license = "Other/Proprietary License",
version = "0.0.2",
author = "Romain Legrand",
author_email = "alexandria.toolbox#gmail.com",
description = "a software for Bayesian time-series econometrics applications",
python_requires = ">=3.6",
keywords=["python", "Bayesian", "time-series", "econometrics"])
Your setup.py has neither py_modules nor packages. Must have one of those. In your case alexandria is a package so
setup(
…
packages = ['alexandria'],
…
)
or
from setuptools import find_packages, setup
…
packages = find_packages('.')

How to run eslint in different folders

I came into a eslint problem.
Generally, we have src folder side by side with package.json, like this:
|-projectName
|- src
|- .eslintrc.js
|- package.json
|- vue.config.js
Then i want to take compiling scripts and business code apart into different folders, and to enable them to be linted, i put two '.eslintrc.js' files in each, like this:
|- projectName
|- runtime
|- babel.config.js
|- .eslintrc.js
|- package.json
|- vue.config.js
|- business
|- .eslintrs.js
|- src
|- main.js
|- index.html
|- ...
Then i found eslint turns into chaos:
When i ran 'npm run build', eslint firstly linted files in 'runtime' folder as '.eslintrc.js' in it,
and then vue-cli-service came into building stage, which called eslint again as '.eslintrc.js' in 'template' folder,
but at last the vue-cli-service still finished building even if eslint throws errors, which should stopped building.
The output was like this:
✖ 7 problems (4 errors, 3 warnings)
3 errors and 3 warnings potentially fixable with the `--fix` option.
# ../template/src/store/index.js 14:0-34 18:10-14
# ../template/src/main.js
# multi ../template/src/main.js
...
File Size Gzipped
../template/build/apps/local/0/js/chun 174.42 KiB 58.47 KiB
k-vendors.9db3f582.js
...
DONE Build complete. The ../template/build directory is ready to be deployed.
INFO Check out deployment instructions at https://cli.vuejs.org/guide/deployment.html
I don't know why this happened? Is there someting wrong with eslint config? I just put two '.eslintrc.js' files generated by 'vue craete' command in two different folders , and configure right paths in vue.config.js, like this:
// vue.config.js
...
outputDir: path.resolve(__dirname, '../template/build'),
pages:{
index: {
entry: path.resolve(__dirname, '../template/src/main.js')
}
}
...

how to use CTest with Node js command, for testing JS file compiled from C++ using emscripten, and use Catch2?

I am try to use Catch2 library for testing and compile it with emscripten and run the test. The directory structure of my project look like this
|- CMakeLists.txt
|- build
|   |- ...
|   |- try-test.js
|   |- try-test.wasm
|   |- try-test.wast
|- test
|   |- main.cpp
|- third_party
|- Catch2
|- ...
when I am move to build directory and run node try-test.js, it success. but when i am run ctest, it fail. Below is the output message.
Test project /Users/janucaria/Projects/junk/em-cpp-unit-test/build
Start 1: trytest
Could not find executable node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
Looked in the following places:
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Release/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Release/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Debug/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Debug/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/MinSizeRel/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/MinSizeRel/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/RelWithDebInfo/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/RelWithDebInfo/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Deployment/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Deployment/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Development/try-test.js
node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/Development/try-test.js
Unable to find executable: node /Users/janucaria/Projects/junk/em-cpp-unit-test/build/try-test.js
1/1 Test #1: trytest ..........................***Not Run 0.00 sec
0% tests passed, 1 tests failed out of 1
Total Test time (real) = 0.01 sec
The following tests FAILED:
1 - trytest (Not Run)
Errors while running CTest
Am I missing something here?
here is my test/main.cpp
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
TEST_CASE("Try test")
{
int foo = 1;
REQUIRE(foo == 1);
}
and here the CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(trytest)
enable_testing()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(try-test "test/main.cpp")
target_include_directories(try-test
PRIVATE
"${PROJECT_SOURCE_DIR}/third_party/Catch2/single_include"
)
target_compile_options(try-test PRIVATE "-Wall" "-Wpedantic" "-stdlib=libc++")
add_test(
NAME trytest
COMMAND "node ${CMAKE_CURRENT_BINARY_DIR}/try-test.js")
I would be grateful for any help you are able to provide.
I figure it out. I am use add_test wrong. It should be
add_test(
NAME trytest
COMMAND node "${CMAKE_CURRENT_BINARY_DIR}/try-test.js")
so the ctest will run command node with arguments ${CMAKE_CURRENT_BINARY_DIR}/try-test.js

Cmake file linking dynamic library to executable

I am trying to make a cmake file for my project just to learn how to make a cmake file.
My directory Structure. I am getting an error :
square_and_add
|- src
| |- <Some source files>
|- libsrc
| |- include
| |- <library header files>
| |- src
| |- <library source files>
|- build
|- libs
|- <installed libraries>
cmake_minimum_required(VERSION 2.6)
project(SQUARE_AND_ADD)
set(CMAKE_CXX_FLAGS "-g -Wall")
include_directories(./libsrc/include)
include_directories(./libsrc/src)
include_directories(./build)
add_executable(no_lib_exec ./src/main.cc)
target_link_libraries(no_lib_exec ./libsrc/src/square.cc)
set_target_properties(no_lib_exec PROPERTIES PREFIX "" OUTPUT_NAME sqnadd_no_lib)
add_library(build_static_lib STATIC ./libsrc/src/square.cc)
set_target_properties(build_static_lib PROPERTIES PREFIX "" OUTPUT_NAME static_library)
add_executable(static_lib_exec ./src/main.cc)
target_link_libraries(static_lib_exec ./build/static_library.a)
set_target_properties(static_lib_exec PROPERTIES PREFIX "" OUTPUT_NAME sqnadd_stat_lib)
add_library(build_dynamic_lib SHARED ./libsrc/src/square.cc)
set_target_properties(build_dynamic_lib PROPERTIES PREFIX "" OUTPUT_NAME dynamic_library)
add_executable(dynamic_lib_exec ./src/main.cc)
target_link_libraries(dynamic_lib_exec ./build/dynamic_library.so)
set_target_properties(dynamic_lib_exec PROPERTIES PREFIX "" OUTPUT_NAME sqnadd_dyn_lib)
install(TARGETS dynamic_lib_exec static_lib_exec
RUNTIME DESTINATION ./libs CONFIGURATIONS debug)
I am getting this error
/usr/bin/ld: cannot find -l./build/dynamic_library
collect2: error: ld returned 1 exit status
CMakeFiles/dynamic_lib_exec.dir/build.make:85: recipe for target 'sqnadd_dyn_lib' failed
Here is my approach on doing such things:
cmake_minimum_required(VERSION 2.6)
project(SQUARE_AND_ADD)
set(CMAKE_CXX_FLAGS "-g -Wall")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libsrc/include)
set(EXEC_NAME_BASE "sqnadd")
set(EXEC_NOLIB_NAME "${EXEC_NAME_BASE}_no_lib")
set(EXEC_STATICLIB_NAME "${EXEC_NAME_BASE}_stat_lib")
set(EXEC_SHAREDLIB_NAME "${EXEC_NAME_BASE}_dyn_lib")
set(STATICLIB_NAME "square_static")
set(SHAREDLIB_NAME "square_shared")
# if no lib, then just compile the square.cc into the executable
add_executable(${EXEC_NOLIB_NAME} src/main.cc libsrc/src/square.cc)
add_library(${STATICLIB_NAME} STATIC libsrc/src/square.cc)
add_executable(${EXEC_STATICLIB_NAME} src/main.cc)
target_link_libraries(${EXEC_STATICLIB_NAME} ${STATICLIB_NAME} )
add_library(${SHAREDLIB_NAME} SHARED libsrc/src/square.cc)
add_executable(${EXEC_SHAREDLIB_NAME} src/main.cc)
target_link_libraries(${EXEC_SHAREDLIB_NAME} ${SHAREDLIB_NAME})
# installing libraries:
install(TARGETS ${SHAREDLIB_NAME} ${STATICLIB_NAME}
RUNTIME DESTINATION lib CONFIGURATIONS debug)
# installing executables
install(TARGETS ${EXEC_NOLIB_NAME}
${EXEC_STATICLIB_NAME}
${EXEC_SHAREDLIB_NAME}
RUNTIME DESTINATION bin
CONFIGURATIONS debug)