在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bootlin/elixir开源软件地址(OpenSource Url):https://github.com/bootlin/elixir开源编程语言(OpenSource Language):C 73.2%开源软件介绍(OpenSource Introduction):The Elixir Cross ReferencerElixir is a source code cross-referencer inspired by LXR. It’s written in Python and its main purpose is to index every release of a C or C++ project (like the Linux kernel) while keeping a minimal footprint. It uses Git as a source-code file store and Berkeley DB for cross-reference data. Internally, it indexes Git blobs rather than trees of files to avoid duplicating work and data. It has a straightforward data structure (reminiscent of older LXR releases) to keep queries simple and fast. You can see it in action on https://elixir.bootlin.com/
Table of Contents
Requirements
ArchitectureElixir has the following architecture: .---------------.----------------. | CGI interface | REST interface | |---------------|----------------. | Query command | Update command | |---------------|----------------| | Shell script | '--------------------------------' The shell script ( When installing the system, you should test each layer manually and make sure it works correctly before moving on to the next one. Database design
A detailed diagram of the databases will be provided. Until then, just use the Source, Luke. Manual InstallationInstall Dependences
yum install python36-pip python36-pytest python36-jinja2 python36-bsddb3 python36-falcon git httpd perl perl-autodie jansson libyaml rh-python36-mod_wsgi
sudo apt install python3 python3-jinja2 python3-bsddb3 python3-falcon python3-pytest universal-ctags perl git apache2 libapache2-mod-wsgi-py3 libjansson4 To enable the REST API, follow the installation instructions on To know which packages to install, you can also read the Docker files in the Special dependenciesDevice Tree and Kconfig Source syntax highlightingThe service on https://elixir.bootlin.com relies on a modified version of Pygments, to enable syntax highlighting on Device Tree Source (DTS) files and on all Kconfig files. The changes have been sent upstream and should appear in future distributions. In the meantime, you can either rebuild this package from its source on GitHub, or download this binary module and install it as follows: sudo pip3 install Pygments-2.6.1.elixir-py3-none-any.whl Kconfig identifiers supportThe service on https://elixir.bootlin.com relies on a modified version of Universal-ctags, to enable indexing of Kconfig identifiers. The changes have been sent upstream and should appear in future distributions. In the meantime, you can either rebuild this package from its source on GitHub, or download this deb binary package or rpm binary package and install it as follows: sudo dpkg -i universal-ctags_0+git20200526-0ubuntu1_amd64.deb or sudo rpm -iv universal-ctags-0+git~20e934e3-1.6.x86_64.rpm Then tell sudo apt-mark hold universal-ctags Download Elixir Projectgit clone https://github.com/bootlin/elixir.git /usr/local/elixir/ Create Directorymkdir -p /path/elixir-data/linux/repo mkdir -p /path/elixir-data/linux/data Set environment variablesTwo environment variables are used to tell Elixir where to find the project’s local git repository and its databases:
Now open export LXR_REPO_DIR=/path/elixir-data/linux/repo export LXR_DATA_DIR=/path/elixir-data/linux/data And then run Clone Kernel source codeFirst clone the master tree released by Linus Torvalds: cd /path/elixir-data/linux git clone https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git repo Then, you should also declare a cd repo git remote add stable git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git git fetch stable Then, you can also declare an cd repo git remote add history https://github.com/bootlin/linux-history.git git fetch history --tags Feel free to add more remote branches in this way, as Elixir will consider tags from all remote branches. First Testcd /usr/local/elixir/ ./script.sh list-tags Create Database./update.py <number of threads (default 10 | min 5)>
Second TestVerify that the queries work: $ ./query.py v4.10 ident raw_spin_unlock_irq C $ ./query.py v4.10 file /kernel/sched/clock.c
Configure httpdThe CGI interface (
It will then generate the other two variables upon calling the query command. Now open HttpProtocolOptions Unsafe # Required for HTTP <Directory /usr/local/elixir/http/> Options +ExecCGI AllowOverride None Require all granted SetEnv PYTHONIOENCODING utf-8 SetEnv LXR_PROJ_DIR /path/elixir-data </Directory> # Required for the REST API <Directory /usr/local/elixir/api/> SetHandler wsgi-script Require all granted SetEnv PYTHONIOENCODING utf-8 SetEnv LXR_PROJ_DIR /path/elixir-data </Directory> AddHandler cgi-script .py #Listen 80 <VirtualHost *:80> ServerName xxx DocumentRoot /usr/local/elixir/http # To enable REST api after installing mod_wsgi: Fill path and uncomment: #WSGIScriptAlias /api /usr/local/elixir/api/api.py AllowEncodedSlashes On RewriteEngine on RewriteRule "^/$" "/linux/latest/source" [R] RewriteRule "^/(?!api|acp).*/(source|ident|search)" "/web.py" [PT] RewriteRule "^/acp" "/autocomplete.py" [PT] </VirtualHost> cgi and rewrite support has been enabled by default in RHEL/CentOS, but you should enable it manually if your distribution is Debian/Ubuntu. a2enmod cgi rewrite Finally, start the httpd server. systemctl start httpd Configure SELinux policyWhen running systemd with SELinux enabled, httpd server can only visit limited directories. If your /path/elixir-data/ is not one of these allowed directories, you will be responded with 500 status code. To allow httpd server to visit /path/elixir-data/, run following codes: chcon -R -t httpd_sys_rw_content_t /path/elixir-data/ To check if it takes effect, run the following codes: ls -Z /path/elixir-data/ In case you want to check SELinux log releated with httpd, run the following codes: audit2why -a | grep httpd | less Configure systemd log directoryBy default, the error log of elixir will be put in /tmp/elixir-errors. However, systemd enables PrivateTmp by default. And, the final error directory will be like /tmp/systemd-private-xxxxx-httpd.service-xxxx/tmp/elixir-errors. If you want to disable it, configure httpd.service with the following attribute: PrivateTmp=false Configure lighthttpdHere’s a sample configuration for lighthttpd: server.document-root = server_root + "/elixir/http" url.redirect = ( "^/$" => "/linux/latest/source" ) url.rewrite = ( "^/(?!api|acp).*/(source|ident|search)" => "/web.py/$1") url.rewrite = ( "^/acp" => "/autocomplete.py") setenv.add-environment = ( "PYTHONIOENCODING" => "utf-8", "LXR_PROJ_DIR" => "/path/to/elixir-data" ) REST API usage
After configuring httpd, you can test the API usage:
ident querySend a get request to curl http://127.0.0.1/api/ident/barebox/cdev?version=latest&family=C The response body is of the following structure: { "definitions": [{"path": "commands/loadb.c", "line": 71, "type": "variable"}, ...], "references": [{"path": "arch/arm/boards/cm-fx6/board.c", "line": "64,64,71,72,75", "type": null}, ...] } Maintenance and enhancementsUsing a cache to improve performanceAt Bootlin, we’re using the Varnish http cache as a front-end to reduce the load on the server running the Elixir code. .-------------. .---------------. .-----------------------. | Http client | --------> | Varnish cache | --------> | Apache running Elixir | '-------------' '---------------' '-----------------------' Keeping Elixir databases up to dateTo keep your Elixir databases up to date and index new versions that are released,
we’re proposing to use a script like You can set Keeping git repository disk usage under controlAs you keep updating your git repositories, you may notice that some can become
considerably bigger than they originally were. This seems to happen when a When this happens, you can save disk space by packing git directories as follows: cd <bare-repo> git prune rm gc.log git gc --aggressive Actually, a second pass with the above commands will save even more space. To process multiple git repositories in a loop, you may use the
Building Docker imagesDocker files are provided in the $ docker build -t elixir --build-arg GIT_REPO_URL=git://git.musl-libc.org/musl --build-arg PROJECT=musl . Then you can use your new container as follows (you get the container id from the output of $ docker run <container-id> You can the open the below URL in a browser on your host: http://172.17.0.2/musl/latest/source (change the container IP address if you don’t get the default one) Hardware requirementsPerformance requirements depend mostly on the amount of traffic that you get on your Elixir service. However, a fast server also helps for the initial indexing of the projects. SSD storage is strongly recommended because of the frequent access to git repositories. At Bootlin, here are a few details about the server we’re using:
Contributing to ElixirSupporting a new projectElixir has a very simple modular architecture that allows to support new source code projects by just adding a new file to the Elixir sources. Elixir’s assumptions:
First make an installation of Elixir by following the above instructions.
See the Once Elixir works for at least one project, it’s time to clone the git repository for the project you want to support: cd /srv/git git clone --bare https://github.com/zephyrproject-rtos/zephyr After doing this, you may also reference and fetch remote branches for this project,
for example corresponding to the Now, in your cd $LXR_PROJ_DIR mkdir -p zephyr/data ln -s /srv/git/zephyr.git repo export LXR_DATA_DIR=$LXR_PROJ_DIR/data export LXR_REPO_DIR=$LXR_PROJ_DIR/repo Now, go back to the Elixir sources and test that tags are correctly extracted: ./script.sh list-tags Depending on how you want to show the available versions on the Elixir pages,
you may have to apply substitutions to each tag string, for example to add
a list_tags() { echo "$tags" | grep -v '^zephyr-v' } Note that The next step is to make sure that versions are classified as you wish
in the version menu. This classification work is done through the
v4 v4.16 v4.16 v4 v4.16 v4.16-rc7 v4 v4.16 v4.16-rc6 v4 v4.16 v4.16-rc5 v4 v4.16 v4.16-rc4 v4 v4.16 v4.16-rc3 v4 v4.16 v4.16-rc2 v4 v4.16 v4.16-rc1 ... The first column is the top level menu entry for versions. The second one is the next level menu entry, and the third one is the actual version that can be selected by the menu. Note that this third entry must correspond to the exact name of the tag in git. If the default behavior is not what you want, you will have
to customize the You should also make sure that Elixir properly identifies the most recent versions: ./script.sh get-latest If needed, customize the If you want to enable support for You are now ready to generate Elixir’s database for your new project: ./update.py <number of threads (default 10 | min 5)> You can then check that Elixir works through your http server. Coding styleIf you wish to contribute to Elixir’s Python code, please follow the official coding style for Python. How to send patchesThe best way to share your contributions with us is to file a pull request on GitHub. Automated testingElixir includes a simple test suite in prove The test suite uses code extracted from Linux v5.4 in
Licensing of code in |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论