Remove useless files in build and add icon-theme-installer

This commit is contained in:
Bertrand Lorentz 2010-06-18 23:16:10 +02:00
parent 9c7a75633f
commit b5b4d6d09b
5 changed files with 178 additions and 304 deletions

View file

@ -1,258 +0,0 @@
using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Collections.Generic;
public static class DllMapVerifier
{
private struct DllImportRef
{
public DllImportRef (string name, int line, int column)
{
Name = name;
Line = line;
Column = column;
}
public string Name;
public int Line;
public int Column;
}
private static Dictionary<string, List<DllImportRef>> dll_imports
= new Dictionary<string, List<DllImportRef>> ();
private static List<string> ignore_dlls = new List<string> ();
private static List<string> config_dlls = null;
public static int Main (string [] args)
{
LoadConfigDlls (args[0]);
foreach (string file in args) {
LoadDllImports (file);
}
return VerifyDllImports (args[0]) ? 0 : 1;
}
private static bool VerifyDllImports (string configFile)
{
int total_unmapped_count = 0;
foreach (KeyValuePair<string, List<DllImportRef>> dll_import in dll_imports) {
int file_unmapped_count = 0;
foreach (DllImportRef dll_import_ref in dll_import.Value) {
if (config_dlls != null && config_dlls.Contains (dll_import_ref.Name)) {
continue;
}
if (file_unmapped_count++ == 0) {
Console.Error.WriteLine ("Unmapped DLLs in file: {0}", dll_import.Key);
}
Console.Error.WriteLine (" + {0} : {1},{2}", dll_import_ref.Name,
dll_import_ref.Line, dll_import_ref.Column);
}
total_unmapped_count += file_unmapped_count;
}
if (total_unmapped_count > 0) {
Console.Error.WriteLine ();
Console.Error.WriteLine (" If any DllImport above is explicitly allowed to be unmapped,");
Console.Error.WriteLine (" add an 'willfully unmapped' comment to the inside of the attribute:");
Console.Error.WriteLine ();
Console.Error.WriteLine (" [DllImport (\"libX11.so.6\") /* willfully unmapped */]");
Console.Error.WriteLine ();
}
if (total_unmapped_count > 0 && config_dlls == null) {
Console.Error.WriteLine ("No config file for DLL mapping was found ({0})", configFile);
}
return total_unmapped_count == 0;
}
private static void LoadDllImports (string csFile)
{
if (csFile.StartsWith ("-i")) {
ignore_dlls.Add (csFile.Substring (2));
return;
}
if (Path.GetExtension (csFile) == ".cs" && File.Exists (csFile)) {
List<DllImportRef> dll_import_refs = null;
foreach (DllImportRef dll_import in ParseFileForDllImports (csFile)) {
if (ignore_dlls.Contains (dll_import.Name)) {
continue;
}
if (dll_import_refs == null) {
dll_import_refs = new List<DllImportRef> ();
}
dll_import_refs.Add (dll_import);
}
if (dll_import_refs != null) {
dll_imports.Add (csFile, dll_import_refs);
}
}
}
private static void LoadConfigDlls (string configFile)
{
try {
XmlTextReader config = new XmlTextReader (configFile);
config_dlls = new List<string> ();
while (config.Read ()) {
if (config.NodeType == XmlNodeType.Element &&
config.Name == "dllmap") {
string dll = config.GetAttribute ("dll");
if (!config_dlls.Contains (dll)) {
config_dlls.Add (dll);
}
}
}
} catch {
}
}
#region DllImport parser
private static StreamReader reader;
private static int reader_line;
private static int reader_col;
private static IEnumerable<DllImportRef> ParseFileForDllImports (string file)
{
reader_line = 1;
reader_col = 1;
using (reader = new StreamReader (file)) {
char c;
bool in_paren = false;
bool in_attr = false;
bool in_dll_attr = false;
bool in_string = false;
bool in_comment = false;
int dll_line = 1, dll_col = 1;
string dll_string = null;
string dll_comment = null;
while ((c = (char)reader.Peek ()) != Char.MaxValue) {
switch (c) {
case ' ':
case '\t': Read (); break;
case '[':
in_attr = true;
dll_string = null;
dll_comment = null;
dll_line = reader_line;
dll_col = reader_col;
Read ();
break;
case '(': Read (); in_paren = true; break;
case ')': Read (); in_paren = false; break;
case '"':
Read ();
if (dll_string == null && in_dll_attr && in_paren && !in_string) {
in_string = true;
}
break;
case '/':
Read ();
if ((char)reader.Peek () == '*') {
Read ();
if (in_dll_attr && !in_comment) {
in_comment = true;
}
}
break;
case ']':
if (in_dll_attr && dll_string != null && dll_comment != "willfully unmapped") {
yield return new DllImportRef (dll_string, dll_line, dll_col);
}
in_attr = false;
in_dll_attr = false;
Read ();
break;
default:
if (!in_dll_attr && in_attr && ReadDllAttribute ()) {
in_dll_attr = true;
} else if (in_dll_attr && in_string) {
dll_string = ReadDllString ();
in_string = false;
} else if (in_dll_attr && in_comment) {
dll_comment = ReadDllComment ();
in_comment = false;
} else {
Read ();
}
break;
}
}
}
}
private static bool ReadDllAttribute ()
{
return
Read () == 'D' &&
Read () == 'l' &&
Read () == 'l' &&
Read () == 'I' &&
Read () == 'm' &&
Read () == 'p' &&
Read () == 'o' &&
Read () == 'r' &&
Read () == 't';
}
private static string ReadDllString ()
{
StringBuilder builder = new StringBuilder (32);
while (true) {
char c = Read ();
if (Char.IsLetterOrDigit (c) || c == '.' || c == '-' || c == '_') {
builder.Append (c);
} else {
break;
}
}
return builder.ToString ();
}
private static string ReadDllComment ()
{
StringBuilder builder = new StringBuilder ();
char lc = Char.MaxValue;
while (true) {
char c = Read ();
if (c == Char.MaxValue || (c == '/' && lc == '*')) {
break;
} else if (lc != Char.MaxValue) {
builder.Append (lc);
}
lc = c;
}
return builder.ToString ().Trim ();
}
private static char Read ()
{
char c = (char)reader.Read ();
if (c == '\n') {
reader_line++;
reader_col = 1;
} else {
reader_col++;
}
return c;
}
#endregion
}

View file

@ -1,18 +1,6 @@
SUBDIRS = m4
DLL_MAP_VERIFIER_ASSEMBLY = dll-map-verifier.exe
ALL_TARGETS = $(DLL_MAP_VERIFIER_ASSEMBLY)
all: $(ALL_TARGETS)
$(DLL_MAP_VERIFIER_ASSEMBLY): DllMapVerifier.cs
$(MCS) -out:$@ $<
EXTRA_DIST = \
private-icon-theme-installer \
DllMapVerifier.cs \
dll-map-makefile-verifier
icon-theme-installer
CLEANFILES = *.exe *.mdb
MAINTAINERCLEANFILES = Makefile.in

View file

@ -1,10 +0,0 @@
#!/usr/bin/env bash
if [ -f $2 ]; then
# Lame, but better than nothing
grep $(basename $2) $1 | grep module_SCRIPTS &>/dev/null || {
echo "Assembly has corresponding .config file, but it was not found in module_SCRIPTS in Makefile.am" 2>&1
exit 1
}
fi

177
build/icon-theme-installer Executable file
View file

@ -0,0 +1,177 @@
#!/usr/bin/env bash
# icon-theme-installer
# Copyright (C) 2006 Novell, Inc.
# Written by Aaron Bockover <abock@gnome.org>
# Licensed under the MIT/X11 license
#
# This script is meant to be invoked from within a Makefile/Makefile.am
# in the install-data-local and uninstall-data sections. It handles the
# task of properly installing icons into the icon theme. It requires a
# few arguments to set up its environment, and a list of files to be
# installed. The format of the file list is critical:
#
# <category>,<local-src-file-name>
#
# apps,music-player-banshee.svg
# apps,music-player-banshee-16.png
# apps,music-player-banshee-22.png
#
# <category> is the icon theme category, for instance, apps, devices,
# actions, emblems...
#
# <local-src-file-name> must have a basename in the form of:
#
# proper-theme-name[-<SIZE>].<EXTENSION>
#
# Where <SIZE> should be either nothing, which will default to scalable
# or \-[0-9]{2}, which will expand to <SIZE>x<SIZE>. For example:
#
# music-player-banshee-16.png
#
# The <SIZE> here is -16 and will expand to 16x16 per the icon theme spec
#
# What follows is an example Makefile.am for icon theme installation:
#
# ---------------
# theme=hicolor
# themedir=$(datadir)/icons/$(theme)
# theme_icons = \
# apps,music-player-banshee.svg \
# apps,music-player-banshee-16.png \
# apps,music-player-banshee-22.png \
# apps,music-player-banshee-24.png \
# apps,music-player-banshee-32.png
#
# install_icon_exec = $(top_srcdir)/build/icon-theme-installer -t $(theme) -s $(srcdir) -d "x$(DESTDIR)" -b $(themedir) -m "$(mkinstalldirs)" -x "$(INSTALL_DATA)"
# install-data-local:
# $(install_icon_exec) -i $(theme_icons)
#
# uninstall-hook:
# $(install_icon_exec) -u $(theme_icons)
#
# MAINTAINERCLEANFILES = Makefile.in
# EXTRA_DIST = $(wildcard *.svg *.png)
# ---------------
#
# Arguments to this program:
#
# -i : Install
# -u : Uninstall
# -t <theme> : Theme name (hicolor)
# -b <dir> : Theme installation dest directory [x$(DESTDIR)] - Always prefix
# this argument with x; it will be stripped but will act as a
# placeholder for zero $DESTDIRs (only set by packagers)
# -d <dir> : Theme installation directory [$(hicolordir)]
# -s <dir> : Source directory [$(srcdir)]
# -m <exec> : Command to exec for directory creation [$(mkinstalldirs)]
# -x <exec> : Command to exec for single file installation [$(INSTALL_DATA)]
# <remainging> : All remainging should be category,filename pairs
while getopts "iut:b:d:s:m:x:" flag; do
case "$flag" in
i) INSTALL=yes ;;
u) UNINSTALL=yes ;;
t) THEME_NAME=$OPTARG ;;
d) INSTALL_DEST_DIR=${OPTARG##x} ;;
b) INSTALL_BASE_DIR=$OPTARG ;;
s) SRC_DIR=$OPTARG ;;
m) MKINSTALLDIRS_EXEC=$OPTARG ;;
x) INSTALL_DATA_EXEC=$OPTARG ;;
esac
done
shift $(($OPTIND - 1))
if test "x$INSTALL" = "xyes" -a "x$UNINSTALL" = "xyes"; then
echo "Cannot pass both -i and -u"
exit 1
elif test "x$INSTALL" = "x" -a "x$UNINSTALL" = "x"; then
echo "Must path either -i or -u"
exit 1
fi
if test -z "$THEME_NAME"; then
echo "Theme name required (-t hicolor)"
exit 1
fi
if test -z "$INSTALL_BASE_DIR"; then
echo "Base theme directory required [-d \$(hicolordir)]"
exit 1
fi
if test ! -x $(echo "$MKINSTALLDIRS_EXEC" | cut -f1 -d' '); then
echo "Cannot find '$MKINSTALLDIRS_EXEC'; You probably want to pass -m \$(mkinstalldirs)"
exit 1
fi
if test ! -x $(echo "$INSTALL_DATA_EXEC" | cut -f1 -d' '); then
echo "Cannot find '$INSTALL_DATA_EXEC'; You probably want to pass -x \$(INSTALL_DATA)"
exit 1
fi
if test -z "$SRC_DIR"; then
SRC_DIR=.
fi
for icon in $@; do
size=$(echo $icon | sed s/[^0-9]*//g)
category=$(echo $icon | cut -d, -f1)
build_name=$(echo $icon | cut -d, -f2)
install_name=$(echo $build_name | sed "s/[0-9]//g; s/-\././")
install_name=$(basename $install_name)
if test -z $size; then
size=scalable;
else
size=${size}x${size};
fi
install_dir=${INSTALL_DEST_DIR}${INSTALL_BASE_DIR}/$size/$category
install_path=$install_dir/$install_name
if test "x$INSTALL" = "xyes"; then
echo "Installing $size $install_name into $THEME_NAME icon theme"
$($MKINSTALLDIRS_EXEC $install_dir) || {
echo "Failed to create directory $install_dir"
exit 1
}
$($INSTALL_DATA_EXEC $SRC_DIR/$build_name $install_path) || {
echo "Failed to install $SRC_DIR/$build_name into $install_path"
exit 1
}
if test ! -e $install_path; then
echo "Failed to install $SRC_DIR/$build_name into $install_path"
exit 1
fi
else
if test -e $install_path; then
echo "Removing $size $install_name from $THEME_NAME icon theme"
rm $install_path || {
echo "Failed to remove $install_path"
exit 1
}
fi
fi
done
gtk_update_icon_cache_bin="$((which gtk-update-icon-cache || echo /opt/gnome/bin/gtk-update-icon-cache)2>/dev/null)"
gtk_update_icon_cache="$gtk_update_icon_cache_bin -f -t $INSTALL_BASE_DIR"
if test -z "$INSTALL_DEST_DIR"; then
if test -x $gtk_update_icon_cache_bin; then
echo "Updating GTK icon cache"
$gtk_update_icon_cache
else
echo "*** Icon cache not updated. Could not execute $gtk_update_icon_cache_bin"
fi
else
echo "*** Icon cache not updated. After (un)install, run this:"
echo "*** $gtk_update_icon_cache"
fi

View file

@ -1,23 +0,0 @@
#!/usr/bin/env bash
mkinstalldirs=$1; shift
install_data=$1; shift
action=$1; shift
dest_dir=$1; shift
src_dir=$1; shift
for icon in $@; do
dest_dir_build="${dest_dir}/icons/hicolor/$(dirname ${icon})"
if [[ ${action} == "-i" || ${action} == "-il" ]]; then
src_file="${src_dir}/ThemeIcons/${icon}"
$mkinstalldirs "${dest_dir_build}" &>/dev/null
if [[ ${action} == "-i" ]]; then
echo "Installing private icon theme icon: ${icon}"
fi
$install_data "${src_file}" "${dest_dir_build}"
else
echo "Uninstalling private icon theme icon: ${icon}"
rm -f "${dest_dir_build}/$(basename ${icon})"
fi
done