Add StructValidator accepted/tizen/unified/20200605.020507 submit/tizen/20200603.230233
authorWonyoung Choi <wy80.choi@samsung.com>
Wed, 3 Jun 2020 06:41:52 +0000 (15:41 +0900)
committerWonyoung Choi <wy80.choi@samsung.com>
Wed, 3 Jun 2020 23:02:16 +0000 (08:02 +0900)
Change-Id: Ib7bd0b9f609af564a9cd68b90e7825fde112426c

21 files changed:
Tizen.GBS.BuildTasks/Tizen.GBS.ImportAfter.targets [deleted file]
Tools/dotnet-build.sh [deleted file]
Tools/dotnet-wrapper.sh [deleted file]
Tools/dummypack.csproj [deleted file]
Tools/retry.sh [deleted file]
Tools/timeout.sh [deleted file]
packaging/dotnet-build-tools.spec
tools/StructValidator/StructValidator.deps.json [new file with mode: 0644]
tools/StructValidator/StructValidator.dll [new file with mode: 0644]
tools/StructValidator/StructValidator.pdb [new file with mode: 0644]
tools/StructValidator/StructValidator.runtimeconfig.json [new file with mode: 0644]
tools/StructValidator/native/Makefile [new file with mode: 0644]
tools/StructValidator/native/common.h [new file with mode: 0644]
tools/StructValidator/native/main.c [new file with mode: 0644]
tools/dotnet-build.sh [new file with mode: 0755]
tools/dotnet-validate-struct.sh [new file with mode: 0755]
tools/dotnet-wrapper.sh [new file with mode: 0755]
tools/dummypack.csproj [new file with mode: 0644]
tools/retry.sh [new file with mode: 0755]
tools/timeout.sh [new file with mode: 0755]
update-tools.sh [new file with mode: 0755]

diff --git a/Tizen.GBS.BuildTasks/Tizen.GBS.ImportAfter.targets b/Tizen.GBS.BuildTasks/Tizen.GBS.ImportAfter.targets
deleted file mode 100644 (file)
index d8aab8d..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
-  <PropertyGroup Condition=" '$(UsingRPMMacro)' == 'true' ">
-
-    <!-- DocumentationFile -->
-    <NoWarn>$(NoWarn);1591</NoWarn>
-    <DocumentationFile Condition="'$(DocumentationFile)' == ''">$(OutputPath)$(AssemblyName).xml</DocumentationFile>
-
-  </PropertyGroup>
-
-</Project>
diff --git a/Tools/dotnet-build.sh b/Tools/dotnet-build.sh
deleted file mode 100755 (executable)
index ef9b020..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-#!/bin/bash
-
-SCRIPT_FILE=$(readlink -f $0)
-SCRIPT_DIR=$(dirname $SCRIPT_FILE)
-
-TIMEOUT_CMD="$SCRIPT_DIR/timeout.sh"
-RETRY_CMD="$SCRIPT_DIR/retry.sh"
-
-usage() {
-  echo "usage: "
-  echo " $0 restore <project> [-s <source>] ..."
-  echo " $0 build <project> [-c <configuration>] ..."
-  echo " $0 pack <project> [-c <configuration>] [-v <version>] ..."
-  echo " $0 install <project> [-t <type>]"
-}
-
-exit_on_error() {
-  if [ $1 -ne 0 ]; then
-    echo "Error $1"
-    exit $1
-  fi
-}
-
-run_dotnet() {
-  echo "+ dotnet $@"
-  $RETRY_CMD $TIMEOUT_CMD 600 dotnet $@ /nologo
-  exit_on_error $?
-}
-
-cmd_restore() {
-  local OPTS=""
-  [ -n "$SOURCE" ] && OPTS="$OPTS -s $SOURCE"
-  run_dotnet restore $PROJECT $OPTS $@
-}
-
-cmd_build() {
-  cmd_restore # restore first
-  local OPTS=""
-  [ -n "$CONFIGURATION" ] && OPTS="$OPTS -c $CONFIGURATION"
-  run_dotnet build --no-restore $PROJECT $OPTS $@ /p:UsingRPMMacro=true
-}
-
-cmd_pack() {
-  local OPTS=""
-  [ -n "$CONFIGURATION" ] && OPTS="$OPTS -c $CONFIGURATION"
-  [ -n "$VERSION" ] && OPTS="$OPTS /p:Version=$VERSION"
-  if [[ $PROJECT == *".nuspec" ]]; then
-    NUSPECPATH=$(readlink -f $PROJECT)
-    OPTS="$OPTS /p:NuspecFile=$NUSPECPATH /p:PWD=$PWD"
-    TMPDIR=$(mktemp -d)
-    cp $SCRIPT_DIR/dummypack.csproj $TMPDIR
-    PROJECT=$TMPDIR/dummypack.csproj
-    run_dotnet restore $PROJECT -s /nuget/
-  fi
-  run_dotnet pack --no-build --no-restore $PRE_OPTS $PROJECT $OPTS $@ /p:UsingRPMMacro=true
-}
-
-cmd_install() {
-  local DEST=$1; shift
-  mkdir -p $DEST
-  if [[ $TYPE == "assembly" ]]; then
-    find $PROJECT/bin -name $PROJECT.dll -not -path "*/ref/*" -exec install -p -m 644 {} $DEST \;
-  elif [[ $TYPE == "nupkg" ]]; then
-    find . -name "$PROJECT.[0-9]*.nupkg" -exec install -p -m 644 {} $DEST \;
-  fi
-}
-
-#########################################################################
-
-# Parse arguments
-
-while getopts "s:c:v:t:" o; do
-  case "$o" in
-    s) SOURCE=${OPTARG} ;;
-    c) CONFIGURATION=${OPTARG} ;;
-    v) VERSION=${OPTARG} ;;
-    t) TYPE=${OPTARG} ;;
-    *) usage; exit 1 ;;
-  esac
-done
-shift $((OPTIND-1))
-
-if [ $# -lt 2 ]; then
-  usage; exit 1
-fi
-
-CMD=$1; shift
-PROJECT=$1; shift
-
-export DOTNET_CLI_TELEMETRY_OPTOUT=1
-export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
-
-# Dump
-echo "----------------------------------------------"
-echo "CMD=$CMD"
-echo "PROJECT=$PROJECT"
-echo "SOURCE=$SOURCE"
-echo "CONFIGURATION=$CONFIGURATION"
-echo "VERSION=$VERSION"
-echo "TYPE=$TYPE"
-echo "REST ARGS=$@"
-echo "----------------------------------------------"
-
-case $CMD in
-  restore) cmd_restore $@ ;;
-  build) cmd_build $@ ;;
-  pack) cmd_pack $@ ;;
-  install) cmd_install $@ ;;
-  *) usage; exit 1 ;;
-esac
diff --git a/Tools/dotnet-wrapper.sh b/Tools/dotnet-wrapper.sh
deleted file mode 100644 (file)
index 6521019..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/bash
-
-DOTNET_CLI_PATH=/usr/share/dotnet-build-tools/cli/dotnet
-
-export DOTNET_CLI_TELEMETRY_OPTOUT=1
-export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
-export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
-export MSBUILDDISABLENODEREUSE=true
-
-$DOTNET_CLI_PATH "$@" /nodeReuse:false /p:UseRazorBuildServer=false /p:UseSharedCompilation=false
diff --git a/Tools/dummypack.csproj b/Tools/dummypack.csproj
deleted file mode 100644 (file)
index 91a2d77..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
-  <PropertyGroup>
-    <TargetFramework>netstandard2.0</TargetFramework>
-  </PropertyGroup>
-
-  <PropertyGroup>
-    <DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>
-  </PropertyGroup>
-
-  <PropertyGroup>
-    <IncludeBuildOutput>false</IncludeBuildOutput>
-    <NoPackageAnalysis>true</NoPackageAnalysis>
-    <NuspecProperties Condition="'$(Version)' != ''">version=$(Version)</NuspecProperties>
-    <NuspecBasePath Condition="'$(NuspecBasePath)' == ''">$(PWD)</NuspecBasePath>
-    <PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(PWD)</PackageOutputPath>
-  </PropertyGroup>
-
-</Project>
\ No newline at end of file
diff --git a/Tools/retry.sh b/Tools/retry.sh
deleted file mode 100755 (executable)
index b6add9d..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/bash
-
-retry_count=3
-cmd="${@}"
-
-n=0
-until [ $n -ge $retry_count ]; do
-  if [ $n -gt 0 ]; then
-    echo "(Failed! Retry $[$n+1]/$retry_count) $cmd"
-    sleep 2
-  fi
-  $cmd
-  RET=$?
-  if [ $RET -eq 0 ]; then
-    break
-  else
-    n=$[$n+1]
-  fi
-done
-
-exit $RET
diff --git a/Tools/timeout.sh b/Tools/timeout.sh
deleted file mode 100755 (executable)
index c7273d0..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-#!/bin/sh
-
-# Execute a command with a timeout
-
-# License: LGPLv2
-# Author:
-#    http://www.pixelbeat.org/
-# Notes:
-#    Note there is a timeout command packaged with coreutils since v7.0
-#    If the timeout occurs the exit status is 124.
-#    There is an asynchronous (and buggy) equivalent of this
-#    script packaged with bash (under /usr/share/doc/ in my distro),
-#    which I only noticed after writing this.
-#    I noticed later again that there is a C equivalent of this packaged
-#    with satan by Wietse Venema, and copied to forensics by Dan Farmer.
-# Changes:
-#    V1.0, Nov  3 2006, Initial release
-#    V1.1, Nov 20 2007, Brad Greenlee <brad@footle.org>
-#                       Make more portable by using the 'CHLD'
-#                       signal spec rather than 17.
-#    V1.3, Oct 29 2009, Ján Sáreník <jasan@x31.com>
-#                       Even though this runs under dash,ksh etc.
-#                       it doesn't actually timeout. So enforce bash for now.
-#                       Also change exit on timeout from 128 to 124
-#                       to match coreutils.
-#    V2.0, Oct 30 2009, Ján Sáreník <jasan@x31.com>
-#                       Rewritten to cover compatibility with other
-#                       Bourne shell implementations (pdksh, dash)
-
-if [ "$#" -lt "2" ]; then
-    echo "Usage:   `basename $0` timeout_in_seconds command" >&2
-    echo "Example: `basename $0` 2 sleep 3 || echo timeout" >&2
-    exit 1
-fi
-
-cleanup()
-{
-    trap - ALRM               #reset handler to default
-    kill -ALRM $a 2>/dev/null #stop timer subshell if running
-    kill $! 2>/dev/null &&    #kill last job
-      exit 124                #exit with 124 if it was running
-}
-
-watchit()
-{
-    trap "cleanup" ALRM
-    sleep $1& wait
-    kill -ALRM $$
-}
-
-watchit $1& a=$!         #start the timeout
-shift                    #first param was timeout for sleep
-trap "cleanup" ALRM INT  #cleanup after timeout
-"$@"& wait $!; RET=$?    #start the job wait for it and save its return value
-kill -ALRM $a            #send ALRM signal to watchit
-wait $a                  #wait for watchit to finish cleanup
-exit $RET                #return the value
-
index d46b34f13597e9e64c85d5f57ec3d86806559ed7..4d553ceca1ede352f7fba768edc19a5de9691494 100644 (file)
@@ -20,12 +20,14 @@ BuildRequires: patchelf
 Requires: corefx-managed-ref
 Requires: libicu
 Requires: openssl1.1
+Requires: make
+Requires: dotnet-launcher-gbs-support
 
 %description
 Provides dotnet-sdk for GBS environment
 
 %define TOOLS_PATH /usr/share/dotnet-build-tools
-%define CLI_PATH %{TOOLS_PATH}/cli
+%define SDK_PATH %{TOOLS_PATH}/sdk
 
 %prep
 %setup -q
@@ -35,16 +37,16 @@ tar xvfz %{SOURCE21} -C dotnet
 tar xvfz %{SOURCE22} -C dotnet/deps
 
 %build
-# Prepare dotnet-cli
+# Prepare dotnet-sdk
 %ifnarch x86_64
 for file in $( find ./dotnet -name "dotnet" -type f )
 do
-    patchelf --set-interpreter %{CLI_PATH}/deps/ld-linux-x86-64.so.2 ${file}
-    patchelf --set-rpath %{CLI_PATH}/deps/ ${file}
+    patchelf --set-interpreter %{SDK_PATH}/deps/ld-linux-x86-64.so.2 ${file}
+    patchelf --set-rpath %{SDK_PATH}/deps/ ${file}
 done
 for file in $( find ./dotnet -type f \( -name "*.so" -or -name "*.so.*" \) -not -name "*.dbg" -not -name "ld-*.so*" )
 do
-    patchelf --set-rpath %{CLI_PATH}/deps/ ${file}
+    patchelf --set-rpath %{SDK_PATH}/deps/ ${file}
 done
 %endif
 
@@ -53,22 +55,20 @@ cp -f overrides/Microsoft.Build.Tasks.Core.dll dotnet/sdk/*/Microsoft.Build.Task
 
 %install
 
+mkdir -p %{buildroot}%{_bindir}
+mkdir -p %{buildroot}%{SDK_PATH}
+
 # RPM Macros
 install -D -p -m 0644 %{S:1} %{buildroot}%{_sysconfdir}/rpm/macros.dotnet-build-tools
 
+# .NETCore SDK
+cp -fr ./dotnet/* %{buildroot}%{SDK_PATH}
+
 # BuildTools
-mkdir -p %{buildroot}%{_bindir}
-mkdir -p %{buildroot}%{TOOLS_PATH}
-install -p -m 755 Tools/* %{buildroot}%{TOOLS_PATH}
+cp -fr ./tools/* %{buildroot}%{TOOLS_PATH}
 ln -s %{TOOLS_PATH}/dotnet-build.sh %{buildroot}%{_bindir}/dotnet-build
-
-# .NETCore SDK
-mkdir -p %{buildroot}%{CLI_PATH}
-cp -fr ./dotnet/* %{buildroot}%{CLI_PATH}
 ln -s %{TOOLS_PATH}/dotnet-wrapper.sh %{buildroot}%{_bindir}/dotnet
-
-# Tizen.GBS.BuildTasks
-install -p -m 644 Tizen.GBS.BuildTasks/Tizen.GBS.ImportAfter.targets %{buildroot}%{CLI_PATH}/sdk/*/Current/Microsoft.Common.targets/ImportAfter
+ln -s %{TOOLS_PATH}/dotnet-validate-struct.sh %{buildroot}%{_bindir}/dotnet-validate-struct
 
 %files
 %config(noreplace) %{_sysconfdir}/rpm/macros.dotnet-build-tools
diff --git a/tools/StructValidator/StructValidator.deps.json b/tools/StructValidator/StructValidator.deps.json
new file mode 100644 (file)
index 0000000..3219b5f
--- /dev/null
@@ -0,0 +1,23 @@
+{
+  "runtimeTarget": {
+    "name": ".NETCoreApp,Version=v3.0",
+    "signature": ""
+  },
+  "compilationOptions": {},
+  "targets": {
+    ".NETCoreApp,Version=v3.0": {
+      "StructValidator/1.0.0": {
+        "runtime": {
+          "StructValidator.dll": {}
+        }
+      }
+    }
+  },
+  "libraries": {
+    "StructValidator/1.0.0": {
+      "type": "project",
+      "serviceable": false,
+      "sha512": ""
+    }
+  }
+}
\ No newline at end of file
diff --git a/tools/StructValidator/StructValidator.dll b/tools/StructValidator/StructValidator.dll
new file mode 100644 (file)
index 0000000..a9d7b78
Binary files /dev/null and b/tools/StructValidator/StructValidator.dll differ
diff --git a/tools/StructValidator/StructValidator.pdb b/tools/StructValidator/StructValidator.pdb
new file mode 100644 (file)
index 0000000..c81f643
Binary files /dev/null and b/tools/StructValidator/StructValidator.pdb differ
diff --git a/tools/StructValidator/StructValidator.runtimeconfig.json b/tools/StructValidator/StructValidator.runtimeconfig.json
new file mode 100644 (file)
index 0000000..33ec9d0
--- /dev/null
@@ -0,0 +1,9 @@
+{
+  "runtimeOptions": {
+    "tfm": "netcoreapp3.0",
+    "framework": {
+      "name": "Microsoft.NETCore.App",
+      "version": "3.0.0"
+    }
+  }
+}
\ No newline at end of file
diff --git a/tools/StructValidator/native/Makefile b/tools/StructValidator/native/Makefile
new file mode 100644 (file)
index 0000000..cc67471
--- /dev/null
@@ -0,0 +1,33 @@
+MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
+MKFILE_DIR := $(dir $(MKFILE_PATH))
+
+BINDIR := $(MKFILE_DIR)
+TARGET ?= $(MKFILE_DIR)/structcheck
+
+CC := gcc
+
+SRCS = $(wildcard $(MKFILE_DIR)/*.c)
+INCS = $(wildcard $(MKFILE_DIR)/*.h)
+OBJS = $(patsubst %.c,%.o,$(SRCS))
+
+include auto-generated.mk
+
+PKGCONFIG = $(if $(strip $(DEPS)), `pkg-config --cflags $(DEPS)`,)
+
+CFLAGS += -fPIC -I$(MKFILE_DIR) $(PKGCONFIG)
+LDFLAGS +=
+
+$(TARGET): $(OBJS)
+       @mkdir -p $(BINDIR)
+       $(CC) -o $@ $^ $(LDFLAGS)
+
+%.o: %.c $(INCS)
+       $(CC) -c -o $@ $< $(CFLAGS)
+
+.PHONY: clean
+clean:
+       @rm -f $(TARGET)
+       @find $(MKFILE_DIR) -type f -name '*.o' -delete
+       @rm -f auto-generated.c
+       @rm -f auto-generated.mk
+
diff --git a/tools/StructValidator/native/common.h b/tools/StructValidator/native/common.h
new file mode 100644 (file)
index 0000000..117aa3e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define PV_CONCAT(x, y) _PV_CONCAT(x, y)
+#define _PV_CONCAT(x, y) x##y
+
+#define CHECK_STRUCT(N, S, T) _CHECK_STRUCT(N, S, T, PV_CONCAT(__fn_, __COUNTER__))
+#define _CHECK_STRUCT(N, S, T, F) __CHECK_STRUCT(N, S, T, F)
+#define __CHECK_STRUCT(N, S, T, F)                                 \
+    static int F(void);                                            \
+    static void __attribute__((constructor)) __construct_##F(void) \
+    {                                                              \
+        _add_function_to_provider_list(F);                         \
+    }                                                              \
+    static int F(void)                                             \
+    {                                                              \
+        return _check_struct(N, S, sizeof(T));                     \
+    }
+
+void _add_function_to_provider_list(int (*f)(void));
+int _check_struct(const char *name, int managed, int unmanaged);
diff --git a/tools/StructValidator/native/main.c b/tools/StructValidator/native/main.c
new file mode 100644 (file)
index 0000000..7f1b25b
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+typedef struct __provider_list_node
+{
+    struct __provider_list_node *next;
+    int (*func)(void);
+} _provider_list_node;
+
+_provider_list_node *_provider_list_head = NULL;
+
+void _add_function_to_provider_list(int (*f)(void))
+{
+    _provider_list_node *node = (_provider_list_node *)malloc(sizeof(_provider_list_node));
+    node->func = f;
+    node->next = _provider_list_head;
+    _provider_list_head = node;
+}
+
+int _check_struct(const char *name, int managed, int unmanaged)
+{
+    if (managed != unmanaged)
+    {
+        printf("* %s size is mismatch. managed(%d) != unmanaged(%d)\n", name, managed, unmanaged);
+        return 0;
+    }
+    return 1;
+}
+
+int main(int argc, char **argv)
+{
+    int valid = 1;
+    _provider_list_node *node = _provider_list_head;
+    while (node != NULL)
+    {
+        valid = valid & node->func();
+        node = node->next;
+    }
+    if (!valid)
+    {
+        printf("***** INVALID STRUCT SIZE *****\n");
+        return 1;
+    }
+    return 0;
+}
diff --git a/tools/dotnet-build.sh b/tools/dotnet-build.sh
new file mode 100755 (executable)
index 0000000..28c5b85
--- /dev/null
@@ -0,0 +1,110 @@
+#!/bin/bash
+
+SCRIPT_FILE=$(readlink -f $0)
+SCRIPT_DIR=$(dirname $SCRIPT_FILE)
+
+TIMEOUT_CMD="$SCRIPT_DIR/timeout.sh"
+RETRY_CMD="$SCRIPT_DIR/retry.sh"
+
+usage() {
+  echo "usage: "
+  echo " $0 restore <project> [-s <source>] ..."
+  echo " $0 build <project> [-c <configuration>] ..."
+  echo " $0 pack <project> [-c <configuration>] [-v <version>] ..."
+  echo " $0 install <project> [-t <type>]"
+}
+
+exit_on_error() {
+  if [ $1 -ne 0 ]; then
+    echo "Error $1"
+    exit $1
+  fi
+}
+
+run_dotnet() {
+  echo "+ dotnet $@"
+  $RETRY_CMD $TIMEOUT_CMD -t 600 dotnet $@ /nologo
+  exit_on_error $?
+}
+
+cmd_restore() {
+  local OPTS=""
+  [ -n "$SOURCE" ] && OPTS="$OPTS -s $SOURCE"
+  run_dotnet restore $PROJECT $OPTS $@
+}
+
+cmd_build() {
+  cmd_restore # restore first
+  local OPTS=""
+  [ -n "$CONFIGURATION" ] && OPTS="$OPTS -c $CONFIGURATION"
+  run_dotnet build --no-restore $PROJECT $OPTS $@ /p:GenerateDocumentationFile=True
+}
+
+cmd_pack() {
+  local OPTS=""
+  [ -n "$CONFIGURATION" ] && OPTS="$OPTS -c $CONFIGURATION"
+  [ -n "$VERSION" ] && OPTS="$OPTS /p:Version=$VERSION"
+  if [[ $PROJECT == *".nuspec" ]]; then
+    NUSPECPATH=$(readlink -f $PROJECT)
+    OPTS="$OPTS /p:NuspecFile=$NUSPECPATH /p:PWD=$PWD"
+    TMPDIR=$(mktemp -d)
+    cp $SCRIPT_DIR/dummypack.csproj $TMPDIR
+    PROJECT=$TMPDIR/dummypack.csproj
+    run_dotnet restore $PROJECT -s /nuget/
+  fi
+  run_dotnet pack --no-build --no-restore $PRE_OPTS $PROJECT $OPTS $@
+}
+
+cmd_install() {
+  local DEST=$1; shift
+  mkdir -p $DEST
+  if [[ $TYPE == "assembly" ]]; then
+    find $PROJECT/bin -name $PROJECT.dll -not -path "*/ref/*" -exec install -p -m 644 {} $DEST \;
+  elif [[ $TYPE == "nupkg" ]]; then
+    find . -name "$PROJECT.[0-9]*.nupkg" -exec install -p -m 644 {} $DEST \;
+  fi
+}
+
+#########################################################################
+
+# Parse arguments
+
+while getopts "s:c:v:t:" o; do
+  case "$o" in
+    s) SOURCE=${OPTARG} ;;
+    c) CONFIGURATION=${OPTARG} ;;
+    v) VERSION=${OPTARG} ;;
+    t) TYPE=${OPTARG} ;;
+    *) usage; exit 1 ;;
+  esac
+done
+shift $((OPTIND-1))
+
+if [ $# -lt 2 ]; then
+  usage; exit 1
+fi
+
+CMD=$1; shift
+PROJECT=$1; shift
+
+export DOTNET_CLI_TELEMETRY_OPTOUT=1
+export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
+
+# Dump
+echo "----------------------------------------------"
+echo "CMD=$CMD"
+echo "PROJECT=$PROJECT"
+echo "SOURCE=$SOURCE"
+echo "CONFIGURATION=$CONFIGURATION"
+echo "VERSION=$VERSION"
+echo "TYPE=$TYPE"
+echo "REST ARGS=$@"
+echo "----------------------------------------------"
+
+case $CMD in
+  restore) cmd_restore $@ ;;
+  build) cmd_build $@ ;;
+  pack) cmd_pack $@ ;;
+  install) cmd_install $@ ;;
+  *) usage; exit 1 ;;
+esac
diff --git a/tools/dotnet-validate-struct.sh b/tools/dotnet-validate-struct.sh
new file mode 100755 (executable)
index 0000000..6a80a15
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/bash -e
+
+SV_ASSEMBLY=/usr/share/dotnet-build-tools/StructValidator/StructValidator.dll
+dotnet-corerun $SV_ASSEMBLY $1
diff --git a/tools/dotnet-wrapper.sh b/tools/dotnet-wrapper.sh
new file mode 100755 (executable)
index 0000000..701cf07
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+DOTNET_CLI_PATH=/usr/share/dotnet-build-tools/sdk/dotnet
+
+export DOTNET_CLI_TELEMETRY_OPTOUT=1
+export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true
+export DOTNET_ROLL_FORWARD_ON_NO_CANDIDATE_FX=2
+export MSBUILDDISABLENODEREUSE=true
+
+if [ "$1" == "msbuild" -o "$1" == "build" -o "$1" == "restore" ]; then
+  echo $DOTNET_CLI_PATH "$@" /nodeReuse:false /p:UseRazorBuildServer=false /p:UseSharedCompilation=false
+  $DOTNET_CLI_PATH "$@" /nodeReuse:false /p:UseRazorBuildServer=false /p:UseSharedCompilation=false
+else
+  echo $DOTNET_CLI_PATH "$@"
+  $DOTNET_CLI_PATH "$@"
+fi
diff --git a/tools/dummypack.csproj b/tools/dummypack.csproj
new file mode 100644 (file)
index 0000000..91a2d77
--- /dev/null
@@ -0,0 +1,19 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>netstandard2.0</TargetFramework>
+  </PropertyGroup>
+
+  <PropertyGroup>
+    <DisableImplicitFrameworkReferences>false</DisableImplicitFrameworkReferences>
+  </PropertyGroup>
+
+  <PropertyGroup>
+    <IncludeBuildOutput>false</IncludeBuildOutput>
+    <NoPackageAnalysis>true</NoPackageAnalysis>
+    <NuspecProperties Condition="'$(Version)' != ''">version=$(Version)</NuspecProperties>
+    <NuspecBasePath Condition="'$(NuspecBasePath)' == ''">$(PWD)</NuspecBasePath>
+    <PackageOutputPath Condition="'$(PackageOutputPath)' == ''">$(PWD)</PackageOutputPath>
+  </PropertyGroup>
+
+</Project>
\ No newline at end of file
diff --git a/tools/retry.sh b/tools/retry.sh
new file mode 100755 (executable)
index 0000000..b6add9d
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+retry_count=3
+cmd="${@}"
+
+n=0
+until [ $n -ge $retry_count ]; do
+  if [ $n -gt 0 ]; then
+    echo "(Failed! Retry $[$n+1]/$retry_count) $cmd"
+    sleep 2
+  fi
+  $cmd
+  RET=$?
+  if [ $RET -eq 0 ]; then
+    break
+  else
+    n=$[$n+1]
+  fi
+done
+
+exit $RET
diff --git a/tools/timeout.sh b/tools/timeout.sh
new file mode 100755 (executable)
index 0000000..5c19d2e
--- /dev/null
@@ -0,0 +1,91 @@
+#!/bin/bash
+#
+# The Bash shell script executes a command with a time-out.
+# Upon time-out expiration SIGTERM (15) is sent to the process. If the signal
+# is blocked, then the subsequent SIGKILL (9) terminates it.
+#
+# Based on the Bash documentation example.
+
+# Hello Chet,
+# please find attached a "little easier"  :-)  to comprehend
+# time-out example.  If you find it suitable, feel free to include
+# anywhere: the very same logic as in the original examples/scripts, a
+# little more transparent implementation to my taste.
+#
+# Dmitry V Golovashkin <Dmitry.Golovashkin@sas.com>
+
+scriptName="${0##*/}"
+
+declare -i DEFAULT_TIMEOUT=9
+declare -i DEFAULT_INTERVAL=1
+declare -i DEFAULT_DELAY=1
+
+# Timeout.
+declare -i timeout=DEFAULT_TIMEOUT
+# Interval between checks if the process is still alive.
+declare -i interval=DEFAULT_INTERVAL
+# Delay between posting the SIGTERM signal and destroying the process by SIGKILL.
+declare -i delay=DEFAULT_DELAY
+
+function printUsage() {
+    cat <<EOF
+
+Synopsis
+    $scriptName [-t timeout] [-i interval] [-d delay] command
+    Execute a command with a time-out.
+    Upon time-out expiration SIGTERM (15) is sent to the process. If SIGTERM
+    signal is blocked, then the subsequent SIGKILL (9) terminates it.
+
+    -t timeout
+        Number of seconds to wait for command completion.
+        Default value: $DEFAULT_TIMEOUT seconds.
+
+    -i interval
+        Interval between checks if the process is still alive.
+        Positive integer, default value: $DEFAULT_INTERVAL seconds.
+
+    -d delay
+        Delay between posting the SIGTERM signal and destroying the
+        process by SIGKILL. Default value: $DEFAULT_DELAY seconds.
+
+As of today, Bash does not support floating point arithmetic (sleep does),
+therefore all delay/time values must be integers.
+EOF
+}
+
+# Options.
+while getopts ":t:i:d:" option; do
+    case "$option" in
+        t) timeout=$OPTARG ;;
+        i) interval=$OPTARG ;;
+        d) delay=$OPTARG ;;
+        *) printUsage; exit 1 ;;
+    esac
+done
+shift $((OPTIND - 1))
+
+# $# should be at least 1 (the command to execute), however it may be strictly
+# greater than 1 if the command itself has options.
+if (($# == 0 || interval <= 0)); then
+    printUsage
+    exit 1
+fi
+
+# kill -0 pid   Exit code indicates if a signal may be sent to $pid process.
+(
+    ((t = timeout))
+
+    while ((t > 0)); do
+        sleep $interval
+        kill -0 $$ || exit 0
+        ((t -= interval))
+    done
+
+    # Be nice, post SIGTERM first.
+    # The 'exit 0' below will be executed if any preceeding command fails.
+    kill -s SIGTERM $$ && kill -0 $$ || exit 0
+    sleep $delay
+    kill -s SIGKILL $$
+) 2> /dev/null &
+
+exec "$@"
diff --git a/update-tools.sh b/update-tools.sh
new file mode 100755 (executable)
index 0000000..5f29e71
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+SCRIPT_FILE=$(readlink -f $0)
+SCRIPT_DIR=$(dirname $SCRIPT_FILE)
+
+SV_GITDIR="$SCRIPT_DIR/.repos/StructValidator"
+SV_BINDIR="$SCRIPT_DIR/tools/StructValidator"
+
+rm -fr $SV_GITDIR
+git clone https://github.sec.samsung.net/dotnet/StructValidator $SV_GITDIR
+dotnet publish $SV_GITDIR -o $SV_BINDIR
+
+rm -fr $SV_GITDIR
+