Skip to content

Commit

Permalink
- REBOL files now use 2 spaces indent (like regular source files)
Browse files Browse the repository at this point in the history
- A bit more idiomatic REBOL code in setup.r & init.r
  • Loading branch information
iarwain committed Dec 29, 2017
1 parent a6f5a9f commit 98368c5
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 275 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ insert_final_newline = true
trim_trailing_whitespace = false
end_of_line = lf

[*.r]
indent_size = 4

[*.sh]
indent_size = 4
end_of_line = lf
170 changes: 85 additions & 85 deletions code/build/rebol/init.r
Original file line number Diff line number Diff line change
@@ -1,123 +1,123 @@
REBOL [
title: {Init}
author: {iarwain@orx-project.org}
date: 15-Aug-2017
file: %init.r
title: {Init}
author: {iarwain@orx-project.org}
date: 15-Aug-2017
file: %init.r
]

; Variables
source: %../template/
template: {[orx]}
extern: %../../../extern/
params: reduce [
'name {Project name, relative or full path} _
'name {Project name, relative or full path} _
]
platforms: [
{windows} [config [{gmake} {codelite} {codeblocks} {vs2013} {vs2015} {vs2017}] premake %premake4.exe setup {setup.bat} script %init.bat ]
{mac} [config [{gmake} {codelite} {codeblocks} {xcode4} ] premake %premake4 setup {./setup.sh} script %./init.sh ]
{linux} [config [{gmake} {codelite} {codeblocks} ] premake %premake4 setup {./setup.sh} script %./init.sh ]
{windows} [config [{gmake} {codelite} {codeblocks} {vs2013} {vs2015} {vs2017}] premake %premake4.exe setup {setup.bat} script %init.bat ]
{mac} [config [{gmake} {codelite} {codeblocks} {xcode4} ] premake %premake4 setup {./setup.sh} script %./init.sh ]
{linux} [config [{gmake} {codelite} {codeblocks} ] premake %premake4 setup {./setup.sh} script %./init.sh ]
]

; Helpers
delete-dir: func [
{Deletes a directory including all files and subdirectories.}
dir [file! url!]
{Deletes a directory including all files and subdirectories.}
dir [file! url!]
] [
if all [
dir? dir
dir: dirize dir
attempt [files: load dir]
] [
foreach file files [delete-dir dir/:file]
]
attempt [delete dir]
if all [
dir? dir
dir: dirize dir
attempt [files: load dir]
] [
foreach file files [delete-dir dir/:file]
]
attempt [delete dir]
]
log: func [
message [string! block!]
/only
/no-break
message [string! block!]
/only
/no-break
] [
unless only [
prin [{[} now/time {] }]
]
either no-break [prin message] [print/eval message]
unless only [
prin [{[} now/time {] }]
]
either no-break [prin message] [print/eval message]
]

; Inits
switch platform: lowercase to-string system/platform/1 [
{macintosh} [platform: {mac}]
{macintosh} [platform: {mac}]
]
platform-info: platforms/:platform
premake-source: rejoin [%../ platform-info/premake]
change-dir root: system/options/path

; Usage
usage: func [
/message content [block! string!]
/message content [block! string!]
] [
if message [
prin {== }
print/eval content
print {}
]
if message [
prin {== }
print/eval content
print {}
]

prin [{== Usage:} to-local-file clean-path rejoin [system/options/script/../../../.. "/" platform-info/script]]
prin [{== Usage:} to-local-file clean-path rejoin [system/options/script/../../../.. "/" platform-info/script]]

print rejoin [
newline newline
map-each [param desc default] params [
prin rejoin [{ } either default [rejoin [{[} param {]}]] [param]]
rejoin [{ = } param {: } desc either default [rejoin [{=[} default {], optional}]] [{, required}] newline]
]
print rejoin [
newline newline
foreach [param desc default] params [
prin rejoin [{ } either default [rejoin [{[} param {]}]] [param]]
rejoin [{ = } param {: } desc either default [rejoin [{=[} default {], optional}]] [{, required}] newline]
]
quit
]
quit
]

; Processes params
either system/options/args [
either (length? system/options/args) > ((length? params) / 3) [
usage/message [{Too many arguments:} mold system/options/args]
] [
use [arg] [
arg: system/options/args
foreach [param desc default] params [
either tail? arg [
either default [
set param default
] [
usage/message [{Not enough arguments:} mold system/options/args]
]
] [
set param arg/1
arg: next arg
]
]
either (length? system/options/args) > ((length? params) / 3) [
usage/message [{Too many arguments:} mold system/options/args]
] [
use [arg] [
arg: system/options/args
foreach [param desc default] params [
either tail? arg [
either default [
set param default
] [
usage/message [{Not enough arguments:} mold system/options/args]
]
] [
set param arg/1
arg: next arg
]
]
]
]
] [
usage
usage
]

; Locates source
source: clean-path rejoin [first split-path system/options/script source]

; Runs setup if premake isn't found
unless exists? source/:premake-source [
log [{New orx installation found, running setup!}]
attempt [delete-dir source/:extern]
change-dir source/../../..
log [{New orx installation found, running setup!}]
attempt [delete-dir source/:extern]
in-dir source/../../.. [
call/shell/wait platform-info/setup
change-dir root
]
]

; Retrieves project name
if dir? name: clean-path to-rebol-file name [clear back tail name]

; Inits project directory
either exists? name [
log [{[} to-local-file name {] already exists, overriding!}]
log [{[} to-local-file name {] already exists, overriding!}]
] [
make-dir/deep name
make-dir/deep name
]
change-dir name/..
set [path name] split-path name
Expand All @@ -127,39 +127,39 @@ log [{Initializing [} name {] in [} to-local-file path {]}]
log {== Creating files:}
build: _
eval copy-files: func [
from [file!]
to [file!]
/local src dst
from [file!]
to [file!]
/local src dst
] [
foreach file read from [
src: from/:file
dst: replace to/:file template name
if file = %build/ [
set 'build dst
]
either dir? src [
make-dir/deep dst
copy-files src dst
] [
log/only [{ +} to-local-file dst]
write dst replace/all read src template name
]
foreach file read from [
src: from/:file
dst: replace to/:file template name
if file = %build/ [
set 'build dst
]

either dir? src [
make-dir/deep dst
copy-files src dst
] [
log/only [{ +} to-local-file dst]
write dst replace/all read src template name
]
]
] source name

; Creates build projects
if build [
change-dir build
in-dir build [
write platform-info/premake read source/:premake-source
unless platform = {windows} [
call/shell/wait reform [{chmod +x} platform-info/premake]
call/shell/wait reform [{chmod +x} platform-info/premake]
]
log [{Generating build files for [} platform {]:}]
foreach config platform-info/config [
log/only [{ *} config]
call/shell/wait reform [to-local-file clean-path platform-info/premake config]
log/only [{ *} config]
call/shell/wait reform [to-local-file clean-path platform-info/premake config]
]
]
]

; Ends
Expand Down
Loading

0 comments on commit 98368c5

Please sign in to comment.