Skip to content

Commit

Permalink
Add a --build_target option to singlejar
Browse files Browse the repository at this point in the history
If set, and build stamping is enabled, it is used as the `build.target`
property instead of the output path.

#17316

PiperOrigin-RevId: 506932307
Change-Id: I06a710445ab79e98fc3794b7eb81a9abd61dce69
  • Loading branch information
cushon authored and copybara-github committed Feb 3, 2023
1 parent 8b7a827 commit a1a5f33
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/tools/singlejar/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bool Options::ParseToken(ArgTokenStream *tokens) {
tokens->MatchAndSet("--classpath_resources", &classpath_resources) ||
tokens->MatchAndSet("--include_prefixes", &include_prefixes) ||
tokens->MatchAndSet("--exclude_build_data", &exclude_build_data) ||
tokens->MatchAndSet("--build_target", &build_target) ||
tokens->MatchAndSet("--compression", &force_compression) ||
tokens->MatchAndSet("--dont_change_compression", &preserve_compression) ||
tokens->MatchAndSet("--normalize", &normalize_timestamps) ||
Expand Down
2 changes: 2 additions & 0 deletions src/tools/singlejar/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Options {
public:
Options()
: output_jar_creator("singlejar"),
build_target(""),
exclude_build_data(false),
force_compression(false),
normalize_timestamps(false),
Expand All @@ -44,6 +45,7 @@ class Options {

std::string output_jar;
std::string output_jar_creator;
std::string build_target;
std::string main_class;
std::string java_launcher;
std::string cds_archive;
Expand Down
8 changes: 5 additions & 3 deletions src/tools/singlejar/output_jar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ int OutputJar::Doit(Options *options) {
manifest_.AppendLine("Manifest-Version: 1.0");
manifest_.AppendLine("Created-By: " + options_->output_jar_creator);

// TODO(b/28294322): do we need to resolve the path to be absolute or
// canonical?
build_properties_.AddProperty("build.target", options_->output_jar.c_str());
// TODO(b/28294322): remove fallback to output_jar
build_properties_.AddProperty("build.target",
!options_->build_target.empty()
? options_->build_target.c_str()
: options_->output_jar.c_str());
if (options_->verbose) {
fprintf(stderr, "combined_file_name=%s\n", options_->output_jar.c_str());
if (!options_->main_class.empty()) {
Expand Down
7 changes: 4 additions & 3 deletions src/tools/singlejar/output_jar_simple_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ class OutputJarSimpleTest : public ::testing::Test {
void SetUp() override { runfiles.reset(Runfiles::CreateForTest()); }

void CreateOutput(const string &out_path, const std::vector<string> &args) {
const char *option_list[100] = {"--output", out_path.c_str()};
int nargs = 2;
const char *option_list[100] = {"--output", out_path.c_str(),
"--build_target", "//some/target"};
int nargs = 4;
for (auto &arg : args) {
if (arg.empty()) {
continue;
Expand Down Expand Up @@ -215,7 +216,7 @@ TEST_F(OutputJarSimpleTest, Empty) {
"\r\n",
manifest);
string build_properties = GetEntryContents(out_path, "build-data.properties");
EXPECT_PRED2(HasSubstr, build_properties, "build.target=");
EXPECT_PRED2(HasSubstr, build_properties, "build.target=//some/target");
}

// Source jars.
Expand Down

0 comments on commit a1a5f33

Please sign in to comment.