Skip to content

Commit

Permalink
[builpkg] Use the buildpkg tool to quickly build argparse's packages!
Browse files Browse the repository at this point in the history
  • Loading branch information
liu2guang committed Oct 1, 2018
0 parents commit 00a51bf
Show file tree
Hide file tree
Showing 18 changed files with 1,772 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
language: c

notifications:
email: true

git:
depth: 1

before_script:
- USER_NAME='liu2guang' REPO_NAME='argparse'

- sudo apt-get update
- "sudo apt-get -qq install gcc-multilib libc6:i386 libgcc1:i386 gcc-4.6-base:i386 libstdc++5:i386 libstdc++6:i386 libsdl-dev || true"
- "[ $RTT_TOOL_CHAIN = 'sourcery-arm' ] && curl -s https://launchpadlibrarian.net/287101520/gcc-arm-none-eabi-5_4-2016q3-20160926-linux.tar.bz2 | sudo tar xjf - -C /opt && export RTT_EXEC_PATH=/opt/gcc-arm-none-eabi-5_4-2016q3/bin && /opt/gcc-arm-none-eabi-5_4-2016q3/bin/arm-none-eabi-gcc --version || true"

- git clone --depth=3 --branch=master https://github.com/RT-Thread/rt-thread.git ../RT-Thread

- export RTT_ROOT=/home/travis/build/$USER_NAME/RT-Thread
- "[ x$RTT_CC == x ] && export RTT_CC='gcc' || true"

- sudo mkdir $RTT_ROOT/bsp/$RTT_BSP/packages
- sudo cp /home/travis/build/$USER_NAME/$REPO_NAME/script/script_bspcfg $RTT_ROOT/bsp/$RTT_BSP/rtconfig.h
- sudo cp /home/travis/build/$USER_NAME/$REPO_NAME/script/script_scons $RTT_ROOT/bsp/$RTT_BSP/packages/SConscript
- sudo cp -r /home/travis/build/$USER_NAME/$REPO_NAME $RTT_ROOT/bsp/$RTT_BSP/packages/$REPO_NAME

script:
- scons -C $RTT_ROOT/bsp/$RTT_BSP

env:
- RTT_BSP='imxrt1052-evk' RTT_TOOL_CHAIN='sourcery-arm'
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)
Copyright (c) 2018 liu2guang

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.

75 changes: 75 additions & 0 deletions SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# -*- coding:utf-8 –*-
# @File: Sconscript
# @Author: buildpkg.exe
# @Date: 2018-09-19 18:07:00(The date the template was created)
#
# @LICENSE: https://github.com/rtpkgs/buildpkg/blob/master/LICENSE.
#
# Change Logs:
# Date Author Notes
# 20xx-xx-xx buildpkg.exe auto create by buildpkg.exe.

import os
from building import *

# Get current dir path
cwd = GetCurrentDir()

# Init inc_list and src_list vars
inc = []
src = []

# debug info
print(inc)
print(src)

# Remove ignore src and
list_ignore_inc = []
list_ignore_src = []

# --------------------------------------------------------------------------------
# user add ignore:
# --------------------------------------------------------------------------------
list_ignore_inc += []
list_ignore_src += []

# --------------------------------------------------------------------------------
# auto add ignore:
# --------------------------------------------------------------------------------
list_ignore_inc += ['.git', 'example', 'doc', 'test']
list_ignore_src += ['test.c', 'example.c']

# Traverse package, add code and path to project
def traverse_package(f):
fs = os.listdir(f)
for f1 in fs:
tmp_path = os.path.join(f, f1)
filename = os.path.basename(tmp_path)

if os.path.isdir(tmp_path): # dir
if not filename in list_ignore_inc:
print("DIR: " + filename)
inc.append(f)
traverse_package(tmp_path)
else: # file
suffix = os.path.splitext(tmp_path)[1]
if suffix == '.c' and not filename in list_ignore_src:
#print("FILE: " + filename)
src.append(tmp_path)
elif suffix == '.h':
inc.append(f)

traverse_package(cwd)

# Add group to IDE project
objs = DefineGroup('argparse-v1.0.1', src, depend = ['PKG_USING_ARGPARSE'], CPPPATH = inc)

# Traversal subscript
list = os.listdir(cwd)
if GetDepend(['PKG_USING_ARGPARSE']):
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))

Return('objs')
5 changes: 5 additions & 0 deletions argparse/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tags
test_argparse
*.[ao]
*.dylib
*.so
5 changes: 5 additions & 0 deletions argparse/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: c
compiler:
- gcc
- clang
script: make test
21 changes: 21 additions & 0 deletions argparse/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2012-2013 Yecheng Fu <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
52 changes: 52 additions & 0 deletions argparse/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Defaults
CFLAGS ?= -O3 -g -ggdb
LDFLAGS ?=

BASIC_CFLAGS = -Wall -Wextra -fPIC
BASIC_LDFLAGS =

# We use ALL_* variants
ALL_CFLAGS = $(BASIC_CFLAGS) $(CFLAGS)
ALL_LDFLAGS = $(BASIC_LDFLAGS) $(LDFLAGS)

LIBNAME=libargparse

DYLIBSUFFIX=so
STLIBSUFFIX=a
DYLIBNAME=$(LIBNAME).$(DYLIBSUFFIX)
DYLIB_MAKE_CMD=$(CC) -shared -o $(DYLIBNAME) $(ALL_LDFLAGS)
STLIBNAME=$(LIBNAME).$(STLIBSUFFIX)
STLIB_MAKE_CMD=ar rcs $(STLIBNAME)

# Platform-specific overrides
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
ifeq ($(uname_S),Darwin)
DYLIBSUFFIX=dylib
DYLIB_MAKE_CMD=$(CC) -shared -o $(DYLIBNAME) $(ALL_LDFLAGS)
endif

all: $(DYLIBNAME) $(STLIBNAME)

OBJS += argparse.o
OBJS += test_argparse.o

$(OBJS): %.o: %.c
$(CC) -o $*.o -c $(ALL_CFLAGS) $<

$(DYLIBNAME): argparse.o
$(DYLIB_MAKE_CMD) $^

$(STLIBNAME): argparse.o
$(STLIB_MAKE_CMD) $^

test: test_argparse
@echo "###### Unit Test #####"
@./test.sh

test_argparse: $(OBJS)
$(CC) $(ALL_CFLAGS) -o $@ $^ $(ALL_LDFLAGS)

clean:
rm -rf test_argparse
rm -rf *.[ao]
rm -rf *.dylib
103 changes: 103 additions & 0 deletions argparse/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# argparse [![Build Status](https://travis-ci.org/cofyc/argparse.png)](https://travis-ci.org/cofyc/argparse)

argparse - A command line arguments parsing library in C (compatible with C++).

## Description

This module is inspired by parse-options.c (git) and python's argparse
module.

Arguments parsing is common task in cli program, but traditional `getopt`
libraries are not easy to use. This library provides high-level arguments
parsing solutions.

The program defines what arguments it requires, and `argparse` will figure
out how to parse those out of `argc` and `argv`, it also automatically
generates help and usage messages and issues errors when users give the
program invalid arguments.

## Features

- handles both optional and positional arguments
- produces highly informative usage messages
- issues errors when given invalid arguments

There are basically three types of options:

- boolean options
- options with mandatory argument
- options with optional argument

There are basically two forms of options:

- short option consist of one dash (`-`) and one alphanumeric character.
- long option begin with two dashes (`--`) and some alphanumeric characters.

Short options may be bundled, e.g. `-a -b` can be specified as `-ab`.

Options are case-sensitive.

Options and non-option arguments can clearly be separated using the `--` option.

## Examples

```c
#include "argparse.h"

static const char *const usage[] = {
"test_argparse [options] [[--] args]",
"test_argparse [options]",
NULL,
};

#define PERM_READ (1<<0)
#define PERM_WRITE (1<<1)
#define PERM_EXEC (1<<2)

int
main(int argc, const char **argv)
{
int force = 0;
int test = 0;
int num = 0;
const char *path = NULL;
int perms = 0;
struct argparse_option options[] = {
OPT_HELP(),
OPT_GROUP("Basic options"),
OPT_BOOLEAN('f', "force", &force, "force to do"),
OPT_BOOLEAN('t', "test", &test, "test only"),
OPT_STRING('p', "path", &path, "path to read"),
OPT_INTEGER('n', "num", &num, "selected num"),
OPT_GROUP("Bits options"),
OPT_BIT(0, "read", &perms, "read perm", NULL, PERM_READ, OPT_NONEG),
OPT_BIT(0, "write", &perms, "write perm", NULL, PERM_WRITE),
OPT_BIT(0, "exec", &perms, "exec perm", NULL, PERM_EXEC),
OPT_END(),
};

struct argparse argparse;
argparse_init(&argparse, options, usage, 0);
argparse_describe(&argparse, "\nA brief description of what the program does and how it works.", "\nAdditional description of the program after the description of the arguments.");
argc = argparse_parse(&argparse, argc, argv);
if (force != 0)
printf("force: %d\n", force);
if (test != 0)
printf("test: %d\n", test);
if (path != NULL)
printf("path: %s\n", path);
if (num != 0)
printf("num: %d\n", num);
if (argc != 0) {
printf("argc: %d\n", argc);
int i;
for (i = 0; i < argc; i++) {
printf("argv[%d]: %s\n", i, *(argv + i));
}
}
if (perms) {
printf("perms: %d\n", perms);
}
return 0;
}
```
Loading

0 comments on commit 00a51bf

Please sign in to comment.