mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1429511 - Move geckodriver to in-tree mozrunner. r=jgraham
This deletes the third-party mozrunner crate off crates.io in favour of using the in-tree version from testing/mozbase/rust/mozrunner. MozReview-Commit-ID: 6xQZ99FYrdP --HG-- extra : rebase_source : 90ef2df2924d4194652255728d73ee03ed729ac3
This commit is contained in:
parent
20a835e1f9
commit
5b3c485463
4
testing/geckodriver/Cargo.lock
generated
4
testing/geckodriver/Cargo.lock
generated
@ -131,7 +131,7 @@ dependencies = [
|
||||
"lazy_static 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozrunner 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozrunner 0.5.0",
|
||||
"mozversion 0.1.2",
|
||||
"regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -280,7 +280,6 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "mozrunner"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -686,7 +685,6 @@ dependencies = [
|
||||
"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
|
||||
"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4"
|
||||
"checksum mozprofile 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a17b8bbde1dc0fbf1c8b073192d7c6f89baa932173ece7c1447de5e9cc7cd7e"
|
||||
"checksum mozrunner 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff037ca681fa465d01c863f8b16d4a008997b35468059c06f1a4b828369600b"
|
||||
"checksum msdos_time 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "65ba9d75bcea84e07812618fedf284a64776c2f2ea0cad6bca7f69739695a958"
|
||||
"checksum num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "a311b77ebdc5dd4cf6449d81e4135d9f0e3b153839ac90e648a8ef538f923525"
|
||||
"checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba"
|
||||
|
@ -16,7 +16,7 @@ hyper = "0.10"
|
||||
lazy_static = "0.1"
|
||||
log = "0.3"
|
||||
mozprofile = "0.3.0"
|
||||
mozrunner = "0.5.0"
|
||||
mozrunner = { path = "../mozbase/rust/mozrunner" }
|
||||
mozversion = { path = "../mozbase/rust/mozversion" }
|
||||
regex = "0.2"
|
||||
rustc-serialize = "0.3"
|
||||
|
@ -1 +0,0 @@
|
||||
{"files":{"Cargo.toml":"657202ea8600feffb50bf5c1e157a3cb7ddbfaabce8ff4fadb4dfc6bbdcd2663","LICENSE":"fab3dd6bdab226f1c08630b1dd917e11fcb4ec5e1e020e2c16f83a0a13863e85","src/bin/firefox-default-path.rs":"21f1aa96a4ffb368a4266e294bc4b1b17ff8229f2418af6679783f6d9c0280df","src/lib.rs":"26ea358c4bc1d45eb3b5ebc702b1a6bffdf5642acab9bbeffddb5be55ddb1b07","src/runner.rs":"ca015cd994987abd6902c61f9cbcabf760e6f0c0a55b4f16aa8420ab88101eae"},"package":"8ff037ca681fa465d01c863f8b16d4a008997b35468059c06f1a4b828369600b"}
|
29
third_party/rust/mozrunner/Cargo.toml
vendored
29
third_party/rust/mozrunner/Cargo.toml
vendored
@ -1,29 +0,0 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
name = "mozrunner"
|
||||
version = "0.5.0"
|
||||
authors = ["Mozilla Tools and Automation <auto-tools@mozilla.com>"]
|
||||
description = "Library for starting Firefox binaries."
|
||||
license = "MPL-2.0"
|
||||
repository = "https://github.com/jgraham/rust_mozrunner"
|
||||
|
||||
[[bin]]
|
||||
name = "firefox-default-path"
|
||||
[dependencies.log]
|
||||
version = "0.3"
|
||||
|
||||
[dependencies.mozprofile]
|
||||
version = "0.3"
|
||||
[target."cfg(target_os = \"windows\")".dependencies.winreg]
|
||||
version = "0.3.5"
|
373
third_party/rust/mozrunner/LICENSE
vendored
373
third_party/rust/mozrunner/LICENSE
vendored
@ -1,373 +0,0 @@
|
||||
Mozilla Public License Version 2.0
|
||||
==================================
|
||||
|
||||
1. Definitions
|
||||
--------------
|
||||
|
||||
1.1. "Contributor"
|
||||
means each individual or legal entity that creates, contributes to
|
||||
the creation of, or owns Covered Software.
|
||||
|
||||
1.2. "Contributor Version"
|
||||
means the combination of the Contributions of others (if any) used
|
||||
by a Contributor and that particular Contributor's Contribution.
|
||||
|
||||
1.3. "Contribution"
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. "Covered Software"
|
||||
means Source Code Form to which the initial Contributor has attached
|
||||
the notice in Exhibit A, the Executable Form of such Source Code
|
||||
Form, and Modifications of such Source Code Form, in each case
|
||||
including portions thereof.
|
||||
|
||||
1.5. "Incompatible With Secondary Licenses"
|
||||
means
|
||||
|
||||
(a) that the initial Contributor has attached the notice described
|
||||
in Exhibit B to the Covered Software; or
|
||||
|
||||
(b) that the Covered Software was made available under the terms of
|
||||
version 1.1 or earlier of the License, but not also under the
|
||||
terms of a Secondary License.
|
||||
|
||||
1.6. "Executable Form"
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. "Larger Work"
|
||||
means a work that combines Covered Software with other material, in
|
||||
a separate file or files, that is not Covered Software.
|
||||
|
||||
1.8. "License"
|
||||
means this document.
|
||||
|
||||
1.9. "Licensable"
|
||||
means having the right to grant, to the maximum extent possible,
|
||||
whether at the time of the initial grant or subsequently, any and
|
||||
all of the rights conveyed by this License.
|
||||
|
||||
1.10. "Modifications"
|
||||
means any of the following:
|
||||
|
||||
(a) any file in Source Code Form that results from an addition to,
|
||||
deletion from, or modification of the contents of Covered
|
||||
Software; or
|
||||
|
||||
(b) any new file in Source Code Form that contains any Covered
|
||||
Software.
|
||||
|
||||
1.11. "Patent Claims" of a Contributor
|
||||
means any patent claim(s), including without limitation, method,
|
||||
process, and apparatus claims, in any patent Licensable by such
|
||||
Contributor that would be infringed, but for the grant of the
|
||||
License, by the making, using, selling, offering for sale, having
|
||||
made, import, or transfer of either its Contributions or its
|
||||
Contributor Version.
|
||||
|
||||
1.12. "Secondary License"
|
||||
means either the GNU General Public License, Version 2.0, the GNU
|
||||
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||
Public License, Version 3.0, or any later versions of those
|
||||
licenses.
|
||||
|
||||
1.13. "Source Code Form"
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. "You" (or "Your")
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, "You" includes any entity that
|
||||
controls, is controlled by, or is under common control with You. For
|
||||
purposes of this definition, "control" means (a) the power, direct
|
||||
or indirect, to cause the direction or management of such entity,
|
||||
whether by contract or otherwise, or (b) ownership of more than
|
||||
fifty percent (50%) of the outstanding shares or beneficial
|
||||
ownership of such entity.
|
||||
|
||||
2. License Grants and Conditions
|
||||
--------------------------------
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
(a) under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or
|
||||
as part of a Larger Work; and
|
||||
|
||||
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||
for sale, have made, import, and otherwise transfer either its
|
||||
Contributions or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution
|
||||
become effective for each Contribution on the date the Contributor first
|
||||
distributes such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under
|
||||
this License. No additional rights or licenses will be implied from the
|
||||
distribution or licensing of Covered Software under this License.
|
||||
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||
Contributor:
|
||||
|
||||
(a) for any code that a Contributor has removed from Covered Software;
|
||||
or
|
||||
|
||||
(b) for infringements caused by: (i) Your and any other third party's
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||
its Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks,
|
||||
or logos of any Contributor (except as may be necessary to comply with
|
||||
the notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this
|
||||
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||
permitted under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its
|
||||
Contributions are its original creation(s) or it has sufficient rights
|
||||
to grant the rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under
|
||||
applicable copyright doctrines of fair use, fair dealing, or other
|
||||
equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||
in Section 2.1.
|
||||
|
||||
3. Responsibilities
|
||||
-------------------
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under
|
||||
the terms of this License. You must inform recipients that the Source
|
||||
Code Form of the Covered Software is governed by the terms of this
|
||||
License, and how they can obtain a copy of this License. You may not
|
||||
attempt to alter or restrict the recipients' rights in the Source Code
|
||||
Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
(a) such Covered Software must also be made available in Source Code
|
||||
Form, as described in Section 3.1, and You must inform recipients of
|
||||
the Executable Form how they can obtain a copy of such Source Code
|
||||
Form by reasonable means in a timely manner, at a charge no more
|
||||
than the cost of distribution to the recipient; and
|
||||
|
||||
(b) You may distribute such Executable Form under the terms of this
|
||||
License, or sublicense it under different terms, provided that the
|
||||
license for the Executable Form does not attempt to limit or alter
|
||||
the recipients' rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for
|
||||
the Covered Software. If the Larger Work is a combination of Covered
|
||||
Software with a work governed by one or more Secondary Licenses, and the
|
||||
Covered Software is not Incompatible With Secondary Licenses, this
|
||||
License permits You to additionally distribute such Covered Software
|
||||
under the terms of such Secondary License(s), so that the recipient of
|
||||
the Larger Work may, at their option, further distribute the Covered
|
||||
Software under the terms of either this License or such Secondary
|
||||
License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices
|
||||
(including copyright notices, patent notices, disclaimers of warranty,
|
||||
or limitations of liability) contained within the Source Code Form of
|
||||
the Covered Software, except that You may alter any license notices to
|
||||
the extent required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on
|
||||
behalf of any Contributor. You must make it absolutely clear that any
|
||||
such warranty, support, indemnity, or liability obligation is offered by
|
||||
You alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
---------------------------------------------------
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this
|
||||
License with respect to some or all of the Covered Software due to
|
||||
statute, judicial order, or regulation then You must: (a) comply with
|
||||
the terms of this License to the maximum extent possible; and (b)
|
||||
describe the limitations and the code they affect. Such description must
|
||||
be placed in a text file included with all distributions of the Covered
|
||||
Software under this License. Except to the extent prohibited by statute
|
||||
or regulation, such description must be sufficiently detailed for a
|
||||
recipient of ordinary skill to be able to understand it.
|
||||
|
||||
5. Termination
|
||||
--------------
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically
|
||||
if You fail to comply with any of its terms. However, if You become
|
||||
compliant, then the rights granted under this License from a particular
|
||||
Contributor are reinstated (a) provisionally, unless and until such
|
||||
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||
ongoing basis, if such Contributor fails to notify You of the
|
||||
non-compliance by some reasonable means prior to 60 days after You have
|
||||
come back into compliance. Moreover, Your grants from a particular
|
||||
Contributor are reinstated on an ongoing basis if such Contributor
|
||||
notifies You of the non-compliance by some reasonable means, this is the
|
||||
first time You have received notice of non-compliance with this License
|
||||
from such Contributor, and You become compliant prior to 30 days after
|
||||
Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions,
|
||||
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||
directly or indirectly infringes any patent, then the rights granted to
|
||||
You by any and all Contributors for the Covered Software under Section
|
||||
2.1 of this License shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||
end user license agreements (excluding distributors and resellers) which
|
||||
have been validly granted by You or Your distributors under this License
|
||||
prior to termination shall survive termination.
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 6. Disclaimer of Warranty *
|
||||
* ------------------------- *
|
||||
* *
|
||||
* Covered Software is provided under this License on an "as is" *
|
||||
* basis, without warranty of any kind, either expressed, implied, or *
|
||||
* statutory, including, without limitation, warranties that the *
|
||||
* Covered Software is free of defects, merchantable, fit for a *
|
||||
* particular purpose or non-infringing. The entire risk as to the *
|
||||
* quality and performance of the Covered Software is with You. *
|
||||
* Should any Covered Software prove defective in any respect, You *
|
||||
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||
* essential part of this License. No use of any Covered Software is *
|
||||
* authorized under this License except under this disclaimer. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
************************************************************************
|
||||
* *
|
||||
* 7. Limitation of Liability *
|
||||
* -------------------------- *
|
||||
* *
|
||||
* Under no circumstances and under no legal theory, whether tort *
|
||||
* (including negligence), contract, or otherwise, shall any *
|
||||
* Contributor, or anyone who distributes Covered Software as *
|
||||
* permitted above, be liable to You for any direct, indirect, *
|
||||
* special, incidental, or consequential damages of any character *
|
||||
* including, without limitation, damages for lost profits, loss of *
|
||||
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||
* and all other commercial damages or losses, even if such party *
|
||||
* shall have been informed of the possibility of such damages. This *
|
||||
* limitation of liability shall not apply to liability for death or *
|
||||
* personal injury resulting from such party's negligence to the *
|
||||
* extent applicable law prohibits such limitation. Some *
|
||||
* jurisdictions do not allow the exclusion or limitation of *
|
||||
* incidental or consequential damages, so this exclusion and *
|
||||
* limitation may not apply to You. *
|
||||
* *
|
||||
************************************************************************
|
||||
|
||||
8. Litigation
|
||||
-------------
|
||||
|
||||
Any litigation relating to this License may be brought only in the
|
||||
courts of a jurisdiction where the defendant maintains its principal
|
||||
place of business and such litigation shall be governed by laws of that
|
||||
jurisdiction, without reference to its conflict-of-law provisions.
|
||||
Nothing in this Section shall prevent a party's ability to bring
|
||||
cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
----------------
|
||||
|
||||
This License represents the complete agreement concerning the subject
|
||||
matter hereof. If any provision of this License is held to be
|
||||
unenforceable, such provision shall be reformed only to the extent
|
||||
necessary to make it enforceable. Any law or regulation which provides
|
||||
that the language of a contract shall be construed against the drafter
|
||||
shall not be used to construe this License against a Contributor.
|
||||
|
||||
10. Versions of the License
|
||||
---------------------------
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version
|
||||
of the License under which You originally received the Covered Software,
|
||||
or under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a
|
||||
modified version of this License if you rename the license and remove
|
||||
any references to the name of the license steward (except to note that
|
||||
such modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||
Licenses
|
||||
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
-------------------------------------------
|
||||
|
||||
This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular
|
||||
file, then You may include the notice in a location (such as a LICENSE
|
||||
file in a relevant directory) where a recipient would be likely to look
|
||||
for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||
---------------------------------------------------------
|
||||
|
||||
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||
defined by the Mozilla Public License, v. 2.0.
|
@ -1,17 +0,0 @@
|
||||
extern crate mozrunner;
|
||||
|
||||
use mozrunner::runner::platform;
|
||||
use std::io::Write;
|
||||
|
||||
fn main() {
|
||||
let (path, code) = platform::firefox_default_path()
|
||||
.map(|x| (x.to_string_lossy().into_owned(), 0))
|
||||
.unwrap_or(("Firefox binary not found".to_owned(), 1));
|
||||
|
||||
let mut writer: Box<Write> = match code {
|
||||
0 => Box::new(std::io::stdout()),
|
||||
_ => Box::new(std::io::stderr())
|
||||
};
|
||||
writeln!(&mut writer, "{}", &*path).unwrap();
|
||||
std::process::exit(code);
|
||||
}
|
8
third_party/rust/mozrunner/src/lib.rs
vendored
8
third_party/rust/mozrunner/src/lib.rs
vendored
@ -1,8 +0,0 @@
|
||||
#[macro_use] extern crate log;
|
||||
extern crate mozprofile;
|
||||
#[cfg(target_os = "windows")]
|
||||
extern crate winreg;
|
||||
|
||||
pub mod runner;
|
||||
|
||||
pub use runner::platform::firefox_default_path;
|
387
third_party/rust/mozrunner/src/runner.rs
vendored
387
third_party/rust/mozrunner/src/runner.rs
vendored
@ -1,387 +0,0 @@
|
||||
use mozprofile::prefreader::PrefReaderError;
|
||||
use mozprofile::profile::Profile;
|
||||
use std::ascii::AsciiExt;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::From;
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::io::{Result as IoResult, Error as IoError, ErrorKind};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process;
|
||||
use std::process::{Command, Stdio};
|
||||
|
||||
pub trait Runner {
|
||||
fn args(&mut self) -> &mut Vec<String>;
|
||||
fn build_command(&self, &mut Command);
|
||||
fn envs(&mut self) -> &mut HashMap<String, String>;
|
||||
fn is_running(&mut self) -> bool;
|
||||
fn start(&mut self) -> Result<(), RunnerError>;
|
||||
fn status(&mut self) -> IoResult<Option<process::ExitStatus>>;
|
||||
fn stop(&mut self) -> IoResult<Option<process::ExitStatus>>;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum RunnerError {
|
||||
Io(IoError),
|
||||
PrefReader(PrefReaderError),
|
||||
}
|
||||
|
||||
impl fmt::Display for RunnerError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
self.description().fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for RunnerError {
|
||||
fn description(&self) -> &str {
|
||||
match *self {
|
||||
RunnerError::Io(ref err) => {
|
||||
match err.kind() {
|
||||
ErrorKind::NotFound => "no such file or directory",
|
||||
_ => err.description(),
|
||||
}
|
||||
}
|
||||
RunnerError::PrefReader(ref err) => err.description(),
|
||||
}
|
||||
}
|
||||
|
||||
fn cause(&self) -> Option<&Error> {
|
||||
Some(match *self {
|
||||
RunnerError::Io(ref err) => err as &Error,
|
||||
RunnerError::PrefReader(ref err) => err as &Error,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<IoError> for RunnerError {
|
||||
fn from(value: IoError) -> RunnerError {
|
||||
RunnerError::Io(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<PrefReaderError> for RunnerError {
|
||||
fn from(value: PrefReaderError) -> RunnerError {
|
||||
RunnerError::PrefReader(value)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct FirefoxRunner {
|
||||
pub binary: PathBuf,
|
||||
args: Vec<String>,
|
||||
envs: HashMap<String, String>,
|
||||
process: Option<process::Child>,
|
||||
pub profile: Profile
|
||||
}
|
||||
|
||||
impl FirefoxRunner {
|
||||
pub fn new(binary: &Path, profile: Option<Profile>) -> IoResult<FirefoxRunner> {
|
||||
let prof = match profile {
|
||||
Some(p) => p,
|
||||
None => try!(Profile::new(None))
|
||||
};
|
||||
|
||||
let mut envs = HashMap::new();
|
||||
envs.insert("MOZ_NO_REMOTE".to_string(), "1".to_string());
|
||||
envs.insert("NO_EM_RESTART".to_string(), "1".to_string());
|
||||
|
||||
Ok(FirefoxRunner {
|
||||
binary: binary.to_path_buf(),
|
||||
process: None,
|
||||
args: Vec::new(),
|
||||
envs: envs,
|
||||
profile: prof
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Runner for FirefoxRunner {
|
||||
fn args(&mut self) -> &mut Vec<String> {
|
||||
&mut self.args
|
||||
}
|
||||
|
||||
fn build_command(&self, command: &mut Command) {
|
||||
command
|
||||
.args(&self.args[..])
|
||||
.envs(&self.envs);
|
||||
|
||||
if !self.args.iter().any(|x| is_profile_arg(x)) {
|
||||
command.arg("-profile").arg(&self.profile.path);
|
||||
}
|
||||
command.stdout(Stdio::inherit())
|
||||
.stderr(Stdio::inherit());
|
||||
}
|
||||
|
||||
fn envs(&mut self) -> &mut HashMap<String, String> {
|
||||
&mut self.envs
|
||||
}
|
||||
|
||||
fn is_running(&mut self) -> bool {
|
||||
self.process.is_some() && self.status().unwrap().is_none()
|
||||
}
|
||||
|
||||
fn start(&mut self) -> Result<(), RunnerError> {
|
||||
let mut cmd = Command::new(&self.binary);
|
||||
self.build_command(&mut cmd);
|
||||
|
||||
let prefs = try!(self.profile.user_prefs());
|
||||
try!(prefs.write());
|
||||
|
||||
info!("Running command: {:?}", cmd);
|
||||
let process = try!(cmd.spawn());
|
||||
self.process = Some(process);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn status(&mut self) -> IoResult<Option<process::ExitStatus>> {
|
||||
self.process.as_mut().map(|p| p.try_wait()).unwrap_or(Ok(None))
|
||||
}
|
||||
|
||||
fn stop(&mut self) -> IoResult<Option<process::ExitStatus>> {
|
||||
let mut retval = None;
|
||||
|
||||
if let Some(ref mut p) = self.process {
|
||||
try!(p.kill());
|
||||
retval = Some(try!(p.wait()));
|
||||
};
|
||||
Ok(retval)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_arg_name(arg: &str) -> Option<&str> {
|
||||
let mut start = 0;
|
||||
let mut end = 0;
|
||||
|
||||
for (i, c) in arg.chars().enumerate() {
|
||||
if i == 0 {
|
||||
if !platform::arg_prefix_char(c) {
|
||||
break;
|
||||
}
|
||||
} else if i == 1 {
|
||||
if name_end_char(c) {
|
||||
break;
|
||||
} else if c != '-' {
|
||||
start = i;
|
||||
end = start + 1;
|
||||
} else {
|
||||
start = i + 1;
|
||||
end = start;
|
||||
}
|
||||
} else {
|
||||
end += 1;
|
||||
if name_end_char(c) {
|
||||
end -= 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if start > 0 && end > start {
|
||||
Some(&arg[start..end])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn name_end_char(c: char) -> bool {
|
||||
c == ' ' || c == '='
|
||||
}
|
||||
|
||||
/// Check if an argument string affects the Firefox profile
|
||||
///
|
||||
/// Returns a boolean indicating whether a given string
|
||||
/// contains one of the `-P`, `-Profile` or `-ProfileManager`
|
||||
/// arguments, respecting the various platform-specific conventions.
|
||||
pub fn is_profile_arg(arg: &str) -> bool {
|
||||
if let Some(name) = parse_arg_name(arg) {
|
||||
name.eq_ignore_ascii_case("profile") ||
|
||||
name.eq_ignore_ascii_case("p") ||
|
||||
name.eq_ignore_ascii_case("profilemanager")
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
fn find_binary(name: &str) -> Option<PathBuf> {
|
||||
env::var("PATH")
|
||||
.ok()
|
||||
.and_then(|path_env| {
|
||||
for mut path in env::split_paths(&*path_env) {
|
||||
path.push(name);
|
||||
if path.exists() {
|
||||
return Some(path)
|
||||
}
|
||||
}
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod platform {
|
||||
use super::find_binary;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn firefox_default_path() -> Option<PathBuf> {
|
||||
find_binary("firefox")
|
||||
}
|
||||
|
||||
pub fn arg_prefix_char(c: char) -> bool {
|
||||
c == '-'
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
pub mod platform {
|
||||
use super::find_binary;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn firefox_default_path() -> Option<PathBuf> {
|
||||
if let Some(path) = find_binary("firefox-bin") {
|
||||
return Some(path)
|
||||
}
|
||||
let home = env::home_dir();
|
||||
for &(prefix_home, trial_path) in [
|
||||
(false, "/Applications/Firefox.app/Contents/MacOS/firefox-bin"),
|
||||
(true, "Applications/Firefox.app/Contents/MacOS/firefox-bin")].iter() {
|
||||
let path = match (home.as_ref(), prefix_home) {
|
||||
(Some(ref home_dir), true) => home_dir.join(trial_path),
|
||||
(None, true) => continue,
|
||||
(_, false) => PathBuf::from(trial_path)
|
||||
};
|
||||
if path.exists() {
|
||||
return Some(path)
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn arg_prefix_char(c: char) -> bool {
|
||||
c == '-'
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub mod platform {
|
||||
use super::find_binary;
|
||||
use std::io::Error;
|
||||
use std::path::PathBuf;
|
||||
use winreg::RegKey;
|
||||
use winreg::enums::*;
|
||||
|
||||
pub fn firefox_default_path() -> Option<PathBuf> {
|
||||
let opt_path = firefox_registry_path().unwrap_or(None);
|
||||
if let Some(path) = opt_path {
|
||||
if path.exists() {
|
||||
return Some(path)
|
||||
}
|
||||
};
|
||||
find_binary("firefox.exe")
|
||||
}
|
||||
|
||||
fn firefox_registry_path() -> Result<Option<PathBuf>, Error> {
|
||||
let hklm = RegKey::predef(HKEY_LOCAL_MACHINE);
|
||||
for subtree_key in ["SOFTWARE", "SOFTWARE\\WOW6432Node"].iter() {
|
||||
let subtree = try!(hklm.open_subkey_with_flags(subtree_key, KEY_READ));
|
||||
let mozilla_org = match subtree.open_subkey_with_flags("mozilla.org\\Mozilla", KEY_READ) {
|
||||
Ok(val) => val,
|
||||
Err(_) => continue
|
||||
};
|
||||
let current_version: String = try!(mozilla_org.get_value("CurrentVersion"));
|
||||
let mozilla = try!(subtree.open_subkey_with_flags("Mozilla", KEY_READ));
|
||||
for key_res in mozilla.enum_keys() {
|
||||
let key = try!(key_res);
|
||||
let section_data = try!(mozilla.open_subkey_with_flags(&key, KEY_READ));
|
||||
let version: Result<String, _> = section_data.get_value("GeckoVer");
|
||||
if let Ok(ver) = version {
|
||||
if ver == current_version {
|
||||
let mut bin_key = key.to_owned();
|
||||
bin_key.push_str("\\bin");
|
||||
if let Ok(bin_subtree) = mozilla.open_subkey_with_flags(bin_key, KEY_READ) {
|
||||
let path: Result<String, _> = bin_subtree.get_value("PathToExe");
|
||||
if let Ok(path) = path {
|
||||
return Ok(Some(PathBuf::from(path)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
pub fn arg_prefix_char(c: char) -> bool {
|
||||
c == '/' || c == '-'
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
|
||||
pub mod platform {
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn firefox_default_path() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn arg_prefix_char(c: char) -> bool {
|
||||
c == '-'
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{parse_arg_name, is_profile_arg};
|
||||
|
||||
fn parse(arg: &str, name: Option<&str>) {
|
||||
let result = parse_arg_name(arg);
|
||||
assert_eq!(result, name);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_arg_name() {
|
||||
parse("-p", Some("p"));
|
||||
parse("--p", Some("p"));
|
||||
parse("--profile foo", Some("profile"));
|
||||
parse("--profile", Some("profile"));
|
||||
parse("--", None);
|
||||
parse("", None);
|
||||
parse("-=", None);
|
||||
parse("--=", None);
|
||||
parse("-- foo", None);
|
||||
parse("foo", None);
|
||||
parse("/ foo", None);
|
||||
parse("/- foo", None);
|
||||
parse("/=foo", None);
|
||||
parse("foo", None);
|
||||
parse("-profile", Some("profile"));
|
||||
parse("-profile=foo", Some("profile"));
|
||||
parse("-profile = foo", Some("profile"));
|
||||
parse("-profile abc", Some("profile"));
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[test]
|
||||
fn test_parse_arg_name_windows() {
|
||||
parse("/profile", Some("profile"));
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[test]
|
||||
fn test_parse_arg_name_non_windows() {
|
||||
parse("/profile", None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_is_profile_arg() {
|
||||
assert!(is_profile_arg("--profile"));
|
||||
assert!(is_profile_arg("-p"));
|
||||
assert!(is_profile_arg("-PROFILEMANAGER"));
|
||||
assert!(is_profile_arg("-ProfileMANAGER"));
|
||||
assert!(!is_profile_arg("-- profile"));
|
||||
assert!(!is_profile_arg("-profiled"));
|
||||
assert!(!is_profile_arg("-p1"));
|
||||
assert!(is_profile_arg("-p test"));
|
||||
assert!(is_profile_arg("-profile /foo"));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user