Skip to content

Commit d5ed1fb

Browse files
authored
Merge pull request #50 from RISC-OS-Community/chore/sync-from-template
Sync from template@92ea3404ed3110ebd66e35e112158e3130246370
2 parents 92ea340 + 518611d commit d5ed1fb

File tree

4 files changed

+130
-57
lines changed

4 files changed

+130
-57
lines changed

.gitattributes

+5-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ doc/** linguist-documentation
3030
src/**/c/* text diff=c linguist-language=c
3131
src/**/h/* text diff=c linguist-language=c
3232
src/**/c++/* text diff=cpp linguist-language=cpp
33-
src/**/cpp/* text diff=cpp linguist-language=cpp
33+
src/**/cpp/* text diff=cpp linguist-language=cpp
34+
src/**/hpp/* text diff=cpp linguist-language=cpp
35+
src/**/hxx/* text diff=cpp linguist-language=cpp
36+
src/**/cxx/* text diff=cpp linguist-language=cpp
37+
src/**/h++/* text diff=cpp linguist-language=cpp
3438
src/**/bas/* text diff=bbcbasic linguist-language=bbcbasic
3539
src/**/s/* text diff=armasm linguist-language=assembly
3640
src/**/Hdr/* text diff=armasm linguist-language=assembly

.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily

.pre-commit-config.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/gitleaks/gitleaks
3+
rev: v8.16.3
4+
hooks:
5+
- id: gitleaks
6+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
7+
rev: 3.0.0
8+
hooks:
9+
- id: shellcheck
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v4.4.0
12+
hooks:
13+
- id: end-of-file-fixer
14+
- id: trailing-whitespace

.rocog/scripts/ux-src

+105-56
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@
2222
# And, if the directory exists in your pwd then it will be removed.
2323
####################
2424

25-
cmd="$1"
26-
env="$2"
25+
declare -r cmd="$1"
26+
declare -r env="$2"
2727
curr_dir="$3"
2828
if [ "${curr_dir}" == "" ]
2929
then
3030
curr_dir="$(pwd)"
31+
declare -r curr_path="$(pwd)/src"
32+
else
33+
declare -r curr_path="${curr_dir}/src"
3134
fi
3235

3336
# Debug mode:
@@ -36,23 +39,41 @@ debug=0
3639
# Display command usage:
3740
function usage()
3841
{
39-
echo "Usage: ux-src [gen|clean] [path]"
40-
echo "gen: generate ux-src directory"
41-
echo "clean: remove ux-src directory"
42+
echo " Usage: ux-src <gen|clean> <github|local> [path]"
43+
echo " gen, generate ux-src directory"
44+
echo " clean, remove ux-src directory"
45+
echo "github, GitHub Actions environment"
46+
echo " local, local environment"
47+
echo " path, the path to the source tree (optional)"
4248
}
4349

4450
# Link files from directory f_dir to directory ux-src with extension f_ext:
4551
function link_files()
4652
{
47-
local src_dir="$1"
48-
local dst_dir="$2"
49-
local f_dir="$3"
50-
local f_ext="$4"
51-
if [ -d ${src_dir}/${f_dir} ]
53+
local dir_type="$1"
54+
local src_dir="$2"
55+
local dst_dir="$3"
56+
local f_dir="$4"
57+
local f_ext="$5"
58+
local srch_path=""
59+
local x="$(basename ${src_dir})"
60+
if [ "$dir_type" != "2" ];
61+
then
62+
srch_path="${src_dir}/${f_dir}"
63+
else
64+
if [ "${x}" == "${f_dir}" ];
65+
then
66+
srch_path="${src_dir}"
67+
dst_dir="$(dirname ${dst_dir})"
68+
else
69+
return
70+
fi
71+
fi
72+
if [ -d ${srch_path} ];
5273
then
53-
for f in ${src_dir}/${f_dir}/*
74+
for f in ${srch_path}/*
5475
do
55-
if [ ! -f ${f} ]
76+
if [ ! -f "${f}" ]
5677
then
5778
continue
5879
else
@@ -81,6 +102,7 @@ function check_path()
81102
[ "${last_dir}" == "c++" ] || [ "${last_dir}" == "C++" ] || \
82103
[ "${last_dir}" == "hpp" ] || [ "${last_dir}" == "HPP" ] || \
83104
[ "${last_dir}" == "hxx" ] || [ "${last_dir}" == "HXX" ] || \
105+
[ "${last_dir}" == "h++" ] || [ "${last_dir}" == "H++" ] || \
84106
[ "${last_dir}" == "s" ] || [ "${last_dir}" == "S" ] || \
85107
[ "${last_dir}" == "Hdr" ] || [ "${last_dir}" == "hdr" ] || \
86108
[ "${last_dir}" == "fth" ] || [ "${last_dir}" == "FTH" ] || \
@@ -97,53 +119,55 @@ function check_path()
97119
# check for files with the known directory structure and link them in
98120
# the ux-src directory with their appropriate extension:
99121
function find_files_and_link() {
100-
local src_dir="$1"
101-
local dst_dir="$2"
122+
local dir_type="$1"
123+
local src_dir="$2"
124+
local dst_dir="$3"
102125

103126
# Link C files (if any):
104-
link_files "${src_dir}" "${dst_dir}" "c" "c"
105-
link_files "${src_dir}" "${dst_dir}" "C" "c"
127+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "c" "c"
128+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "C" "c"
106129

107130
# Link C++ files (if any):
108-
link_files "${src_dir}" "${dst_dir}" "cpp" "cpp"
109-
link_files "${src_dir}" "${dst_dir}" "CPP" "cpp"
110-
link_files "${src_dir}" "${dst_dir}" "cxx" "cxx"
111-
link_files "${src_dir}" "${dst_dir}" "CXX" "cxx"
112-
link_files "${src_dir}" "${dst_dir}" "cc" "cc"
113-
link_files "${src_dir}" "${dst_dir}" "CC" "cc"
114-
link_files "${src_dir}" "${dst_dir}" "c++" "cpp"
115-
link_files "${src_dir}" "${dst_dir}" "C++" "cpp"
131+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "cpp" "cpp"
132+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "CPP" "cpp"
133+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "cxx" "cxx"
134+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "CXX" "cxx"
135+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "cc" "cc"
136+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "CC" "cc"
137+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "c++" "cpp"
138+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "C++" "cpp"
116139

117140
# Link C++ header files (if any):
118-
link_files "${src_dir}" "${dst_dir}" "hpp" "hpp"
119-
link_files "${src_dir}" "${dst_dir}" "HPP" "hpp"
120-
link_files "${src_dir}" "${dst_dir}" "hxx" "hxx"
121-
link_files "${src_dir}" "${dst_dir}" "HXX" "hxx"
141+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "hpp" "hpp"
142+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "HPP" "hpp"
143+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "hxx" "hxx"
144+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "HXX" "hxx"
145+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "h++" "hpp"
122146

123147
# Link C header files (if any):
124-
link_files "${src_dir}" "${dst_dir}" "h" "h"
125-
link_files "${src_dir}" "${dst_dir}" "H" "h"
148+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "h" "h"
149+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "H" "h"
126150

127151
# Link Assembler files (if any):
128-
link_files "${src_dir}" "${dst_dir}" "s" "s"
129-
link_files "${src_dir}" "${dst_dir}" "S" "s"
130-
link_files "${src_dir}" "${dst_dir}" "Hdr" "s"
152+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "s" "s"
153+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "S" "s"
154+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "Hdr" "s"
131155

132156
# Link Forth files (if any):
133-
link_files "${src_dir}" "${dst_dir}" "fth" "fth"
134-
link_files "${src_dir}" "${dst_dir}" "FTH" "fth"
157+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "fth" "fth"
158+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "FTH" "fth"
135159

136160
# Link Pascal and Prolog files (if any):
137-
link_files "${src_dir}" "${dst_dir}" "p" "p"
138-
link_files "${src_dir}" "${dst_dir}" "P" "p"
161+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "p" "p"
162+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "P" "p"
139163

140164
# Link Perl files (if any):
141-
link_files "${src_dir}" "${dst_dir}" "pl" "pl"
142-
link_files "${src_dir}" "${dst_dir}" "PL" "pl"
165+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "pl" "pl"
166+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "PL" "pl"
143167

144168
# Link BASIC files (if any):
145-
link_files "${src_dir}" "${dst_dir}" "bas" "bas"
146-
link_files "${src_dir}" "${dst_dir}" "BAS" "bas"
169+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "bas" "bas"
170+
link_files "${dir_type}" "${src_dir}" "${dst_dir}" "BAS" "bas"
147171

148172
# Find and link local files
149173
# (that may also be called Makefile.unix etc.):
@@ -154,10 +178,19 @@ function find_files_and_link() {
154178
then
155179
for f in ${src_dir}/*
156180
do
157-
fname="$(basename ${f})"
181+
local fname="$(basename ${f})"
158182
# Remove ,fd7 etc. from the filename:
159183
fname="$(echo ${fname} | sed 's/,.*//')"
160-
if [ -f ${f} ];
184+
local fext="$(echo ${fname} | sed 's/^.*\.//')"
185+
# Skip files with extensions: .o, .a, .so
186+
if [ "${fext}" == "o" ] || [ "${fext}" == "a" ] ||
187+
[ "${fext}" == "od" ] || [ "${fext}" == "oz" ] ||
188+
[ "${fext}" == "odz" ] || [ "${fext}" == "so" ] ||
189+
[[ "${fext}" =~ "so\..*" ]];
190+
then
191+
continue
192+
fi
193+
if [ -f "${f}" ];
161194
then
162195
if [ "$env" == "github" ]
163196
then
@@ -181,24 +214,40 @@ function gen_dirs()
181214
if [ ! -d "${d}" ]
182215
then
183216
local dname2="$(echo ${d} | sed 's/^.*\/src\///')"
184-
find_files_and_link "${d}" "${curr_dir}/ux-src/${dname2}"
217+
find_files_and_link "0" "${d}" "${curr_dir}/ux-src/${dname2}"
185218
else
186219
local dname="$(basename "${d}")"
187220
check_path "${dname}"
188221
local rval=$?
189222
if [ $rval -eq 1 ];
190223
then
191-
local dname2="$(echo ${d} | sed 's/^.*\/src\///')"
192-
find_files_and_link "${d}" "${curr_dir}/ux-src/${dname2}"
224+
#local dname2="$(echo ${d} | sed 's/^.*\/src\///')"
225+
local dname2="${d#*/src/}"
226+
if [ "${dname2}" != "" ]
227+
then
228+
find_files_and_link "2" "${d}" "${curr_dir}/ux-src/${dname2}"
229+
fi
193230
else
194231
local dname2="$(echo ${d} | sed 's/^.*\/src\///')"
195-
if [ ! -d "${curr_dir}/ux-src/${dname2}" ]
232+
echo -n "Processing: ${dname2} ... "
233+
local dname3="$(basename ${dname2})"
234+
if [ "${dname3}" != "o" ] && [ "${dname3}" != "a" ] &&
235+
[ "${dname3}" != "od" ] && [ "${dname3}" != "oz" ] &&
236+
[ "${dname3}" != "odz" ] && [ "${dname3}" != "so" ] ;
196237
then
197-
mkdir -p "${curr_dir}/ux-src/${dname2}"
198-
find_files_and_link "${d}" "${curr_dir}/ux-src/${dname2}"
238+
# Skip the o directory (it's not required in the UX world)
239+
# process everythign else:
240+
if [ ! -d "${curr_dir}/ux-src/${dname2}" ]
241+
then
242+
mkdir -p "${curr_dir}/ux-src/${dname2}"
243+
find_files_and_link "${rval}" "${d}" "${curr_dir}/ux-src/${dname2}"
244+
fi
245+
echo "ok"
246+
# Recursive call to explore the sub-directory
247+
gen_dirs "${d}"
248+
else
249+
echo "skipped"
199250
fi
200-
# Recursive call to explore the sub-directory
201-
gen_dirs "${d}"
202251
fi
203252
fi
204253
done
@@ -224,7 +273,7 @@ check_cmd
224273
# Check if we are in a RISC OS source tree:
225274
if [ ! -d ${curr_dir}/src ]
226275
then
227-
echo "Error: you are not in a RISC OS Community source tree"
276+
echo "Error: it appears you are not in a RISC OS Community source tree"
228277
exit 1
229278
fi
230279

@@ -234,13 +283,13 @@ then
234283
echo "Generating ux-src directory in ${curr_dir}"
235284

236285
# Generate ux-src:
237-
mkdir ${curr_dir}/ux-src
286+
mkdir -p ${curr_dir}/ux-src
238287

239288
# Generate all the directories in ux-src:
240-
gen_dirs
289+
gen_dirs "${curr_path}"
241290

242291
# Link main Makefiles:
243-
if [ -f ${curr_dir}/src/Makefile* ]
292+
if compgen -G "${curr_dir}/src/Makefile*" > /dev/null;
244293
then
245294
for f in ${curr_dir}/src/Makefile*
246295
do
@@ -256,7 +305,7 @@ then
256305
fi
257306

258307
# Link the Build Script for Unix:
259-
if [ -f ${curr_dir}/src/MkGCC.sh ]
308+
if [ -f "${curr_dir}/src/MkGCC.sh" ]
260309
then
261310
if [ "$env" == "github" ]
262311
then

0 commit comments

Comments
 (0)