Comments (8)
Without having looked at the code yet, I may add some input on this:
I encountered the problem of including a git version in scripts or binaries a few times now and wrote a blog entry about using .gitattributes
and $Format:%h$
strings.
In short, you create a special variable or constant which is assigned the value of $Format:%h$
in the source code and add the respective file to your .gitattributes
. During archive creation with git archive ...
or e.g. downloading from GitHub this will then be replaced with the commit hash. When using this variable you check for the substring Format:
and if it does not exist you know you have a commit hash in your variable.
During build you should then either always build from git archives or add a step in the makefile which checks if the .git
dir is present and try to export the commit hash with git rev-parse ...
, then replace the constant during compilation. I know Go can do that with a compiler flag, I am not sure about C but there ought to be some way to override #DEFINE
's or something?
Any other process I could think of either requires that the user has git
installed and builds from git clones, uses client-side hooks which git does not allow to be checked in and out for good reason (think arbitrary code-execution) or requires a VERSION
file to be manually updated every time.
from slirp4netns.
Thanks for the info!
@giuseppe Any thought?
from slirp4netns.
would something like:
$ git diff
diff --git a/Makefile.am b/Makefile.am
index 318f448..f180ea4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -66,6 +66,7 @@ libqemu_slirp_a_SOURCES = \
libslirp_a_SOURCES = rd235_libslirp/src/qemu2libslirp.c
+slirp4netns_CFLAGS = $(AM_CFLAGS) -DVERSION=\""$(shell git rev-parse HEAD)"\"
slirp4netns_SOURCES = main.c slirp4netns.c
slirp4netns_LDADD = libslirp.a libqemu_slirp.a
man1_MANS = slirp4netns.1
diff --git a/main.c b/main.c
index 5ec4693..224a3b1 100644
--- a/main.c
+++ b/main.c
@@ -242,6 +242,8 @@ static void usage(const char *argv0)
printf("-r, --ready-fd=FD specify the FD to write to when the network is configured\n");
printf("-m, --mtu=MTU specify MTU (default=1500, max=65521)\n");
printf("-6, --enable-ipv6 enable IPv6 (experimental)\n");
+ printf("\n");
+ printf("Version: %s\n", VERSION);
}
struct options {
be fine?
I will polish and open a PR if it is fine for you
from slirp4netns.
Thanks, SGTM
from slirp4netns.
As I said above, I think that will break if you build from a downloaded tarball where git rev-parse
cannot find any commit information.
from slirp4netns.
we could create a .tarball-distribution
file if creating the tarball with "make dist" but I am not sure creating a tarball from github can simulate that. How would we know the commit?
from slirp4netns.
I've opened a PR here: #34
If git fails, then the version specified in the configure.ac
file is used
from slirp4netns.
It has been a while since I touched C code but to iterate on the above I would do something like this:
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..cba1251
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+main.c export-subst
\ No newline at end of file
diff --git a/Makefile.am b/Makefile.am
index 318f448..6b1879c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -66,6 +66,9 @@ libqemu_slirp_a_SOURCES = \
libslirp_a_SOURCES = rd235_libslirp/src/qemu2libslirp.c
+VERSION := $(shell [ -d .git ] && echo "-DVERSION=\"$$(git describe --always --abbrev)\"")
+
+slirp4netns_CFLAGS = $(AM_CFLAGS) $(VERSION)
slirp4netns_SOURCES = main.c slirp4netns.c
slirp4netns_LDADD = libslirp.a libqemu_slirp.a
man1_MANS = slirp4netns.1
diff --git a/main.c b/main.c
index 5ec4693..38ce8d3 100644
--- a/main.c
+++ b/main.c
@@ -233,6 +233,10 @@ static int parent(int sock, int exit_fd, unsigned int mtu, bool enable_ipv6)
return 0;
}
+#ifndef VERSION
+#define VERSION "$Format:%h$"
+#endif
+
static void usage(const char *argv0)
{
printf("Usage: %s [OPTION]... PID TAPNAME\n", argv0);
@@ -242,6 +246,8 @@ static void usage(const char *argv0)
printf("-r, --ready-fd=FD specify the FD to write to when the network is configured\n");
printf("-m, --mtu=MTU specify MTU (default=1500, max=65521)\n");
printf("-6, --enable-ipv6 enable IPv6 (experimental)\n");
+ printf("\n");
+ printf("Version: %s\n", VERSION);
}
struct options {
That fails to compile though with <command-line>: error: ‘e09a981’ undeclared (first use in this function)
.. probably screwed up quoting somewhere.
Edit: fixed that, see 740b346
from slirp4netns.
Related Issues (20)
- Instances aren't able to handle jumbo udp packets. HOT 1
- slirp4netns startup issue for path-based configuration
- Please change the "master branch to "main".
- Can't seem to filter packets from slirp4netns HOT 2
- Interaction with bwrap --dev HOT 1
- Load search domains from /etc/resolv.conf
- Rootless Podman can not create containers that bind to privileged (< 1024) ports HOT 3
- rootless Podman-compose containers cannot reach eachother HOT 1
- built-in dns broken with enable-sandbox HOT 1
- port is not bound on all IPs on the host when using --network=slirp4netns:port_handler=slirp4netns
- `--enable-sandbox` is not compatible with `--userns-path=... --netns-type=path` HOT 1
- Cannot pull images with rootless docker on openSUSE Tumbleweed HOT 2
- Access a service from the same ip:port in both a container and the host/lan (docker rootless) HOT 1
- [NixOS] Handling multi-layer and parent symlinks for `/etc/resolv.conf` HOT 2
- Consider supporting TUN in addition to TAP (may achieve better performance, slightly)
- How to configure port forwarding? HOT 1
- slirp4netns general protection fault
- nonroot binary install HOT 2
- outbound_addr is not applied HOT 1
- DNS server of slirp4netns only forwards to primary DNS server of Host system HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slirp4netns.