Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved testing and more #60

Merged
merged 5 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
build
corral/version.pony
**/_repos
**/_corral
.vscode
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ifdef static
endif

ifeq ($(static),true)
LINKER += --static
LINKER += --static
endif

ifneq ($(linker),)
Expand Down Expand Up @@ -78,8 +78,11 @@ install: $(binary)
$(tests_binary): $(GEN_FILES) $(SOURCE_FILES) $(TEST_FILES) | $(BUILD_DIR)
${PONYC} $(arch_arg) $(LINKER) --debug -o ${BUILD_DIR} $(SRC_DIR)/test

integration: $(binary) $(tests_binary)
CORRAL_BIN=$$(pwd)/$(binary) $(tests_binary) --only=integration --sequential
cquinn marked this conversation as resolved.
Show resolved Hide resolved

test: $(tests_binary)
$^ --sequential
$^ --exclude=integration --sequential

clean:
rm -rf $(BUILD_DIR)
Expand All @@ -90,4 +93,3 @@ $(BUILD_DIR):
mkdir -p $(BUILD_DIR)

.PHONY: all clean install test

84 changes: 36 additions & 48 deletions corral/bundle/bundle.pony
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,77 @@ use "files"
use "json"
use "../util"

primitive Files
fun tag bundle_filename(): String => "corral.json"
fun tag lock_filename(): String => "lock.json"
fun tag corral_dirname(): String => "_corral"

primitive BundleFile
"""
Loader and creator of Bundle files.
Locator, loader and creator of Bundle files.
"""
fun find_bundle_dir(env: Env, dir: String, log: Log): (FilePath | None) =>
fun find_bundle_dir(auth: AmbientAuth, dir: String, log: Log): (FilePath | None) =>
var dir' = dir
while dir'.size() > 0 do
log.info("Looking for " + Files.bundle_filename() + " in: '" + dir' + "'")
try
let dir_path = FilePath(env.root as AmbientAuth, dir')?
let dir_path = FilePath(auth, dir')?
let bundle_file = dir_path.join(Files.bundle_filename())?
if bundle_file.exists() then
return dir_path
end
end
dir' = Path.split(dir')._1
end
log.info("corral.json not found, looked last in: '" + dir' + "'")
log.info(Files.bundle_filename() + " not found, looked last in: '" + dir' + "'")
None

fun load_bundle(env: Env, dir: String, log: Log): (Bundle | Error) =>
match find_bundle_dir(env, dir, log)
| let dir': FilePath =>
try
Bundle.load(env, dir', log)?
else
Error("Error loading bundle files in " + dir'.path)
fun resolve_bundle_dir(auth: AmbientAuth, dir: String, log: Log): (FilePath | None) =>
log.info("Checking for " + Files.bundle_filename() + " in: '" + dir + "'")
try
let dir_path = FilePath(auth, dir)?
let bundle_file = dir_path.join(Files.bundle_filename())?
if bundle_file.exists() then
return dir_path
end
else
Error(
"No " + Files.bundle_filename()
+ " in current working directory or ancestors.")
end
log.info(Files.bundle_filename() + " not found")
None

fun create_bundle(env: Env, dir: String, log: Log): (Bundle | Error) =>
fun load_bundle(dir: FilePath, log: Log): (Bundle iso^ | Error) =>
try
let dir' = FilePath(env.root as AmbientAuth, dir)?
try Files.bundle_filepath(dir')?.remove() end
Bundle.create(env, dir', log)
Bundle.load(dir, log)?
else
Error(
"Could not create " + Files.bundle_filename()
+ " in current working directory.")
Error("Error loading bundle files in " + dir.path)
end

fun create_bundle(dir: FilePath, log: Log): (Bundle iso^ | Error) =>
try dir.join(Files.bundle_filename())?.remove() end
Bundle.create(dir, log)

class Bundle
"""
Encapsulation of a Bundle + Lock file pair, including all file activities.
"""
let env: Env
let dir: FilePath
let log: Log
let info: InfoData
let deps: Map[String, Dep ref] = deps.create()
var modified: Bool = false

new create(env': Env, dir': FilePath, log': Log) =>
env = env'
new iso create(dir': FilePath, log': Log) =>
dir = dir'
log = log'
info = InfoData(JsonObject)
log.info("Created bundle in " + dir.path)
modified = true

new load(env': Env, dir': FilePath, log': Log) ? =>
env = env'
new iso load(dir': FilePath, log': Log) ? =>
dir = dir'
log = log'

log.fine("Loading bundle: " + Files.bundle_filepath(dir)?.path)
let data = match Json.load_object(Files.bundle_filepath(dir)?, log)
log.fine("Loading bundle: " + dir.join(Files.bundle_filename())?.path)
let data = match Json.load_object(dir.join(Files.bundle_filename())?, log)
| let jo: JsonObject => BundleData(jo)
| let fe: FileErrNo =>
log.fine("Bundle file not present.")
Expand All @@ -86,7 +86,7 @@ class Bundle

let lm = Map[String, LockData]
try
let locks_data = match Json.load_object(Files.lock_filepath(dir)?, log)
let locks_data = match Json.load_object(dir.join(Files.lock_filename())?, log)
| let jo: JsonObject => LocksData(jo)
| let fe: FileErrNo =>
log.fine("Lock file not present.")
Expand All @@ -103,18 +103,18 @@ class Bundle
for dd in data.deps.values() do
let d = Dep(this, dd, lm.get_or_else(dd.locator, LockData.none()))
deps(d.data.locator) = d
log.fine("Dep " + d.name())
log.fine("Dep of " + name() + ": " + d.name())
end

fun box name(): String => Path.base(dir.path)

fun box bundle_filepath(): FilePath ? => Files.bundle_filepath(dir)?
fun box bundle_filepath(): FilePath ? => dir.join(Files.bundle_filename())?

fun box lock_filepath(): FilePath ? => Files.lock_filepath(dir)?
fun box lock_filepath(): FilePath ? => dir.join(Files.lock_filename())?

fun box corral_dirpath(): FilePath ? => dir.join("_corral")?
fun box corral_dirpath(): FilePath ? => dir.join(Files.corral_dirname())?

fun box corral_dir(): String => Path.join(dir.path, "_corral")
fun box corral_dir(): String => Path.join(dir.path, Files.corral_dirname())

fun box dep_workspace_root(dep: Dep box): FilePath ? =>
corral_dirpath()?.join(dep.flat_name())?
Expand All @@ -137,7 +137,7 @@ class Bundle
if not tran_deps.contains(dep.name()) then
tran_deps(dep.name()) = dep
let bundle_root = base_bundle.dep_bundle_root(dep)?
let dbundle = Bundle.load(env, bundle_root, log)?
let dbundle: Bundle val = Bundle.load(bundle_root, log)?
dbundle._transitive_deps(base_bundle, tran_deps)
end
else
Expand Down Expand Up @@ -192,15 +192,3 @@ class Bundle
Json.write_object(bundle_json(), bundle_filepath()?, log)
end
Json.write_object(lock_json(), lock_filepath()?, log)


primitive Files
fun tag bundle_filename(): String => "corral.json"

fun tag bundle_filepath(dir: FilePath): FilePath ? =>
dir.join(bundle_filename())?

fun tag lock_filename(): String => "lock.json"

fun tag lock_filepath(dir: FilePath): FilePath ? =>
dir.join(lock_filename())?
2 changes: 2 additions & 0 deletions corral/bundle/data.pony
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ class BundleData
let deps: Array[DepData]

new create(jo: JsonObject box) =>
// TODO: iterate over jo's map and verify we just have "info" or "deps"
info = InfoData(Json.objekt(jo, "info"))

deps = Array[DepData]
let bundles_array = Json.array(jo, "deps")
for bjt in bundles_array.data.values() do
// TODO: catch and return this error somehow
cquinn marked this conversation as resolved.
Show resolved Hide resolved
let bjo = try bjt as JsonObject box else JsonObject end
let bd = DepData(bjo)
deps.push(bd)
Expand Down
8 changes: 0 additions & 8 deletions corral/bundle/dep.pony
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,6 @@ class Dep
fun box flat_repo(): String =>
_Flattened(repo())

//fun repo_root(base_bundle: Bundle box): String =>
// """Return this dep's repo workspace dir under the base bundle's corral."""
// Path.join(base_bundle.corral_path(), flat_name())

//fun bundle_root(base_bundle: Bundle box): String =>
// """Return this dep's bundle dir withing its repo workspace."""
// Path.join(repo_root(base_bundle), locator.bundle_path)

fun box version(): String =>
if lock.revision != "" then
lock.revision
Expand Down
4 changes: 2 additions & 2 deletions corral/bundle/json.pony
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ primitive Json
fun load_object(file_path: FilePath, log: Log)
: (JsonObject | FileErrNo | JsonError)
=>
log.fine("Reading " + file_path.path)
//log.fine("Reading json from: " + file_path.path)
cquinn marked this conversation as resolved.
Show resolved Hide resolved
let file = match OpenFile(file_path)
| let f: File => f
| let e: FileErrNo => return e
end
let content: String = file.read_string(file.size())
//log.log("Read: " + content + ".")
//log.fine("Read: " + content + ".")
let json: JsonDoc ref = JsonDoc
try
json.parse(content)?
Expand Down
121 changes: 121 additions & 0 deletions corral/cli.pony
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use "cli"
use "files"
use "util"
use "cmd"

primitive CLI
fun parse(
args: Array[String] box,
envs: (Array[String] box | None))
: (Command | (U8, String))
=>
try
match CommandParser(spec()?).parse(args, envs)
| let c: Command => c
| let h: CommandHelp => (0, h.help_string())
| let e: SyntaxError => (1, e.string())
end
else
(2, "Internal error: invalid command spec")
end

fun help(): String =>
try Help.general(spec()?).help_string() else "" end

fun spec(): CommandSpec ?
=>
CommandSpec.parent(
"corral",
"",
[
OptionSpec.bool(
"quiet",
"Quiet output."
where short'='q',
default' = false)
OptionSpec.bool(
"nothing",
"Don't actually apply changes."
where short' = 'n',
default' = false)
OptionSpec.bool(
"verbose",
"Verbose output."
where short'='v',
default' = false)
OptionSpec.string(
"bundle_dir",
"The directory where corral.json and lock.json are located."
where short' = 'd',
default' = "<cwd>")
],
[
CommandSpec.leaf(
"version",
"Show the version and exit")?
CommandSpec.leaf(
"init",
"Initializes the corral.json and lock.json files with"
+ " skeletal information."
)?
CommandSpec.leaf(
"info",
"Prints all or specific information about the bundle from"
+ " corral.json.")?
CommandSpec.leaf(
"add",
"Adds a remote VCS, local VCS or local direct dependency.",
[
OptionSpec.string(
"version",
"Version constraint"
where short' = 'v',
default' = "")
OptionSpec.string(
"revision",
"Specific revision: tag, branch, commit"
where short' = 'r',
default' = "")
],
[
ArgSpec.string("locator", "Organization/repository name.")
])?
CommandSpec.leaf(
"remove",
"Removes one or more deps from the corral.")?
CommandSpec.leaf(
"list",
"Lists the deps and packages, including corral details.")?
CommandSpec.leaf(
"clean",
"Cleans up repo cache and working corral. Default is to clean"
+ " only working corral.",
[
OptionSpec.bool(
"all",
"Clean both repo cache and working corral."
where short' = 'a',
default' = false)
OptionSpec.bool(
"repos",
"Clean repo cache only."
where short' = 'r',
default' = false)
])?
CommandSpec.leaf(
"update",
"Updates one or more or all of the deps in the corral to their"
+ " best revisions.")?
CommandSpec.leaf(
"fetch",
"Fetches one or more or all of the deps into the corral.")?
CommandSpec.leaf(
"run",
"Runs a shell command inside an environment with the corral on"
+ " the PONYPATH.",
Array[OptionSpec](),
[
ArgSpec.string_seq("args", "Arguments to run.")
])?
])?
.> add_help()?
2 changes: 1 addition & 1 deletion corral/cmd/cmd_add.pony
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ primitive CmdAdd
"\nadd: adding: " + dd.locator.string() + " "
+ dd.version.string() + " " + ld.revision.string())

match BundleFile.load_bundle(ctx.env, ctx.directory, ctx.log)
match BundleFile.load_bundle(ctx.bundle_dir, ctx.log)
| let bundle: Bundle =>
try
bundle.add_dep(dd, ld)
Expand Down
2 changes: 1 addition & 1 deletion corral/cmd/cmd_clean.pony
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ primitive CmdClean
fun apply(ctx: Context, cmd: Command) =>
//ctx.log.info("clean: " + cmd.string())

match BundleFile.load_bundle(ctx.env, ctx.directory, ctx.log)
match BundleFile.load_bundle(ctx.bundle_dir, ctx.log)
| let bundle: Bundle =>
try
let repos_dir = ctx.repo_cache
Expand Down
Loading