Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redoxer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mattmadeofpasta
redoxer
Commits
d85cb0cc
Verified
Commit
d85cb0cc
authored
5 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
WIP: Add function for generating prefix
parent
caa47b52
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+91
-10
91 additions, 10 deletions
src/main.rs
with
91 additions
and
10 deletions
src/main.rs
+
91
−
10
View file @
d85cb0cc
...
@@ -207,7 +207,80 @@ fn base(bootloader_bin: &Path) -> io::Result<PathBuf> {
...
@@ -207,7 +207,80 @@ fn base(bootloader_bin: &Path) -> io::Result<PathBuf> {
Ok
(
base_bin
)
Ok
(
base_bin
)
}
}
fn
inner
()
->
io
::
Result
<
()
>
{
//TODO: Rewrite with hyper or reqwest, tar-rs, sha2, and some gzip crate?
fn
download
<
P
:
AsRef
<
Path
>>
(
url
:
&
str
,
path
:
P
)
->
io
::
Result
<
()
>
{
Command
::
new
(
"curl"
)
.arg
(
"--proto"
)
.arg
(
"=https"
)
.arg
(
"--tlsv1.2"
)
.arg
(
"--fail"
)
.arg
(
"--output"
)
.arg
(
path
.as_ref
())
.arg
(
url
)
.status
()
.and_then
(
status_error
)
}
//TODO: Rewrite with hyper or reqwest, tar-rs, sha2, and some gzip crate?
fn
shasum
<
P
:
AsRef
<
Path
>>
(
path
:
P
)
->
io
::
Result
<
bool
>
{
let
parent
=
path
.as_ref
()
.parent
()
.ok_or
(
io
::
Error
::
new
(
io
::
ErrorKind
::
Other
,
"shasum path had no parent"
)
)
?
;
Command
::
new
(
"sha256sum"
)
.arg
(
"--check"
)
.arg
(
"--ignore-missing"
)
.arg
(
"--quiet"
)
.arg
(
path
.as_ref
())
.current_dir
(
parent
)
.status
()
.map
(|
status
|
status
.success
())
}
//TODO: Rewrite with hyper or reqwest, tar-rs, sha2, and some gzip crate?
fn
prefix
()
->
io
::
Result
<
PathBuf
>
{
let
url
=
"https://static.redox-os.org/toolchain/x86_64-unknown-redox"
;
let
toolchain_dir
=
redoxer_dir
()
.join
(
"toolchain"
);
let
prefix_dir
=
toolchain_dir
.join
(
"prefix"
);
if
!
prefix_dir
.is_dir
()
{
println!
(
"redoxer: building prefix"
);
if
toolchain_dir
.is_dir
()
{
fs
::
remove_dir_all
(
&
toolchain_dir
)
?
;
}
fs
::
create_dir_all
(
&
toolchain_dir
)
?
;
let
shasum_file
=
toolchain_dir
.join
(
"SHA256SUM"
);
download
(
&
format!
(
"{}/SHA256SUM"
,
url
),
&
shasum_file
)
?
;
let
prefix_tar
=
toolchain_dir
.join
(
"relibc-install.tar.gz"
);
download
(
&
format!
(
"{}/relibc-install.tar.gz"
,
url
),
&
prefix_tar
)
?
;
if
!
shasum
(
&
shasum_file
)
?
{
return
Err
(
io
::
Error
::
new
(
io
::
ErrorKind
::
Other
,
"shasum invalid"
));
}
let
prefix_partial
=
redoxer_dir
()
.join
(
"prefix.partial"
);
fs
::
create_dir_all
(
&
prefix_partial
)
?
;
Command
::
new
(
"tar"
)
.arg
(
"--extract"
)
.arg
(
"--file"
)
.arg
(
&
prefix_tar
)
.arg
(
"-C"
)
.arg
(
&
prefix_partial
)
.arg
(
"."
)
.status
()
.and_then
(
status_error
)
?
;
fs
::
rename
(
&
prefix_partial
,
&
prefix_dir
)
?
;
}
Ok
(
prefix_dir
)
}
fn
inner
()
->
io
::
Result
<
i32
>
{
if
!
installed
(
"kvm"
)
?
{
if
!
installed
(
"kvm"
)
?
{
eprintln!
(
"redoxer: kvm not found, please install before continuing"
);
eprintln!
(
"redoxer: kvm not found, please install before continuing"
);
process
::
exit
(
1
);
process
::
exit
(
1
);
...
@@ -224,10 +297,11 @@ fn inner() -> io::Result<()> {
...
@@ -224,10 +297,11 @@ fn inner() -> io::Result<()> {
let
bootloader_bin
=
bootloader
()
?
;
let
bootloader_bin
=
bootloader
()
?
;
let
base_bin
=
base
(
&
bootloader_bin
)
?
;
let
base_bin
=
base
(
&
bootloader_bin
)
?
;
let
prefix_dir
=
prefix
()
?
;
let
tempdir
=
tempfile
::
tempdir
()
?
;
let
tempdir
=
tempfile
::
tempdir
()
?
;
{
let
code
=
{
let
redoxer_bin
=
tempdir
.path
()
.join
(
"redoxer.bin"
);
let
redoxer_bin
=
tempdir
.path
()
.join
(
"redoxer.bin"
);
fs
::
copy
(
&
base_bin
,
&
redoxer_bin
)
?
;
fs
::
copy
(
&
base_bin
,
&
redoxer_bin
)
?
;
...
@@ -274,34 +348,41 @@ fn inner() -> io::Result<()> {
...
@@ -274,34 +348,41 @@ fn inner() -> io::Result<()> {
.arg
(
"-drive"
)
.arg
(
format!
(
"file={},format=raw"
,
redoxer_bin
.display
()))
.arg
(
"-drive"
)
.arg
(
format!
(
"file={},format=raw"
,
redoxer_bin
.display
()))
.status
()
?
;
.status
()
?
;
match
status
.code
()
{
eprintln!
();
let
code
=
match
status
.code
()
{
Some
(
51
)
=>
{
Some
(
51
)
=>
{
eprintln!
(
"## redoxer (success) ##"
);
eprintln!
(
"## redoxer (success) ##"
);
0
},
},
Some
(
53
)
=>
{
Some
(
53
)
=>
{
eprintln!
(
"## redoxer (failure) ##"
);
eprintln!
(
"## redoxer (failure) ##"
);
//TODO: Return error
1
},
},
_
=>
{
_
=>
{
eprintln!
(
"## redoxer (failure, qemu exit status {:?} ##"
,
status
);
eprintln!
(
"## redoxer (failure, qemu exit status {:?} ##"
,
status
);
//TODO: Return error
2
}
}
}
}
;
print!
(
"{}"
,
fs
::
read_to_string
(
&
redoxer_log
)
?
);
print!
(
"{}"
,
fs
::
read_to_string
(
&
redoxer_log
)
?
);
}
code
};
tempdir
.close
()
?
;
tempdir
.close
()
?
;
Ok
(
()
)
Ok
(
code
)
}
}
fn
main
()
{
fn
main
()
{
match
inner
()
{
match
inner
()
{
Ok
(())
=>
(),
Ok
(
code
)
=>
{
process
::
exit
(
code
);
},
Err
(
err
)
=>
{
Err
(
err
)
=>
{
eprintln!
(
"redoxer: {}"
,
err
);
eprintln!
(
"redoxer: {}"
,
err
);
process
::
exit
(
1
)
process
::
exit
(
3
);
}
}
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment