Skip to content

Commit dd3e8f8

Browse files
committed
Merge branch 'tools-ynl-add-install-target'
Jan Stancek says: ==================== tools: ynl: add install target This series adds an install target for ynl. The python code is moved to a subdirectory, so it can be used as a package with flat layout, as well as directly from the tree. To try the install as a non-root user you can run: $ mkdir /tmp/myroot $ make DESTDIR=/tmp/myroot install $ PATH="/tmp/myroot/usr/bin:$PATH" PYTHONPATH="$(ls -1d /tmp/myroot/usr/lib/python*/site-packages)" ynl --help Proposed install layout is described in last patch. ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 93e505a + e5ad1d9 commit dd3e8f8

File tree

23 files changed

+113
-25
lines changed

23 files changed

+113
-25
lines changed

Documentation/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ quiet_cmd_sphinx = SPHINX $@ --> file://$(abspath $(BUILDDIR)/$3/$4)
104104
YNL_INDEX:=$(srctree)/Documentation/networking/netlink_spec/index.rst
105105
YNL_RST_DIR:=$(srctree)/Documentation/networking/netlink_spec
106106
YNL_YAML_DIR:=$(srctree)/Documentation/netlink/specs
107-
YNL_TOOL:=$(srctree)/tools/net/ynl/ynl-gen-rst.py
107+
YNL_TOOL:=$(srctree)/tools/net/ynl/pyynl/ynl_gen_rst.py
108108

109109
YNL_RST_FILES_TMP := $(patsubst %.yaml,%.rst,$(wildcard $(YNL_YAML_DIR)/*.yaml))
110110
YNL_RST_FILES := $(patsubst $(YNL_YAML_DIR)%,$(YNL_RST_DIR)%, $(YNL_RST_FILES_TMP))

Documentation/networking/multi-pf-netdev.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Observability
8989
=============
9090
The relation between PF, irq, napi, and queue can be observed via netlink spec::
9191

92-
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump queue-get --json='{"ifindex": 13}'
92+
$ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump queue-get --json='{"ifindex": 13}'
9393
[{'id': 0, 'ifindex': 13, 'napi-id': 539, 'type': 'rx'},
9494
{'id': 1, 'ifindex': 13, 'napi-id': 540, 'type': 'rx'},
9595
{'id': 2, 'ifindex': 13, 'napi-id': 541, 'type': 'rx'},
@@ -101,7 +101,7 @@ The relation between PF, irq, napi, and queue can be observed via netlink spec::
101101
{'id': 3, 'ifindex': 13, 'napi-id': 542, 'type': 'tx'},
102102
{'id': 4, 'ifindex': 13, 'napi-id': 543, 'type': 'tx'}]
103103

104-
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump napi-get --json='{"ifindex": 13}'
104+
$ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/netdev.yaml --dump napi-get --json='{"ifindex": 13}'
105105
[{'id': 543, 'ifindex': 13, 'irq': 42},
106106
{'id': 542, 'ifindex': 13, 'irq': 41},
107107
{'id': 541, 'ifindex': 13, 'irq': 40},

Documentation/networking/napi.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ parameters mentioned above use hyphens instead of underscores:
199199

200200
Per-NAPI configuration can be done programmatically in a user application
201201
or by using a script included in the kernel source tree:
202-
``tools/net/ynl/cli.py``.
202+
``tools/net/ynl/pyynl/cli.py``.
203203

204204
For example, using the script:
205205

206206
.. code-block:: bash
207207
208-
$ kernel-source/tools/net/ynl/cli.py \
208+
$ kernel-source/tools/net/ynl/pyynl/cli.py \
209209
--spec Documentation/netlink/specs/netdev.yaml \
210210
--do napi-set \
211211
--json='{"id": 345,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
SPDX-License-Identifier: GPL-2.0
22

33
This file is populated during the build of the documentation (htmldocs) by the
4-
tools/net/ynl/ynl-gen-rst.py script.
4+
tools/net/ynl/pyynl/ynl_gen_rst.py script.

Documentation/userspace-api/netlink/intro-specs.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ developing Netlink related code. The tool is implemented in Python
1515
and can use a YAML specification to issue Netlink requests
1616
to the kernel. Only Generic Netlink is supported.
1717

18-
The tool is located at ``tools/net/ynl/cli.py``. It accepts
18+
The tool is located at ``tools/net/ynl/pyynl/cli.py``. It accepts
1919
a handul of arguments, the most important ones are:
2020

2121
- ``--spec`` - point to the spec file
@@ -27,7 +27,7 @@ YAML specs can be found under ``Documentation/netlink/specs/``.
2727

2828
Example use::
2929

30-
$ ./tools/net/ynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \
30+
$ ./tools/net/ynl/pyynl/cli.py --spec Documentation/netlink/specs/ethtool.yaml \
3131
--do rings-get \
3232
--json '{"header":{"dev-index": 18}}'
3333
{'header': {'dev-index': 18, 'dev-name': 'eni1np1'},
@@ -75,7 +75,7 @@ the two marker lines like above to a file, add that file to git,
7575
and run the regeneration tool. Grep the tree for ``YNL-GEN``
7676
to see other examples.
7777

78-
The code generation itself is performed by ``tools/net/ynl/ynl-gen-c.py``
78+
The code generation itself is performed by ``tools/net/ynl/pyynl/ynl_gen_c.py``
7979
but it takes a few arguments so calling it directly for each file
8080
quickly becomes tedious.
8181

@@ -84,7 +84,7 @@ YNL lib
8484

8585
``tools/net/ynl/lib/`` contains an implementation of a C library
8686
(based on libmnl) which integrates with code generated by
87-
``tools/net/ynl/ynl-gen-c.py`` to create easy to use netlink wrappers.
87+
``tools/net/ynl/pyynl/ynl_gen_c.py`` to create easy to use netlink wrappers.
8888

8989
YNL basics
9090
----------

tools/net/ynl/Makefile

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# SPDX-License-Identifier: GPL-2.0
22

3+
include ../../scripts/Makefile.arch
4+
5+
INSTALL ?= install
6+
prefix ?= /usr
7+
ifeq ($(LP64), 1)
8+
libdir_relative = lib64
9+
else
10+
libdir_relative = lib
11+
endif
12+
libdir ?= $(prefix)/$(libdir_relative)
13+
includedir ?= $(prefix)/include
14+
315
SUBDIRS = lib generated samples
416

517
all: $(SUBDIRS) libynl.a
@@ -21,5 +33,20 @@ clean distclean:
2133
fi \
2234
done
2335
rm -f libynl.a
36+
rm -rf pyynl/__pycache__
37+
rm -rf pyynl/lib/__pycache__
38+
rm -rf pyynl.egg-info
39+
rm -rf build
40+
41+
install: libynl.a lib/*.h
42+
@echo -e "\tINSTALL libynl.a"
43+
@$(INSTALL) -d $(DESTDIR)$(libdir)
44+
@$(INSTALL) -m 0644 libynl.a $(DESTDIR)$(libdir)/libynl.a
45+
@echo -e "\tINSTALL libynl headers"
46+
@$(INSTALL) -d $(DESTDIR)$(includedir)/ynl
47+
@$(INSTALL) -m 0644 lib/*.h $(DESTDIR)$(includedir)/ynl/
48+
@echo -e "\tINSTALL pyynl"
49+
@pip install --prefix=$(DESTDIR)$(prefix) .
50+
@make -C generated install
2451

25-
.PHONY: all clean distclean $(SUBDIRS)
52+
.PHONY: all clean distclean install $(SUBDIRS)

tools/net/ynl/generated/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*-user.c
22
*-user.h
3+
*.rst

tools/net/ynl/generated/Makefile

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,82 @@ ifeq ("$(DEBUG)","1")
77
CFLAGS += -g -fsanitize=address -fsanitize=leak -static-libasan
88
endif
99

10+
INSTALL ?= install
11+
prefix ?= /usr
12+
datarootdir ?= $(prefix)/share
13+
docdir ?= $(datarootdir)/doc
14+
includedir ?= $(prefix)/include
15+
1016
include ../Makefile.deps
1117

1218
YNL_GEN_ARG_ethtool:=--user-header linux/ethtool_netlink.h \
1319
--exclude-op stats-get
1420

15-
TOOL:=../ynl-gen-c.py
21+
TOOL:=../pyynl/ynl_gen_c.py
22+
TOOL_RST:=../pyynl/ynl_gen_rst.py
1623

24+
SPECS_DIR:=../../../../Documentation/netlink/specs
1725
GENS_PATHS=$(shell grep -nrI --files-without-match \
1826
'protocol: netlink' \
19-
../../../../Documentation/netlink/specs/)
20-
GENS=$(patsubst ../../../../Documentation/netlink/specs/%.yaml,%,${GENS_PATHS})
27+
$(SPECS_DIR))
28+
GENS=$(patsubst $(SPECS_DIR)/%.yaml,%,${GENS_PATHS})
2129
SRCS=$(patsubst %,%-user.c,${GENS})
2230
HDRS=$(patsubst %,%-user.h,${GENS})
2331
OBJS=$(patsubst %,%-user.o,${GENS})
2432

25-
all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI)
33+
SPECS_PATHS=$(wildcard $(SPECS_DIR)/*.yaml)
34+
SPECS=$(patsubst $(SPECS_DIR)/%.yaml,%,${SPECS_PATHS})
35+
RSTS=$(patsubst %,%.rst,${SPECS})
36+
37+
all: protos.a $(HDRS) $(SRCS) $(KHDRS) $(KSRCS) $(UAPI) $(RSTS)
2638

2739
protos.a: $(OBJS)
2840
@echo -e "\tAR $@"
2941
@ar rcs $@ $(OBJS)
3042

31-
%-user.h: ../../../../Documentation/netlink/specs/%.yaml $(TOOL)
43+
%-user.h: $(SPECS_DIR)/%.yaml $(TOOL)
3244
@echo -e "\tGEN $@"
3345
@$(TOOL) --mode user --header --spec $< -o $@ $(YNL_GEN_ARG_$*)
3446

35-
%-user.c: ../../../../Documentation/netlink/specs/%.yaml $(TOOL)
47+
%-user.c: $(SPECS_DIR)/%.yaml $(TOOL)
3648
@echo -e "\tGEN $@"
3749
@$(TOOL) --mode user --source --spec $< -o $@ $(YNL_GEN_ARG_$*)
3850

3951
%-user.o: %-user.c %-user.h
4052
@echo -e "\tCC $@"
4153
@$(COMPILE.c) $(CFLAGS_$*) -o $@ $<
4254

55+
%.rst: $(SPECS_DIR)/%.yaml $(TOOL_RST)
56+
@echo -e "\tGEN_RST $@"
57+
@$(TOOL_RST) -o $@ -i $<
58+
4359
clean:
4460
rm -f *.o
4561

4662
distclean: clean
47-
rm -f *.c *.h *.a
63+
rm -f *.c *.h *.a *.rst
4864

4965
regen:
5066
@../ynl-regen.sh
5167

52-
.PHONY: all clean distclean regen
68+
install-headers: $(HDRS)
69+
@echo -e "\tINSTALL generated headers"
70+
@$(INSTALL) -d $(DESTDIR)$(includedir)/ynl
71+
@$(INSTALL) -m 0644 *.h $(DESTDIR)$(includedir)/ynl/
72+
73+
install-rsts: $(RSTS)
74+
@echo -e "\tINSTALL generated docs"
75+
@$(INSTALL) -d $(DESTDIR)$(docdir)/ynl
76+
@$(INSTALL) -m 0644 $(RSTS) $(DESTDIR)$(docdir)/ynl/
77+
78+
install-specs:
79+
@echo -e "\tINSTALL specs"
80+
@$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl
81+
@$(INSTALL) -m 0644 ../../../../Documentation/netlink/*.yaml $(DESTDIR)$(datarootdir)/ynl/
82+
@$(INSTALL) -d $(DESTDIR)$(datarootdir)/ynl/specs
83+
@$(INSTALL) -m 0644 $(SPECS_DIR)/*.yaml $(DESTDIR)$(datarootdir)/ynl/specs/
84+
85+
install: install-headers install-rsts install-specs
86+
87+
.PHONY: all clean distclean regen install install-headers install-rsts install-specs
5388
.DEFAULT_GOAL: all

tools/net/ynl/lib/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
__pycache__/
21
*.d

tools/net/ynl/lib/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ ynl.a: $(OBJS)
1919

2020
clean:
2121
rm -f *.o *.d *~
22-
rm -rf __pycache__
2322

2423
distclean: clean
2524
rm -f *.a

0 commit comments

Comments
 (0)