summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJengHyun Kang <jhyuni.kang@samsung.com>2016-03-31 16:47:14 +0900
committerJengHyun Kang <jhyuni.kang@samsung.com>2016-03-31 16:47:14 +0900
commit4e2e1fbc347948d70a65535f81f523af815bc8b9 (patch)
tree6417f37dc383c159b2e5ab86b3e298534d69a237
parent7e401391883fd87c2477327fa63e28f6ec4eab26 (diff)
downloadxkeyboard-config-4e2e1fbc347948d70a65535f81f523af815bc8b9.tar.gz
xkeyboard-config-4e2e1fbc347948d70a65535f81f523af815bc8b9.tar.bz2
xkeyboard-config-4e2e1fbc347948d70a65535f81f523af815bc8b9.zip
Compile a pre-cached keymap file when build timesubmit/tizen/20160405.075340
-rw-r--r--Makefile.am2
-rw-r--r--cache/Makefile.am7
-rw-r--r--cache/cache.c198
-rw-r--r--configure.ac3
-rw-r--r--packaging/xkeyboard-config.spec7
5 files changed, 216 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 4cc82541..e56bb8b3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,6 @@
AUTOMAKE_OPTIONS = foreign
-SUBDIRS = compat geometry keycodes po rules symbols types docs man
+SUBDIRS = compat geometry keycodes po rules symbols types docs man cache
pkgconfigdir = $(datadir)/pkgconfig
pkgconfig_DATA = xkeyboard-config.pc
diff --git a/cache/Makefile.am b/cache/Makefile.am
new file mode 100644
index 00000000..f8a57d1c
--- /dev/null
+++ b/cache/Makefile.am
@@ -0,0 +1,7 @@
+bin_PROGRAMS = cache
+
+AM_CPPFLAGS = $(GCC_CFLAGS) -I$(top_srcdir)
+
+cache_LDADD = $(XKBCOMMON_LIBS)
+cache_CFLAGS = $(XKBCOMMON_CFLAGS)
+cache_SOURCES = cache.c
diff --git a/cache/cache.c b/cache/cache.c
new file mode 100644
index 00000000..5420e990
--- /dev/null
+++ b/cache/cache.c
@@ -0,0 +1,198 @@
+#include <xkbcommon/xkbcommon.h>
+#include <stdio.h>
+#include <string.h>
+
+#define DFLT_RULES "evdev"
+#define DFLT_MODEL "pc105"
+#define DFLT_LAYOUT "us"
+
+#define STRLEN(s) (s ? strlen(s) : 0)
+#define STR(s) (s ? s : "")
+
+void parseArgs(int argc, char **argv, struct xkb_rule_names *names)
+{
+ int i;
+ char *tmp, *rule_path;
+ FILE *file;
+ int len_rule_path;
+ char buf[1024] = {0, };
+
+ if (argc < 2)
+ {
+ rule_path = getenv("RULE_FILE_PATH");
+
+ printf("Cache file rule from %s file\n", rule_path);
+
+ file = fopen(rule_path, "r");
+ if (!file) return;
+
+ while (!feof(file))
+ {
+ fscanf(file, "%s", buf);
+ if (strstr(buf, "rules") > 0)
+ {
+ tmp = strtok(buf, "=");
+ tmp = strtok(NULL, "=");
+ if (tmp) names->rules= strdup(tmp);
+ }
+ else if (strstr(buf, "model") > 0)
+ {
+ tmp = strtok(buf, "=");
+ tmp = strtok(NULL, "=");
+ if (tmp) names->model= strdup(tmp);
+ }
+ else if (strstr(buf, "layout") > 0)
+ {
+ tmp = strtok(buf, "=");
+ tmp = strtok(NULL, "=");
+ if (tmp) names->layout= strdup(tmp);
+ }
+ else if (strstr(buf, "variant") > 0)
+ {
+ tmp = strtok(buf, "=");
+ tmp = strtok(NULL, "=");
+ if (tmp) names->variant= strdup(tmp);
+ }
+ else if (strstr(buf, "options") > 0)
+ {
+ tmp = strtok(buf, "=");
+ tmp = strtok(NULL, "=");
+ if (tmp) names->options= strdup(tmp);
+ }
+ }
+
+ fclose(file);
+ }
+ else
+ {
+ for (i = 1; i < argc; i++)
+ {
+ printf("Cache file rule from argument\n");
+
+ if (strstr(argv[i], "-rules") > 0)
+ {
+ tmp = strtok(argv[i], "=");
+ tmp = strtok(NULL, "=");
+ names->rules= strdup(tmp);
+ }
+ else if (strstr(argv[i], "-model") > 0)
+ {
+ tmp = strtok(argv[i], "=");
+ tmp = strtok(NULL, "=");
+ names->model = strdup(tmp);
+ }
+ else if (strstr(argv[i], "-layout") > 0)
+ {
+ tmp = strtok(argv[i], "=");
+ tmp = strtok(NULL, "=");
+ names->layout = strdup(tmp);
+ }
+ else if (strstr(argv[i], "-variant") > 0)
+ {
+ tmp = strtok(argv[i], "=");
+ tmp = strtok(NULL, "=");
+ names->variant = strdup(tmp);
+ }
+ else if (strstr(argv[i], "-options") > 0)
+ {
+ tmp = strtok(argv[i], "=");
+ tmp = strtok(NULL, "=");
+ names->options = strdup(tmp);
+ }
+ }
+ }
+}
+
+void checkRules(struct xkb_rule_names *names)
+{
+ if (!names->rules)
+ {
+ printf("Set default rules: %s\n", DFLT_RULES);
+ names->rules = strdup(DFLT_RULES);
+ }
+ else printf("Current rules: %s\n", names->rules);
+
+ if (!names->model)
+ {
+ printf("Set default model: %s\n", DFLT_MODEL);
+ names->model = strdup(DFLT_MODEL);
+ }
+ else printf("Current model: %s\n", names->model);
+
+ if (!names->layout)
+ {
+ printf("Set default layout: %s\n", DFLT_LAYOUT);
+ names->layout = strdup(DFLT_LAYOUT);
+ }
+ else printf("Current layout: %s\n", names->layout);
+
+ if (!names->variant) printf("There is no variant\n");
+ else printf("Current variant: %s\n", names->variant);
+
+ if (!names->options) printf("There is no options\n");
+ else printf("Current options: %s\n", names->options);
+}
+
+int main(int argc, char **argv)
+{
+ struct xkb_context *ctx;
+ struct xkb_keymap *map;
+ struct xkb_rule_names names;
+ char *keymap_path;
+ char *keymap_string;
+ char *cache_path;
+ FILE *file = NULL;
+ int len_cache_path;
+
+ memset(&names, 0, sizeof(names));
+
+ parseArgs(argc, argv, &names);
+
+ checkRules(&names);
+
+ ctx = xkb_context_new(0);
+ if (!ctx) {
+ printf("Failed to generate a xkb context file\n");
+ return 0;
+ }
+
+ if (!keymap_path) keymap_path = getenv("LOCAL_KEYMAP_PATH");
+
+ xkb_context_include_path_append(ctx, keymap_path);
+
+ map = xkb_map_new_from_names(ctx, &names, 0);
+
+ keymap_string = xkb_map_get_as_string(map);
+ if (!keymap_string) {
+ printf("Failed convert keymap to string\n");
+ return 0;
+ }
+
+ len_cache_path = STRLEN(names.rules) + STRLEN(names.model) + STRLEN(names.layout) + STRLEN(names.variant) + STRLEN(names.options) + sizeof("xkb") + 5;
+ cache_path = (char *)calloc(1, len_cache_path);
+ snprintf(cache_path, len_cache_path, "%s-%s-%s-%s-%s.xkb", STR(names.rules), STR(names.model), STR(names.layout), STR(names.variant), STR(names.options));
+
+ file = fopen(cache_path, "w");
+ if (fputs(keymap_string, file) < 0)
+ {
+ printf("Failed to write keymap file: %s\n", cache_path);
+ fclose(file);
+ unlink(cache_path);
+ }
+ else
+ {
+ printf("Success to make keymap file: %s\n", cache_path);
+ fclose(file);
+ }
+
+ if (names.rules) free(names.rules);
+ if (names.model) free(names.model);
+ if (names.layout) free(names.layout);
+ if (names.variant) free(names.variant);
+ if (names.options) free(names.options);
+ if (cache_path) free(cache_path);
+ xkb_keymap_unref(map);
+ xkb_context_unref(ctx);
+
+ return 0;
+}
diff --git a/configure.ac b/configure.ac
index b71b2a10..4c95ab9c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -22,6 +22,8 @@ AC_ARG_WITH( tizen_profile,
AC_CHECK_FILE(/usr/share/X11/xkb/tizen_key_layout.txt, [key_layout_exist=yes], [key_layout_exist=no])
AM_CONDITIONAL(KEY_LAYOUT_EXIST, [test "x$key_layout_exist" = xyes])
+PKG_CHECK_MODULES(XKBCOMMON, [xkbcommon])
+
AC_ARG_WITH( xkb_base,
[AS_HELP_STRING([--with-xkb-base=DIR],[XKB base path @<:@DATADIR/X11/xkb@:>@])],
xkb_base="$withval",
@@ -115,6 +117,7 @@ types/Makefile
xkeyboard-config.pc
docs/Makefile
man/Makefile
+cache/Makefile
])
echo '***********************************************************'
diff --git a/packaging/xkeyboard-config.spec b/packaging/xkeyboard-config.spec
index ae1256a7..601202ea 100644
--- a/packaging/xkeyboard-config.spec
+++ b/packaging/xkeyboard-config.spec
@@ -28,6 +28,7 @@ Requires(pre): /usr/bin/rm
%else
BuildRequires: xkb-tizen-data
%endif
+BuildRequires: pkgconfig(xkbcommon)
%global TZ_SYS_RO_SHARE %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:/usr/share}
%global TZ_SYS_VAR %{?TZ_SYS_VAR:%TZ_SYS_VAR}%{!?TZ_SYS_VAR:/opt/var}
@@ -85,6 +86,11 @@ sed -i 's/evdev/tizen_%{?profile}/g' %{buildroot}/%{TZ_SYS_RO_SHARE}/X11/xkb/rul
ln -sf tizen_"%{?profile}" %{buildroot}/%{TZ_SYS_RO_SHARE}/X11/xkb/rules/evdev
export LOCAL_KEYMAP_PATH=%{buildroot}/%{TZ_SYS_RO_SHARE}/X11/xkb
./remove_unused_files.sh
+export RULE_FILE_PATH=%{TZ_SYS_RO_SHARE}/X11/xkb/xkb.rule
+%{buildroot}%{_bindir}/cache
+rm %{buildroot}%{_bindir}/cache
+mkdir -p %{buildroot}/%{TZ_SYS_VAR}/lib/xkb/
+cp *.xkb %{buildroot}/%{TZ_SYS_VAR}/lib/xkb/
#for license notification
mkdir -p %{buildroot}/%{TZ_SYS_RO_SHARE}/license
@@ -99,3 +105,4 @@ cp -a %{_builddir}/%{buildsubdir}/COPYING %{buildroot}/%{TZ_SYS_RO_SHARE}/licens
%{TZ_SYS_RO_SHARE}/license/%{name}
%{_datadir}/X11/xkb/
%{_datadir}/pkgconfig/*.pc
+%{TZ_SYS_VAR}/lib/xkb/*.xkb