-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from ubports/path-fix
Introduce a setPath option for tools
- Loading branch information
Showing
17 changed files
with
86 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2021 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -353,7 +354,7 @@ describe("Adb module", function () { | |
expect(child_process.spawn).toHaveBeenCalledWith( | ||
adb.executable, | ||
[...adb.extra, "sideload", "tests/test-data/test_file"], | ||
{ env: { ADB_TRACE: "rwx" } } | ||
{ env: expect.objectContaining({ ADB_TRACE: "rwx" }) } | ||
); | ||
}); | ||
}); | ||
|
@@ -1017,6 +1018,7 @@ describe("Adb module", function () { | |
it("should restore full backup", function () { | ||
stubExec(1, "should not be called"); | ||
jest.useFakeTimers(); | ||
jest.setSystemTime(); | ||
fs.readJSON = jest.fn().mockReturnValue({ | ||
codename: "codename", | ||
comment: "Ubuntu Touch backup created on 1970-01-01T00:00:00.000Z", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2020-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2020-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
import { jest, expect } from "@jest/globals"; | ||
|
||
import cp from "cancelable-promise"; | ||
|
||
describe("CancelablePromise", function () { | ||
it("should export tool when packaged", function () { | ||
cp.CancelablePromise = null; | ||
return import("./cancelable-promise.js").then(cp => | ||
expect(cp).toBeTruthy() | ||
); | ||
}); | ||
it("should export tool when native", function () { | ||
return import("./cancelable-promise.js").then(cp => | ||
expect(cp).toBeTruthy() | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2021 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2021 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -81,6 +82,7 @@ describe("Fastboot module", function () { | |
on: jest.fn((_, cb) => { | ||
if (i++ === 0) { | ||
cb("Sending 'boot'"); | ||
cb("OKAY"); | ||
setTimeout(() => cb("Writing 'boot'"), 1); | ||
setTimeout(() => cb("Finished 'boot'"), 2); | ||
} else { | ||
|
@@ -118,7 +120,7 @@ describe("Fastboot module", function () { | |
expect(child_process.spawn).toHaveBeenCalledWith( | ||
fastboot.executable, | ||
["flash", "boot", "/path/to/boot.img"], | ||
{ env: { ADB_TRACE: "rwx" } } | ||
{ env: expect.objectContaining({ ADB_TRACE: "rwx" }) } | ||
); | ||
expect(child_process.spawn).toHaveBeenCalledWith( | ||
fastboot.executable, | ||
|
@@ -129,7 +131,7 @@ describe("Fastboot module", function () { | |
"--disable-verity", | ||
"/path/to/recovery.img" | ||
], | ||
{ env: { ADB_TRACE: "rwx" } } | ||
{ env: expect.objectContaining({ ADB_TRACE: "rwx" }) } | ||
); | ||
expect(progress).toHaveBeenCalledWith(0); | ||
expect(progress).toHaveBeenCalledWith(0.15); | ||
|
@@ -179,7 +181,7 @@ describe("Fastboot module", function () { | |
expect(child_process.spawn).toHaveBeenCalledWith( | ||
fastboot.executable, | ||
["flash", "boot", "/path/to/image"], | ||
{ env: { ADB_TRACE: "rwx" } } | ||
{ env: expect.objectContaining({ ADB_TRACE: "rwx" }) } | ||
); | ||
done(); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2019-2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2019-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2019-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2019-2021 UBports Foundation <[email protected]> | ||
* Copyright (C) 2019-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2019-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2021 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2017-2020 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2017-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -18,7 +19,7 @@ | |
*/ | ||
|
||
import child_process from "child_process"; | ||
import { getAndroidToolPath } from "android-tools-bin"; | ||
import { getAndroidToolPath, getAndroidToolBaseDir } from "android-tools-bin"; | ||
import EventEmitter from "events"; | ||
import { removeFalsy } from "./common.js"; | ||
import { CancelablePromise } from "./cancelable-promise.js"; | ||
|
@@ -38,6 +39,12 @@ export class Tool extends EventEmitter { | |
this.extra = options?.extra || []; | ||
this.execOptions = options?.execOptions || {}; | ||
this.processes = []; | ||
if ( | ||
options.setPath && | ||
process.env.PATH && | ||
!process.env.PATH.includes(getAndroidToolBaseDir()) | ||
) | ||
process.env.PATH = `${getAndroidToolBaseDir()}:${process.env.PATH}`; | ||
} | ||
|
||
/** | ||
|
@@ -116,6 +123,7 @@ export class Tool extends EventEmitter { | |
[...this.extra, ...args].flat(), | ||
{ | ||
env: { | ||
...process.env, | ||
ADB_TRACE: "rwx" | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
"use strict"; | ||
|
||
/* | ||
* Copyright (C) 2019-2021 UBports Foundation <[email protected]> | ||
* Copyright (C) 2019-2022 UBports Foundation <[email protected]> | ||
* Copyright (C) 2019-2022 Johannah Sprinz <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
|
@@ -40,7 +41,7 @@ describe("Tool module", function () { | |
describe("constructor()", function () { | ||
["adb", "fastboot", "heimdall"].forEach(t => { | ||
it(`should create generic ${t}`, function () { | ||
const tool = new Tool({ tool: t }); | ||
const tool = new Tool({ tool: t, setPath: true }); | ||
expect(tool).toExist; | ||
expect(tool.tool).toEqual(t); | ||
expect(tool.executable).toMatch(t); | ||
|
@@ -217,7 +218,7 @@ describe("Tool module", function () { | |
expect(child_process.spawn).toHaveBeenCalledWith( | ||
tool.executable, | ||
[...tool.extra, ...args], | ||
{ env: { ADB_TRACE: "rwx" } } | ||
{ env: expect.objectContaining({ ADB_TRACE: "rwx" }) } | ||
); | ||
expect(spawnStartListenerStub).toHaveBeenCalledWith({ | ||
cmd: [tool.tool, ...tool.extra, ...args] | ||
|